@@ -121,7 +121,16 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
121
121
$ dataItemVal [] = $ _item ;
122
122
}
123
123
}
124
- $ dataItemVal [] = $ itemValue ;
124
+ $ update = false ;
125
+ foreach ($ dataItemVal as $ __item ) {
126
+ if ($ __item ['product_id ' ] == $ itemValue ['product_id ' ] && $ __item ['pdp_product_id ' ] == $ itemValue ['pdp_product_id ' ] && $ __item ['design_id ' ] == $ itemValue ['design_id ' ]) {
127
+ $ update = true ;
128
+ break ;
129
+ }
130
+ }
131
+ if (!$ update ) {
132
+ $ dataItemVal [] = $ itemValue ;
133
+ }
125
134
$ dataGuestDesign ->setItemValue (serialize ($ dataItemVal ))->save ();
126
135
}
127
136
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
@@ -136,7 +145,17 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
136
145
$ dataGuestDesign = $ modelGuestDesign ->loadByCustomerId ($ customerId );
137
146
if ($ dataGuestDesign ->getEntityId ()) {
138
147
$ dataItemVal = unserialize ($ dataGuestDesign ->getItemValue ());
139
- $ dataItemVal [] = $ itemValue ;
148
+ $ update = false ;
149
+ foreach ($ dataItemVal as $ __item ) {
150
+ if ($ __item ['product_id ' ] == $ itemValue ['product_id ' ] && $ __item ['pdp_product_id ' ] == $ itemValue ['pdp_product_id ' ] && $ __item ['design_id ' ] == $ itemValue ['design_id ' ]) {
151
+ $ update = true ;
152
+ break ;
153
+ }
154
+ }
155
+ if (!$ update ) {
156
+ $ dataItemVal [] = $ itemValue ;
157
+ }
158
+
140
159
$ dataGuestDesign ->setItemValue (serialize ($ dataItemVal ))->save ();
141
160
}
142
161
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
@@ -152,7 +171,16 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
152
171
try {
153
172
$ dataGuestDesign = $ modelGuestDesign ->load ($ pdpGuestDesignId );
154
173
$ dataItemVal = unserialize ($ dataGuestDesign ->getItemValue ());
155
- $ dataItemVal [] = $ itemValue ;
174
+ $ update = false ;
175
+ foreach ($ dataItemVal as $ __item ) {
176
+ if ($ __item ['product_id ' ] == $ itemValue ['product_id ' ] && $ __item ['pdp_product_id ' ] == $ itemValue ['pdp_product_id ' ] && $ __item ['design_id ' ] == $ itemValue ['design_id ' ]) {
177
+ $ update = true ;
178
+ break ;
179
+ }
180
+ }
181
+ if (!$ update ) {
182
+ $ dataItemVal [] = $ itemValue ;
183
+ }
156
184
$ dataGuestDesign ->setItemValue (serialize ($ dataItemVal ))->save ();
157
185
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
158
186
$ reponse ->setStatus (false )
@@ -189,5 +217,5 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
189
217
}
190
218
191
219
return $ reponse ;
192
- }
220
+ }
193
221
}
0 commit comments