Skip to content

Commit c5c32f2

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-3770' into PR_2025_07_08_muntianu
2 parents a947b30 + 48555da commit c5c32f2

File tree

3 files changed

+38
-7
lines changed
  • app/code/Magento/Bundle

3 files changed

+38
-7
lines changed

app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
use Magento\Bundle\Api\Data\OptionInterfaceFactory as OptionFactory;
99
use Magento\Bundle\Api\Data\LinkInterfaceFactory as LinkFactory;
1010
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory;
11+
use Magento\Catalog\Api\Data\ProductInterface;
1112
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
1213
use Magento\Store\Model\StoreManagerInterface as StoreManager;
1314
use Magento\Framework\App\RequestInterface;
1415

1516
/**
16-
* Class Bundle
17+
* Plugin class to initialize Bundle product
18+
*
1719
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1820
*/
1921
class Bundle
@@ -106,12 +108,14 @@ public function afterInitialize(
106108
$product->setBundleOptionsData($result['bundle_options']);
107109
}
108110

111+
if (!$result['bundle_selections']) {
112+
$this->resetBundleProductOptions($product);
113+
}
114+
109115
$this->processBundleOptionsData($product);
110116
$this->processDynamicOptionsData($product);
111117
} elseif (!$compositeReadonly) {
112-
$extension = $product->getExtensionAttributes();
113-
$extension->setBundleProductOptions([]);
114-
$product->setExtensionAttributes($extension);
118+
$this->resetBundleProductOptions($product);
115119
}
116120

117121
$affectProductSelections = (bool)$this->request->getPost('affect_bundle_product_selections');
@@ -120,6 +124,8 @@ public function afterInitialize(
120124
}
121125

122126
/**
127+
* Process Bundle Options Data
128+
*
123129
* @param \Magento\Catalog\Model\Product $product
124130
* @return void
125131
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -161,10 +167,11 @@ protected function processBundleOptionsData(\Magento\Catalog\Model\Product $prod
161167
$extension = $product->getExtensionAttributes();
162168
$extension->setBundleProductOptions($options);
163169
$product->setExtensionAttributes($extension);
164-
return;
165170
}
166171

167172
/**
173+
* Process Dynamic Options Data
174+
*
168175
* @param \Magento\Catalog\Model\Product $product
169176
* @return void
170177
*/
@@ -198,9 +205,10 @@ protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $pro
198205
}
199206

200207
/**
208+
* Build product link
209+
*
201210
* @param \Magento\Catalog\Model\Product $product
202211
* @param array $linkData
203-
*
204212
* @return \Magento\Bundle\Api\Data\LinkInterface
205213
*/
206214
private function buildLink(
@@ -228,4 +236,18 @@ private function buildLink(
228236

229237
return $link;
230238
}
239+
240+
/**
241+
* Resets bundle product options inside product extension attributes
242+
*
243+
* @param ProductInterface $product
244+
* @return void
245+
*/
246+
private function resetBundleProductOptions(ProductInterface $product) : void
247+
{
248+
$extension = $product->getExtensionAttributes();
249+
$extension->setBundleProductOptions([]);
250+
$product->setExtensionAttributes($extension);
251+
$product->setDropOptions(true);
252+
}
231253
}

app/code/Magento/Bundle/Model/Product/SaveHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ public function execute($entity, $arguments = [])
9696
/** @var OptionInterface[] $bundleProductOptions */
9797
$bundleProductOptions = $entity->getExtensionAttributes()->getBundleProductOptions() ?: [];
9898
//Only processing bundle products.
99-
if ($entity->getTypeId() !== Type::TYPE_CODE || empty($bundleProductOptions)) {
99+
if ($entity->getTypeId() !== Type::TYPE_CODE
100+
|| (empty($bundleProductOptions) && !$entity->getDropOptions())
101+
) {
100102
return $entity;
101103
}
102104

app/code/Magento/Bundle/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/Plugin/BundleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ public function testAfterInitializeIfBundleSelectionsAndCustomOptionsExist()
173173
->method('setBundleOptionsData')
174174
->with($this->bundleOptionsCleaned);
175175
$this->productMock->expects($this->never())->method('setBundleSelectionsData');
176+
$extensionAttribute = $this->getMockBuilder(ProductExtensionInterface::class)
177+
->disableOriginalConstructor()
178+
->addMethods(['setBundleProductOptions'])
179+
->getMockForAbstractClass();
180+
$extensionAttribute->expects($this->once())->method('setBundleProductOptions')->with([]);
181+
$this->productMock->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttribute);
182+
$this->productMock->expects($this->once())->method('setExtensionAttributes')->with($extensionAttribute);
176183
$this->productMock->expects($this->once())->method('getPriceType')->willReturn(2);
177184
$this->productMock->expects($this->any())->method('getOptionsReadonly')->willReturn(true);
178185
$this->productMock->expects($this->once())->method('setCanSaveBundleSelections')->with(false);

0 commit comments

Comments
 (0)