Skip to content

Commit

Permalink
Check cart rule subselect conditions against quote item children too
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marinagociu committed Oct 6, 2017
1 parent 03f7ded commit ae9f205
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,22 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
$attr = $this->getAttribute();
$total = 0;
foreach ($model->getQuote()->getAllVisibleItems() as $item) {
if (parent::validate($item)) {
$total += $item->getData($attr);
$hasValidChild = false;
$useChildrenTotal = ($item->getProductType() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
$childrenAttrTotal = 0;
$children = $item->getChildren();
if (!empty($children)) {
foreach ($children as $child) {
if (parent::validate($child)) {
$hasValidChild = true;
if ($useChildrenTotal) {
$childrenAttrTotal += $child->getData($attr);
}
}
}
}
if ($hasValidChild || parent::validate($item)) {
$total += (($hasValidChild && $useChildrenTotal) ? $childrenAttrTotal : $item->getData($attr));
}
}
return $this->validateAttribute($total);
Expand Down

0 comments on commit ae9f205

Please sign in to comment.