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

 - Merge Pull Request #11274 from marinagociu/magento2:fix-cart-rule-subselect
 - Merged commits:
   1. ae9f205
   2. f6121da
  • Loading branch information
fooman committed Nov 9, 2017
2 parents fd8dcad + f6121da commit ed897e3
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

0 comments on commit ed897e3

Please sign in to comment.