Skip to content

Commit a118876

Browse files
committed
MAGETWO-64547: Bundle Products - The options you selected are not available.
Static fixes
1 parent 3026ed7 commit a118876

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public function saveChild(
168168
* @param string $linkedProductId
169169
* @param string $parentProductId
170170
* @return \Magento\Bundle\Model\Selection
171+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
171172
*/
172173
protected function mapProductLinkToSelectionModel(
173174
\Magento\Bundle\Model\Selection $selectionModel,
@@ -177,10 +178,10 @@ protected function mapProductLinkToSelectionModel(
177178
) {
178179
$selectionModel->setProductId($linkedProductId);
179180
$selectionModel->setParentProductId($parentProductId);
180-
if (($productLink->getSelectionId() !== null)) {
181+
if ($productLink->getSelectionId() !== null) {
181182
$selectionModel->setSelectionId($productLink->getSelectionId());
182183
}
183-
if (($productLink->getOptionId() !== null)) {
184+
if ($productLink->getOptionId() !== null) {
184185
$selectionModel->setOptionId($productLink->getOptionId());
185186
}
186187
if ($productLink->getPosition() !== null) {

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

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

6767
if (!$entity->getCopyFromView()) {
68+
$updatedOptions = [];
6869
$oldOptions = $this->optionRepository->getList($entity->getSku());
6970

7071
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
7172

7273
$productId = $entity->getData($metadata->getLinkField());
7374

7475
foreach ($options as $option) {
75-
if ($option->getOptionId()) {
76-
$updatedOptions[$option->getOptionId()][$productId] = true;
77-
}
76+
$updatedOptions[$option->getOptionId()][$productId] = (bool)$option->getOptionId();
7877
}
7978

8079
foreach ($oldOptions as $option) {
8180
if (!isset($updatedOptions[$option->getOptionId()][$productId])) {
8281
$option->setParentId($productId);
83-
8482
$this->removeOptionLinks($entity->getSku(), $option);
85-
8683
$this->optionRepository->delete($option);
8784
}
8885
}
86+
}
8987

90-
foreach ($options as $option) {
91-
$this->optionRepository->save($entity, $option);
92-
}
93-
} else {
94-
//save only labels and not selections + product links
95-
foreach ($options as $option) {
96-
$this->optionRepository->save($entity, $option);
97-
}
98-
$entity->setCopyFromView(false);
88+
foreach ($options as $option) {
89+
$this->optionRepository->save($entity, $option);
9990
}
10091

92+
$entity->setCopyFromView(false);
93+
10194
return $entity;
10295
}
10396

0 commit comments

Comments
 (0)