diff --git a/vendor/magento/module-target-rule/Model/ResourceModel/Index.php b/vendor/magento/module-target-rule/Model/ResourceModel/Index.php index 4f9a53eb781..669fe639baa 100644 --- a/vendor/magento/module-target-rule/Model/ResourceModel/Index.php +++ b/vendor/magento/module-target-rule/Model/ResourceModel/Index.php @@ -45,22 +45,16 @@ class Index extends AbstractDb protected $_bindIncrement = 0; /** - * Target rule data - * * @var TargetRuleHelper */ protected $_targetRuleData; /** - * Core registry - * * @var Registry */ protected $_coreRegistry; /** - * Customer segment data - * * @var CustomerSegmentHelper */ protected $_customerSegmentData; @@ -334,7 +328,7 @@ class Index extends AbstractDb $select->columns('entity_id', 'e'); $select->limit($limit); - $bind = $this->_prepareRuleActionSelectBind($object, $actionBind); + $bind = $this->_prepareRuleActionSelectBind($object, $actionBind, $rule); $result = $this->getConnection()->fetchCol($select, $bind); return $result; @@ -345,10 +339,12 @@ class Index extends AbstractDb * * @param TargetRuleIndex $object * @param array $actionBind + * @param Rule $rule * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) */ - protected function _prepareRuleActionSelectBind($object, $actionBind) + protected function _prepareRuleActionSelectBind($object, $actionBind, $rule) { $bind = []; if (!is_array($actionBind)) { @@ -361,7 +357,8 @@ class Index extends AbstractDb continue; } $k = $bindData['bind']; - $v = $object->getProduct()->getDataUsingMethod($bindData['field']); + $v = ($bindData['field'] === 'category_ids') ? $this->extractCategoryIdsFromRule($rule) : + $object->getProduct()->getDataUsingMethod($bindData['field']); if (!empty($bindData['callback'])) { $callbacks = $bindData['callback']; @@ -387,6 +384,25 @@ class Index extends AbstractDb return $bind; } + /** + * Extracts Category ids from Rule + * + * @param Rule $rule + * @return string + */ + private function extractCategoryIdsFromRule(Rule $rule): string + { + $value = ''; + foreach ($rule->getConditions()->getConditions() as $condition) { + if ($condition->getAttribute() === 'category_ids') { + $value = $condition->getValue(); + break; + } + } + + return $value; + } + /** * Retrieve new SELECT instance (used Read Adapter) *