6
6
*/
7
7
namespace Magento \ConfigurableProduct \Plugin \Model \ResourceModel ;
8
8
9
+ use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
9
10
use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
10
11
use Magento \Framework \Indexer \ActionInterface ;
12
+ use Magento \ConfigurableProduct \Api \Data \OptionInterface ;
11
13
14
+ /**
15
+ * Plugin product resource model
16
+ */
12
17
class Product
13
18
{
14
19
/**
@@ -41,6 +46,7 @@ public function __construct(
41
46
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
42
47
* @param \Magento\Framework\DataObject $object
43
48
* @return void
49
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
44
50
*
45
51
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46
52
*/
@@ -51,6 +57,29 @@ public function beforeSave(
51
57
/** @var \Magento\Catalog\Model\Product $object */
52
58
if ($ object ->getTypeId () == Configurable::TYPE_CODE ) {
53
59
$ 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
+ }
54
83
}
55
84
}
56
85
0 commit comments