Skip to content

Commit 533979f

Browse files
author
Stanislav Idolov
authored
ENGCOM-2997: #4942 and bundle checkbox bug #15905
2 parents 11d9560 + eabe665 commit 533979f

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Bundle\Model\Option;
99
use Magento\Catalog\Model\Product;
10+
use Magento\Framework\DataObject;
1011

1112
/**
1213
* Catalog bundle product info block
@@ -166,7 +167,7 @@ public function getJsonConfig()
166167

167168
$defaultValues = [];
168169
$preConfiguredFlag = $currentProduct->hasPreconfiguredValues();
169-
/** @var \Magento\Framework\DataObject|null $preConfiguredValues */
170+
/** @var DataObject|null $preConfiguredValues */
170171
$preConfiguredValues = $preConfiguredFlag ? $currentProduct->getPreconfiguredValues() : null;
171172

172173
$position = 0;
@@ -185,12 +186,13 @@ public function getJsonConfig()
185186
if ($configValue) {
186187
$defaultValues[$optionId] = $configValue;
187188
}
189+
$options = $this->processOptions($optionId, $options, $preConfiguredValues);
188190
}
189191
$position++;
190192
}
191193
$config = $this->getConfigData($currentProduct, $options);
192194

193-
$configObj = new \Magento\Framework\DataObject(
195+
$configObj = new DataObject(
194196
[
195197
'config' => $config,
196198
]
@@ -393,4 +395,30 @@ private function getConfigData(Product $product, array $options)
393395
];
394396
return $config;
395397
}
398+
399+
/**
400+
* Set preconfigured quantities and selections to options.
401+
*
402+
* @param string $optionId
403+
* @param array $options
404+
* @param DataObject $preConfiguredValues
405+
* @return array
406+
*/
407+
private function processOptions(string $optionId, array $options, DataObject $preConfiguredValues)
408+
{
409+
$preConfiguredQtys = $preConfiguredValues->getData("bundle_option_qty/${optionId}") ?? [];
410+
$selections = $options[$optionId]['selections'];
411+
array_walk($selections, function (&$selection, $selectionId) use ($preConfiguredQtys) {
412+
if (is_array($preConfiguredQtys) && isset($preConfiguredQtys[$selectionId])) {
413+
$selection['qty'] = $preConfiguredQtys[$selectionId];
414+
} else {
415+
if ((int)$preConfiguredQtys > 0) {
416+
$selection['qty'] = $preConfiguredQtys;
417+
}
418+
}
419+
});
420+
$options[$optionId]['selections'] = $selections;
421+
422+
return $options;
423+
}
396424
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ protected function _getSelectedOptions()
169169
*/
170170
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
171171
{
172-
if ($selectionId && $option->getSelectionById($selectionId)) {
172+
if (is_array($selectionId)) {
173+
$this->_selectedOptions = $selectionId;
174+
} else if ($selectionId && $option->getSelectionById($selectionId)) {
173175
$this->_selectedOptions = $selectionId;
174176
} elseif (!$option->getRequired()) {
175177
$this->_selectedOptions = 'None';

app/code/Magento/Bundle/Test/Mftf/Test/StorefrontEditBundleProductTest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@
9696
<click selector="{{CheckoutCartProductSection.editItemParametersButton('1')}}" stepKey="clickEdit"/>
9797
<waitForPageLoad stepKey="waitForStorefront2"/>
9898

99-
<!-- Choose both of the options on the storefront -->
100-
<click selector="{{StorefrontBundledSection.bundleOption('1','1')}}" stepKey="selectFirstBundleOption2"/>
99+
<!-- Check second one option to choose both of the options on the storefront -->
101100
<click selector="{{StorefrontBundledSection.bundleOption('1','2')}}" stepKey="selectSecondBundleOption2"/>
102101

103102
<waitForPageLoad stepKey="waitForPriceUpdate3"/>

0 commit comments

Comments
 (0)