Skip to content

Commit

Permalink
Merge forwardport of #11274 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11274.patch (created by @marinagociu) based on commit(s):
  1. ae9f205
  2. f6121da

Fixed GitHub Issues in 2.3-develop branch:
  - #10477: Cart price rule has failed if use dropdown attribute (reported by @minosss)
  • Loading branch information
magento-engcom-team committed Jan 24, 2018
2 parents 2497062 + 7369261 commit 1f7347f
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 1f7347f

Please sign in to comment.