Skip to content

Commit 8552389

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-73718: Bundle simple products stays unchanged after scheduled update end
1 parent 87e96d3 commit 8552389

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

app/code/Magento/Bundle/Model/OptionRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public function save(
201201

202202
/** @var \Magento\Bundle\Model\Option $existingOption */
203203
$existingOption = $optionCollection->getFirstItem();
204-
if (!$optionId) {
205-
$option->setOptionId(null);
206-
}
207204
if (!$optionId || $existingOption->getParentId() != $parentId) {
205+
//If option ID is empty or existing option's parent ID is different
206+
//we'd need a new ID for the option.
207+
$option->setOptionId(null);
208208
$option->setDefaultTitle($option->getTitle());
209209
if (is_array($option->getProductLinks())) {
210210
$linksToAdd = $option->getProductLinks();

app/code/Magento/Bundle/Model/Product/SaveHandler.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ public function execute($entity, $arguments = [])
6565
}
6666

6767
if (!$entity->getCopyFromView()) {
68-
$updatedOptions = [];
6968
$oldOptions = $this->optionRepository->getList($entity->getSku());
70-
71-
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
72-
73-
$productId = $entity->getData($metadata->getLinkField());
74-
75-
foreach ($options as $option) {
76-
$updatedOptions[$option->getOptionId()][$productId] = (bool)$option->getOptionId();
77-
}
78-
79-
foreach ($oldOptions as $option) {
80-
if (!isset($updatedOptions[$option->getOptionId()][$productId])) {
81-
$option->setParentId($productId);
82-
$this->removeOptionLinks($entity->getSku(), $option);
83-
$this->optionRepository->delete($option);
69+
if ($oldOptions) {
70+
$remainingOptions = [];
71+
$metadata
72+
= $this->metadataPool->getMetadata(ProductInterface::class);
73+
$productId = $entity->getData($metadata->getLinkField());
74+
75+
foreach ($options as $option) {
76+
$remainingOptions[] = $option->getOptionId();
77+
}
78+
foreach ($oldOptions as $option) {
79+
if (!in_array($option->getOptionId(), $remainingOptions)) {
80+
$option->setParentId($productId);
81+
$this->removeOptionLinks($entity->getSku(), $option);
82+
$this->optionRepository->delete($option);
83+
}
8484
}
8585
}
8686
}

0 commit comments

Comments
 (0)