Skip to content

Commit e7ff694

Browse files
committed
Fix bug 26449:
- Set null for configurable options of parent product whenever it's saved
1 parent ecaa3b7 commit e7ff694

File tree

1 file changed

+29
-0
lines changed
  • app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel

1 file changed

+29
-0
lines changed

app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel/Product.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
*/
77
namespace Magento\ConfigurableProduct\Plugin\Model\ResourceModel;
88

9+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
910
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1011
use Magento\Framework\Indexer\ActionInterface;
12+
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
1113

14+
/**
15+
* Plugin product resource model
16+
*/
1217
class Product
1318
{
1419
/**
@@ -41,6 +46,7 @@ public function __construct(
4146
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
4247
* @param \Magento\Framework\DataObject $object
4348
* @return void
49+
* @throws \Magento\Framework\Exception\NoSuchEntityException
4450
*
4551
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4652
*/
@@ -51,6 +57,29 @@ public function beforeSave(
5157
/** @var \Magento\Catalog\Model\Product $object */
5258
if ($object->getTypeId() == Configurable::TYPE_CODE) {
5359
$object->getTypeInstance()->getSetAttributes($object);
60+
$this->resetConfigurableOptionsData($object);
61+
}
62+
}
63+
64+
/**
65+
* Set null for configurable options attribute of configurable product
66+
*
67+
* @param \Magento\Catalog\Model\Product $object
68+
* @return void
69+
* @throws \Magento\Framework\Exception\NoSuchEntityException
70+
*/
71+
private function resetConfigurableOptionsData($object)
72+
{
73+
$extensionAttribute = $object->getExtensionAttributes();
74+
if ($extensionAttribute && $extensionAttribute->getConfigurableProductOptions()) {
75+
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
76+
$productAttributeRepository = \Magento\Framework\App\ObjectManager::getInstance()
77+
->get(ProductAttributeRepositoryInterface::class);
78+
/** @var OptionInterface $option */
79+
foreach ($extensionAttribute->getConfigurableProductOptions() as $option) {
80+
$eavAttribute = $productAttributeRepository->get($option->getAttributeId());
81+
$object->setData($eavAttribute->getAttributeCode(), null);
82+
}
5483
}
5584
}
5685

0 commit comments

Comments
 (0)