Skip to content

Commit 3b6b038

Browse files
committed
Fix bug 26449: Set null for configurable options of parent product whenever it's saved
- Remove static function
1 parent 1071acf commit 3b6b038

File tree

1 file changed

+42
-6
lines changed
  • app/code/Magento/ConfigurableProduct/Plugin/Model/ResourceModel

1 file changed

+42
-6
lines changed

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
78
namespace Magento\ConfigurableProduct\Plugin\Model\ResourceModel;
89

910
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1011
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1112
use Magento\Framework\Indexer\ActionInterface;
1213
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
14+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1315

1416
/**
1517
* Plugin product resource model
@@ -26,18 +28,42 @@ class Product
2628
*/
2729
private $productIndexer;
2830

31+
/**
32+
* @var ProductAttributeRepositoryInterface
33+
*/
34+
private $productAttributeRepository;
35+
36+
/**
37+
* @var \Magento\Framework\Api\SearchCriteriaBuilder
38+
*/
39+
private $searchCriteriaBuilder;
40+
41+
/**
42+
* @var \Magento\Framework\Api\FilterBuilder
43+
*/
44+
private $filterBuilder;
45+
2946
/**
3047
* Initialize Product dependencies.
3148
*
3249
* @param Configurable $configurable
3350
* @param ActionInterface $productIndexer
51+
* @param ProductAttributeRepositoryInterface $productAttributeRepository
52+
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
53+
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
3454
*/
3555
public function __construct(
3656
Configurable $configurable,
37-
ActionInterface $productIndexer
57+
ActionInterface $productIndexer,
58+
ProductAttributeRepositoryInterface $productAttributeRepository,
59+
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
60+
\Magento\Framework\Api\FilterBuilder $filterBuilder
3861
) {
3962
$this->configurable = $configurable;
4063
$this->productIndexer = $productIndexer;
64+
$this->productAttributeRepository = $productAttributeRepository;
65+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
66+
$this->filterBuilder = $filterBuilder;
4167
}
4268

4369
/**
@@ -72,13 +98,23 @@ private function resetConfigurableOptionsData($object)
7298
{
7399
$extensionAttribute = $object->getExtensionAttributes();
74100
if ($extensionAttribute && $extensionAttribute->getConfigurableProductOptions()) {
75-
/** @var ProductAttributeRepositoryInterface $productAttributeRepository */
76-
$productAttributeRepository = \Magento\Framework\App\ObjectManager::getInstance()
77-
->get(ProductAttributeRepositoryInterface::class);
101+
$attributeIds = [];
78102
/** @var OptionInterface $option */
79103
foreach ($extensionAttribute->getConfigurableProductOptions() as $option) {
80-
$eavAttribute = $productAttributeRepository->get($option->getAttributeId());
81-
$object->setData($eavAttribute->getAttributeCode(), null);
104+
$attributeIds[] = $option->getAttributeId();
105+
}
106+
107+
$filter = $this->filterBuilder
108+
->setField(ProductAttributeInterface::ATTRIBUTE_ID)
109+
->setConditionType('in')
110+
->setValue($attributeIds)
111+
->create();
112+
$this->searchCriteriaBuilder->addFilters([$filter]);
113+
$searchCriteria = $this->searchCriteriaBuilder->create();
114+
$optionAttributes = $this->productAttributeRepository->getList($searchCriteria)->getItems();
115+
116+
foreach ($optionAttributes as $optionAttribute) {
117+
$object->setData($optionAttribute->getAttributeCode(), null);
82118
}
83119
}
84120
}

0 commit comments

Comments
 (0)