Skip to content

Commit 73f9e9f

Browse files
committed
MC-35690: [B2B] Unexpected results of editing of a Bundle Product in the Shopping Cart, added from a Requisition List
1 parent 427f9bf commit 73f9e9f

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ public function getJsonConfig()
184184
$configValue = $preConfiguredValues->getData('bundle_option/' . $optionId);
185185
if ($configValue) {
186186
$defaultValues[$optionId] = $configValue;
187-
$configQty = $preConfiguredValues->getData('bundle_option_qty/' . $optionId);
188-
if ($configQty) {
189-
$options[$optionId]['selections'][$configValue]['qty'] = $configQty;
190-
}
191187
}
192188
$options = $this->processOptions($optionId, $options, $preConfiguredValues);
193189
}

app/code/Magento/Bundle/Model/CartItemProcessor.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151
}
5252

5353
/**
54-
* {@inheritdoc}
54+
* @inheritDoc
5555
*/
5656
public function convertToBuyRequest(CartItemInterface $cartItem)
5757
{
@@ -73,7 +73,7 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
7373
}
7474

7575
/**
76-
* {@inheritdoc}
76+
* @inheritDoc
7777
* @SuppressWarnings(PHPMD.NPathComplexity)
7878
*/
7979
public function processOptions(CartItemInterface $cartItem)
@@ -83,20 +83,21 @@ public function processOptions(CartItemInterface $cartItem)
8383
}
8484
$productOptions = [];
8585
$bundleOptions = $cartItem->getBuyRequest()->getBundleOption();
86-
$bundleOptionsQty = $cartItem->getBuyRequest()->getBundleOptionQty();
86+
$bundleOptionsQty = $cartItem->getBuyRequest()->getBundleOptionQty() ?? [];
8787
if (is_array($bundleOptions)) {
8888
foreach ($bundleOptions as $optionId => $optionSelections) {
8989
if (empty($optionSelections)) {
9090
continue;
9191
}
9292
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
93-
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;
9493

9594
/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */
9695
$productOption = $this->bundleOptionFactory->create();
9796
$productOption->setOptionId($optionId);
9897
$productOption->setOptionSelections($optionSelections);
99-
$productOption->setOptionQty($optionQty);
98+
if (is_array($bundleOptionsQty) && isset($bundleOptionsQty[$optionId])) {
99+
$productOption->setOptionQty($bundleOptionsQty[$optionId]);
100+
}
100101
$productOptions[] = $productOption;
101102
}
102103

dev/tests/integration/testsuite/Magento/Bundle/Block/Catalog/Product/View/Type/BundleTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
99

1010
use Magento\Bundle\Model\Product\Price;
11+
use Magento\Bundle\Model\Product\Type;
1112
use Magento\Catalog\Api\Data\ProductInterface;
1213
use Magento\Catalog\Api\ProductRepositoryInterface;
14+
use Magento\Catalog\Helper\Product as ProductHelper;
1315
use Magento\Framework\ObjectManagerInterface;
1416
use Magento\Framework\Registry;
1517
use Magento\Framework\Serialize\SerializerInterface;
1618
use Magento\Framework\View\LayoutInterface;
1719
use Magento\TestFramework\Helper\Bootstrap;
1820
use PHPUnit\Framework\TestCase;
21+
use Magento\Framework\DataObject\Factory as DataObjectFactory;
1922

2023
/**
2124
* Class checks bundle product view behaviour
@@ -87,6 +90,41 @@ public function testGetJsonConfig(): void
8790
$this->assertEquals(5, $selection['prices']['finalPrice']['amount']);
8891
}
8992

93+
/**
94+
* Check that selection qty is calculated correctly for Bundle config.
95+
*
96+
* @return void
97+
*/
98+
public function testGetJsonConfigWithPreconfiguredValues(): void
99+
{
100+
$optionQty = 3;
101+
$bundleProduct = $this->productRepository->get('bundle-product');
102+
$bundleSelection = $this->productRepository->get('simple');
103+
104+
/** @var Type $typeInstance */
105+
$typeInstance = $bundleProduct->getTypeInstance();
106+
$typeInstance->setStoreFilter($bundleProduct->getStoreId(), $bundleProduct);
107+
$optionCollection = $typeInstance->getOptionsCollection($bundleProduct);
108+
$optionId = $optionCollection->getFirstItem()->getId();
109+
$preconfiguredValues = $this->objectManager->get(DataObjectFactory::class)->create([
110+
'bundle_option' => [
111+
$optionId => [$bundleSelection->getId()]
112+
],
113+
'bundle_option_qty' => [
114+
$optionId => $optionQty
115+
],
116+
]);
117+
118+
/** @var ProductHelper $productHelper */
119+
$productHelper = $this->objectManager->get(ProductHelper::class);
120+
$productHelper->prepareProductOptions($bundleProduct, $preconfiguredValues);
121+
$this->registerProduct($bundleProduct);
122+
123+
$resultConfig = $this->json->unserialize($this->block->getJsonConfig());
124+
$this->assertTrue(isset($resultConfig['options'][$optionId]['selections'][$optionId]['qty']));
125+
$this->assertEquals($optionQty, $resultConfig['options'][$optionId]['selections'][$optionId]['qty']);
126+
}
127+
90128
/**
91129
* @dataProvider isSalableForStockStatusProvider
92130
*

0 commit comments

Comments
 (0)