Skip to content

Commit ed897e3

Browse files
committed
MAGETWO-81161: Fix #10477 Check cart rule subselect conditions against quote item children too #11274
- Merge Pull Request #11274 from marinagociu/magento2:fix-cart-rule-subselect - Merged commits: 1. ae9f205 2. f6121da
2 parents fd8dcad + f6121da commit ed897e3

File tree

1 file changed

+17
-2
lines changed
  • app/code/Magento/SalesRule/Model/Rule/Condition/Product

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public function asHtml()
136136
*
137137
* @param \Magento\Framework\Model\AbstractModel $model
138138
* @return bool
139+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
139140
*/
140141
public function validate(\Magento\Framework\Model\AbstractModel $model)
141142
{
@@ -145,8 +146,22 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
145146
$attr = $this->getAttribute();
146147
$total = 0;
147148
foreach ($model->getQuote()->getAllVisibleItems() as $item) {
148-
if (parent::validate($item)) {
149-
$total += $item->getData($attr);
149+
$hasValidChild = false;
150+
$useChildrenTotal = ($item->getProductType() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
151+
$childrenAttrTotal = 0;
152+
$children = $item->getChildren();
153+
if (!empty($children)) {
154+
foreach ($children as $child) {
155+
if (parent::validate($child)) {
156+
$hasValidChild = true;
157+
if ($useChildrenTotal) {
158+
$childrenAttrTotal += $child->getData($attr);
159+
}
160+
}
161+
}
162+
}
163+
if ($hasValidChild || parent::validate($item)) {
164+
$total += (($hasValidChild && $useChildrenTotal) ? $childrenAttrTotal : $item->getData($attr));
150165
}
151166
}
152167
return $this->validateAttribute($total);

0 commit comments

Comments
 (0)