Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Bundle\Model\Option;
use Magento\Catalog\Model\Product;
use Magento\Framework\DataObject;

/**
* Catalog bundle product info block
Expand Down Expand Up @@ -170,7 +171,7 @@ public function getJsonConfig()

$defaultValues = [];
$preConfiguredFlag = $currentProduct->hasPreconfiguredValues();
/** @var \Magento\Framework\DataObject|null $preConfiguredValues */
/** @var DataObject|null $preConfiguredValues */
$preConfiguredValues = $preConfiguredFlag ? $currentProduct->getPreconfiguredValues() : null;

$position = 0;
Expand All @@ -193,12 +194,13 @@ public function getJsonConfig()
$options[$optionId]['selections'][$configValue]['qty'] = $configQty;
}
}
$options = $this->processOptions($optionId, $options, $preConfiguredValues);
}
$position++;
}
$config = $this->getConfigData($currentProduct, $options);

$configObj = new \Magento\Framework\DataObject(
$configObj = new DataObject(
[
'config' => $config,
]
Expand Down Expand Up @@ -403,4 +405,30 @@ private function getConfigData(Product $product, array $options)
];
return $config;
}

/**
* Set preconfigured quantities and selections to options.
*
* @param string $optionId
* @param array $options
* @param DataObject $preConfiguredValues
* @return array
*/
private function processOptions(string $optionId, array $options, DataObject $preConfiguredValues)
{
$preConfiguredQtys = $preConfiguredValues->getData("bundle_option_qty/${optionId}") ?? [];
$selections = $options[$optionId]['selections'];
array_walk($selections, function (&$selection, $selectionId) use ($preConfiguredQtys) {
if (is_array($preConfiguredQtys) && isset($preConfiguredQtys[$selectionId])) {
$selection['qty'] = $preConfiguredQtys[$selectionId];
} else {
if ((int)$preConfiguredQtys > 0) {
$selection['qty'] = $preConfiguredQtys;
}
}
});
$options[$optionId]['selections'] = $selections;

return $options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ protected function _getSelectedOptions()
*/
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
{
if ($selectionId && $option->getSelectionById($selectionId)) {
if (is_array($selectionId)) {
$this->_selectedOptions = $selectionId;
} else if ($selectionId && $option->getSelectionById($selectionId)) {
$this->_selectedOptions = $selectionId;
} elseif (!$option->getRequired()) {
$this->_selectedOptions = 'None';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@
<click stepKey="clickEdit" selector="{{CheckoutCartProductSection.nthEditButton('1')}}"/>
<waitForPageLoad stepKey="waitForStorefront2"/>

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

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