23 private $ruleColletionFactory;
33 private $resourceModelRule;
38 private $moduleDataSetup;
60 $this->ruleColletionFactory = $ruleColletionFactory;
62 $this->resourceModelRule = $resourceModelRule;
63 $this->moduleDataSetup = $moduleDataSetup;
64 $this->appState = $appState;
72 $this->moduleDataSetup->getConnection()->startSetup();
73 $this->appState->emulateAreaCode(
74 \
Magento\Backend\
App\Area\FrontNameResolver::AREA_CODE,
75 [$this,
'fillSalesRuleProductAttributeTable']
77 $this->fillSalesRuleProductAttributeTable();
78 $this->moduleDataSetup->getConnection()->endSetup();
84 public function fillSalesRuleProductAttributeTable()
87 $ruleCollection = $this->ruleColletionFactory->create();
89 foreach ($ruleCollection as
$rule) {
91 $conditions =
$rule->getConditions()->asArray();
92 $actions =
$rule->getActions()->asArray();
93 $serializedConditions = $this->serializer->serialize($conditions);
94 $serializedActions = $this->serializer->serialize($actions);
95 $conditionAttributes = $this->resourceModelRule->getProductAttributes($serializedConditions);
96 $actionAttributes = $this->resourceModelRule->getProductAttributes($serializedActions);
97 $ruleProductAttributes = array_merge($conditionAttributes, $actionAttributes);
98 if ($ruleProductAttributes) {
99 $this->resourceModelRule->setActualProductAttributes(
$rule, $ruleProductAttributes);
110 ConvertSerializedDataToJson::class
__construct(\Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory $ruleColletionFactory, \Magento\Framework\Serialize\SerializerInterface $serializer, \Magento\SalesRule\Model\ResourceModel\Rule $resourceModelRule, \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup, State $appState)