diff --git a/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php b/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php
index 62a2fa1c47e1e..fa488b073f515 100644
--- a/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php
+++ b/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php
@@ -7,6 +7,7 @@
use Magento\Bundle\Model\Option;
use Magento\Catalog\Model\Product;
+use Magento\Framework\DataObject;
/**
* Catalog bundle product info block
@@ -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;
@@ -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,
]
@@ -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;
+ }
}
diff --git a/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php b/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php
index 5d326e7c01d19..ed6a4d1ad7209 100644
--- a/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php
+++ b/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php
@@ -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';
diff --git a/app/code/Magento/Bundle/Test/Mftf/Test/StorefrontEditBundleProductTest.xml b/app/code/Magento/Bundle/Test/Mftf/Test/StorefrontEditBundleProductTest.xml
index f94cd83f4e7d7..4945308c26c4a 100644
--- a/app/code/Magento/Bundle/Test/Mftf/Test/StorefrontEditBundleProductTest.xml
+++ b/app/code/Magento/Bundle/Test/Mftf/Test/StorefrontEditBundleProductTest.xml
@@ -94,9 +94,8 @@
-
-
-
+
+