Skip to content

Commit a13835a

Browse files
committed
edit file
1 parent 82e98c7 commit a13835a

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

app/code/PDP/Integration/Model/Pdpproduct/PdpGuestDesignRepository.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,16 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
121121
$dataItemVal[] = $_item;
122122
}
123123
}
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+
}
125134
$dataGuestDesign->setItemValue(serialize($dataItemVal))->save();
126135
}
127136
} catch(\Magento\Framework\Exception\LocalizedException $e) {
@@ -136,7 +145,17 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
136145
$dataGuestDesign = $modelGuestDesign->loadByCustomerId($customerId);
137146
if($dataGuestDesign->getEntityId()) {
138147
$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+
140159
$dataGuestDesign->setItemValue(serialize($dataItemVal))->save();
141160
}
142161
} catch(\Magento\Framework\Exception\LocalizedException $e) {
@@ -152,7 +171,16 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
152171
try {
153172
$dataGuestDesign = $modelGuestDesign->load($pdpGuestDesignId);
154173
$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+
}
156184
$dataGuestDesign->setItemValue(serialize($dataItemVal))->save();
157185
} catch(\Magento\Framework\Exception\LocalizedException $e) {
158186
$reponse->setStatus(false)
@@ -189,5 +217,5 @@ public function save(\PDP\Integration\Api\Data\PdpDesignItemInterface $pdpDesign
189217
}
190218

191219
return $reponse;
192-
}
220+
}
193221
}

0 commit comments

Comments
 (0)