Skip to content

Commit 5beb093

Browse files
committed
ACP2E-3770: No information when deleting last option from bundle
1 parent 462ede9 commit 5beb093

File tree

3 files changed

+26
-4
lines changed
  • app/code/Magento/Bundle

3 files changed

+26
-4
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
use Magento\Framework\App\RequestInterface;
1414

1515
/**
16-
* Class Bundle
16+
* Plugin class to initialize Bundle product
17+
*
1718
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1819
*/
1920
class Bundle
@@ -106,6 +107,13 @@ public function afterInitialize(
106107
$product->setBundleOptionsData($result['bundle_options']);
107108
}
108109

110+
if (!$result['bundle_selections']) {
111+
$extension = $product->getExtensionAttributes();
112+
$extension->setBundleProductOptions([]);
113+
$product->setExtensionAttributes($extension);
114+
$product->setDropOptions(true);
115+
}
116+
109117
$this->processBundleOptionsData($product);
110118
$this->processDynamicOptionsData($product);
111119
} elseif (!$compositeReadonly) {
@@ -120,6 +128,8 @@ public function afterInitialize(
120128
}
121129

122130
/**
131+
* Process Bundle Options Data
132+
*
123133
* @param \Magento\Catalog\Model\Product $product
124134
* @return void
125135
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -161,10 +171,11 @@ protected function processBundleOptionsData(\Magento\Catalog\Model\Product $prod
161171
$extension = $product->getExtensionAttributes();
162172
$extension->setBundleProductOptions($options);
163173
$product->setExtensionAttributes($extension);
164-
return;
165174
}
166175

167176
/**
177+
* Process Dynamic Options Data
178+
*
168179
* @param \Magento\Catalog\Model\Product $product
169180
* @return void
170181
*/
@@ -198,9 +209,10 @@ protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $pro
198209
}
199210

200211
/**
212+
* Build product link
213+
*
201214
* @param \Magento\Catalog\Model\Product $product
202215
* @param array $linkData
203-
*
204216
* @return \Magento\Bundle\Api\Data\LinkInterface
205217
*/
206218
private function buildLink(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ 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)
101+
&& !$entity->getDropOptions()
102+
) {
100103
return $entity;
101104
}
102105

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)