ruleColletionFactory = $ruleColletionFactory; $this->serializer = $serializer; $this->resourceModelRule = $resourceModelRule; $this->moduleDataSetup = $moduleDataSetup; $this->appState = $appState; } /** * @inheritdoc */ public function apply() { $this->moduleDataSetup->getConnection()->startSetup(); $this->appState->emulateAreaCode( \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, [$this, 'fillSalesRuleProductAttributeTable'] ); $this->fillSalesRuleProductAttributeTable(); $this->moduleDataSetup->getConnection()->endSetup(); } /** * Fill attribute table for sales rule */ public function fillSalesRuleProductAttributeTable() { /** @var \Magento\SalesRule\Model\ResourceModel\Rule\Collection $ruleCollection */ $ruleCollection = $this->ruleColletionFactory->create(); /** @var \Magento\SalesRule\Model\Rule $rule */ foreach ($ruleCollection as $rule) { // Save product attributes used in rule $conditions = $rule->getConditions()->asArray(); $actions = $rule->getActions()->asArray(); $serializedConditions = $this->serializer->serialize($conditions); $serializedActions = $this->serializer->serialize($actions); $conditionAttributes = $this->resourceModelRule->getProductAttributes($serializedConditions); $actionAttributes = $this->resourceModelRule->getProductAttributes($serializedActions); $ruleProductAttributes = array_merge($conditionAttributes, $actionAttributes); if ($ruleProductAttributes) { $this->resourceModelRule->setActualProductAttributes($rule, $ruleProductAttributes); } } } /** * @inheritdoc */ public static function getDependencies() { return [ ConvertSerializedDataToJson::class ]; } /** * @inheritdoc */ public static function getVersion() { return '2.0.3'; } /** * @inheritdoc */ public function getAliases() { return []; } }