Skip to content

Commit 1946914

Browse files
committed
MAGETWO-94407: [2.3.0] Cart Price Rule for configurable products
- Fix static tests
1 parent 805790d commit 1946914

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

app/code/Magento/SalesRule/Model/Rule/Condition/Product.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ public function loadAttributeOptions()
6666
$attributes = [];
6767
foreach ($productAttributes as $attribute) {
6868
/* @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
69-
if (!$attribute->isAllowedForRuleCondition() || !$attribute->getDataUsingMethod(
70-
$this->_isUsedForRuleProperty
71-
)
69+
if (!$attribute->isAllowedForRuleCondition()
70+
|| !$attribute->getDataUsingMethod($this->_isUsedForRuleProperty)
7271
) {
7372
continue;
7473
}

app/code/Magento/SalesRule/Model/Rule/Condition/Product/Combine.php

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,7 @@ protected function _isValid($entity)
100100

101101
foreach ($this->getConditions() as $cond) {
102102
if ($entity instanceof \Magento\Framework\Model\AbstractModel) {
103-
$attributeScope = $cond->getAttributeScope();
104-
if ($attributeScope === 'parent') {
105-
$validateEntities = [$entity];
106-
} elseif ($attributeScope === 'children') {
107-
$validateEntities = $entity->getChildren() ?: [$entity];
108-
} else {
109-
$validateEntities = $entity->getChildren() ?: [];
110-
$validateEntities[] = $entity;
111-
}
112-
$validated = !$true;
113-
foreach ($validateEntities as $validateEntity) {
114-
$validated = $cond->validate($validateEntity);
115-
if ($validated === $true) {
116-
break;
117-
}
118-
}
103+
$validated = $this->validateEntity($cond, $entity);
119104
} else {
120105
$validated = $cond->validateByEntityId($entity);
121106
}
@@ -127,4 +112,44 @@ protected function _isValid($entity)
127112
}
128113
return $all ? true : false;
129114
}
115+
116+
/**
117+
* @param object $cond
118+
* @param \Magento\Framework\Model\AbstractModel $entity
119+
* @return bool
120+
*/
121+
private function validateEntity($cond, \Magento\Framework\Model\AbstractModel $entity)
122+
{
123+
$true = (bool)$this->getValue();
124+
$validated = !$true;
125+
foreach ($this->retrieveValidateEntities($cond->getAttributeScope(), $entity) as $validateEntity) {
126+
$validated = $cond->validate($validateEntity);
127+
if ($validated === $true) {
128+
break;
129+
}
130+
}
131+
132+
return $validated;
133+
}
134+
135+
/**
136+
* Retrieve entities for validation by attribute scope
137+
*
138+
* @param $attributeScope
139+
* @param \Magento\Framework\Model\AbstractModel $entity
140+
* @return \Magento\Framework\Model\AbstractModel[]
141+
*/
142+
private function retrieveValidateEntities($attributeScope, \Magento\Framework\Model\AbstractModel $entity)
143+
{
144+
if ($attributeScope === 'parent') {
145+
$validateEntities = [$entity];
146+
} elseif ($attributeScope === 'children') {
147+
$validateEntities = $entity->getChildren() ?: [$entity];
148+
} else {
149+
$validateEntities = $entity->getChildren() ?: [];
150+
$validateEntities[] = $entity;
151+
}
152+
153+
return $validateEntities;
154+
}
130155
}

0 commit comments

Comments
 (0)