Skip to content

Commit

Permalink
MAGETWO-81161: Fix #10477 Check cart rule subselect conditions agains…
Browse files Browse the repository at this point in the history
…t quote item children too #11274
  • Loading branch information
Oleksii Korshenko authored Nov 13, 2017
2 parents 2033c05 + ed897e3 commit e7c3cf0
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function asHtml()
*
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
Expand All @@ -145,8 +146,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

1 comment on commit e7c3cf0

@robyerevan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.