Skip to content

Commit 83eac4e

Browse files
ENGCOM-3161: [Forwardport] #4942 and bundle checkbox bug #18520
- Merge Pull Request #18520 from gelanivishal/magento2:2.3-develop-PR-port-15905 - Merged commits: 1. e210b70 2. 53f5942 3. 8050d50 4. 0bd75c8
2 parents de50d12 + 0bd75c8 commit 83eac4e

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
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
@@ -170,7 +171,7 @@ public function getJsonConfig()
170171

171172
$defaultValues = [];
172173
$preConfiguredFlag = $currentProduct->hasPreconfiguredValues();
173-
/** @var \Magento\Framework\DataObject|null $preConfiguredValues */
174+
/** @var DataObject|null $preConfiguredValues */
174175
$preConfiguredValues = $preConfiguredFlag ? $currentProduct->getPreconfiguredValues() : null;
175176

176177
$position = 0;
@@ -193,12 +194,13 @@ public function getJsonConfig()
193194
$options[$optionId]['selections'][$configValue]['qty'] = $configQty;
194195
}
195196
}
197+
$options = $this->processOptions($optionId, $options, $preConfiguredValues);
196198
}
197199
$position++;
198200
}
199201
$config = $this->getConfigData($currentProduct, $options);
200202

201-
$configObj = new \Magento\Framework\DataObject(
203+
$configObj = new DataObject(
202204
[
203205
'config' => $config,
204206
]
@@ -403,4 +405,30 @@ private function getConfigData(Product $product, array $options)
403405
];
404406
return $config;
405407
}
408+
409+
/**
410+
* Set preconfigured quantities and selections to options.
411+
*
412+
* @param string $optionId
413+
* @param array $options
414+
* @param DataObject $preConfiguredValues
415+
* @return array
416+
*/
417+
private function processOptions(string $optionId, array $options, DataObject $preConfiguredValues)
418+
{
419+
$preConfiguredQtys = $preConfiguredValues->getData("bundle_option_qty/${optionId}") ?? [];
420+
$selections = $options[$optionId]['selections'];
421+
array_walk($selections, function (&$selection, $selectionId) use ($preConfiguredQtys) {
422+
if (is_array($preConfiguredQtys) && isset($preConfiguredQtys[$selectionId])) {
423+
$selection['qty'] = $preConfiguredQtys[$selectionId];
424+
} else {
425+
if ((int)$preConfiguredQtys > 0) {
426+
$selection['qty'] = $preConfiguredQtys;
427+
}
428+
}
429+
});
430+
$options[$optionId]['selections'] = $selections;
431+
432+
return $options;
433+
}
406434
}

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
@@ -167,7 +167,9 @@ protected function _getSelectedOptions()
167167
*/
168168
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
169169
{
170-
if ($selectionId && $option->getSelectionById($selectionId)) {
170+
if (is_array($selectionId)) {
171+
$this->_selectedOptions = $selectionId;
172+
} else if ($selectionId && $option->getSelectionById($selectionId)) {
171173
$this->_selectedOptions = $selectionId;
172174
} elseif (!$option->getRequired()) {
173175
$this->_selectedOptions = 'None';

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@
9494
<click stepKey="clickEdit" selector="{{CheckoutCartProductSection.nthEditButton('1')}}"/>
9595
<waitForPageLoad stepKey="waitForStorefront2"/>
9696

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

101100
<waitForPageLoad stepKey="waitForPriceUpdate3"/>
102101
<see stepKey="seeDoublePrice" selector="{{StorefrontBundledSection.configuredPrice}}" userInput="2,460.00"/>

0 commit comments

Comments
 (0)