Skip to content

Commit ae9f205

Browse files
committed
Check cart rule subselect conditions against quote item children too
The subselect condition only checked the visible quote items and this proved to be a problem in the case of configurable and bundle products. The quote item children are now checked against the validation too, and an item will be considered valid and added to the subselect total if either it, or at least one of it's children is validated. In the case of bundle products, the children items data will be used and added to the subselect total, when the match is on a child item. In the case of configurable products, the parent item data will be used in the subselect total, just like for all the other product types. Resolves: #10477
1 parent 03f7ded commit ae9f205

File tree

1 file changed

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

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,22 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
145145
$attr = $this->getAttribute();
146146
$total = 0;
147147
foreach ($model->getQuote()->getAllVisibleItems() as $item) {
148-
if (parent::validate($item)) {
149-
$total += $item->getData($attr);
148+
$hasValidChild = false;
149+
$useChildrenTotal = ($item->getProductType() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
150+
$childrenAttrTotal = 0;
151+
$children = $item->getChildren();
152+
if (!empty($children)) {
153+
foreach ($children as $child) {
154+
if (parent::validate($child)) {
155+
$hasValidChild = true;
156+
if ($useChildrenTotal) {
157+
$childrenAttrTotal += $child->getData($attr);
158+
}
159+
}
160+
}
161+
}
162+
if ($hasValidChild || parent::validate($item)) {
163+
$total += (($hasValidChild && $useChildrenTotal) ? $childrenAttrTotal : $item->getData($attr));
150164
}
151165
}
152166
return $this->validateAttribute($total);

0 commit comments

Comments
 (0)