Skip to content

Commit 5c2d208

Browse files
committed
MAGETWO-70540: Edit bundle product from shopping cart work unexpected
1 parent 9842136 commit 5c2d208

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function getDefaultValues()
142142
*/
143143
protected function _getSelectedOptions()
144144
{
145-
if (is_null($this->_selectedOptions)) {
145+
if ($this->_selectedOptions === null) {
146146
$this->_selectedOptions = [];
147147

148148
/** @var \Magento\Bundle\Model\Option $option */
@@ -152,17 +152,29 @@ protected function _getSelectedOptions()
152152
$selectionId = $this->getProduct()->getPreconfiguredValues()->getData(
153153
'bundle_option/' . $option->getId()
154154
);
155-
if ($selectionId && $option->getSelectionById($selectionId)) {
156-
$this->_selectedOptions = $selectionId;
157-
} elseif (!$option->getRequired()) {
158-
$this->_selectedOptions = 'None';
159-
}
155+
$this->assignSelection($option, $selectionId);
160156
}
161157
}
162158

163159
return $this->_selectedOptions;
164160
}
165161

162+
/**
163+
* Set selected options.
164+
*
165+
* @param \Magento\Bundle\Model\Option $option
166+
* @param mixed $selectionId
167+
* @return void
168+
*/
169+
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
170+
{
171+
if ($selectionId && $option->getSelectionById($selectionId)) {
172+
$this->_selectedOptions = $selectionId;
173+
} elseif (!$option->getRequired()) {
174+
$this->_selectedOptions = 'None';
175+
}
176+
}
177+
166178
/**
167179
* Define if selection is selected
168180
*

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,16 @@ class Multi extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
2121
/**
2222
* @inheritdoc
2323
*/
24-
protected function _getSelectedOptions()
24+
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
2525
{
26-
if ($this->_selectedOptions === null) {
27-
$this->_selectedOptions = [];
28-
/** @var \Magento\Bundle\Model\Option $option */
29-
$option = $this->getOption();
30-
if ($this->getProduct()->hasPreconfiguredValues()) {
31-
$selectionIds = $this->getProduct()->getPreconfiguredValues()->getData(
32-
'bundle_option/' . $option->getId()
33-
);
34-
foreach ($selectionIds as $selectionId) {
35-
if ($selectionId && $option->getSelectionById($selectionId)) {
36-
$this->_selectedOptions[] = $selectionId;
37-
}
26+
if (is_array($selectionId)) {
27+
foreach ($selectionId as $id) {
28+
if ($id && $option->getSelectionById($id)) {
29+
$this->_selectedOptions[] = $id;
3830
}
3931
}
32+
} else {
33+
parent::assignSelection($option, $selectionId);
4034
}
41-
42-
return $this->_selectedOptions;
4335
}
4436
}

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/options.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
<?php
1212
$product = $block->getProduct();
1313
$helper = $this->helper('Magento\Catalog\Helper\Output');
14+
$stripSelection = $product->getConfigureMode() ? true : false;
15+
$options = $block->decorateArray($block->getOptions($stripSelection));
1416
?>
15-
<?php $options = $block->decorateArray($block->getOptions($product->getConfigureMode())); ?>
1617
<?php if ($product->isSaleable()):?>
1718
<?php if (count($options)): ?>
1819
<script type="text/x-magento-init">

0 commit comments

Comments
 (0)