From 7369261d82e0e5ad926eaf4ccb2a8def79c4fcbb Mon Sep 17 00:00:00 2001 From: Magento EngCom Team Date: Tue, 23 Jan 2018 11:00:17 -0600 Subject: [PATCH] :arrow_double_up: Forwardport of magento/magento2#11274 to 2.3-develop branch Applied pull request patch https://github.com/magento/magento2/pull/11274.patch (created by @marinagociu) based on commit(s): 1. ae9f2050e0cb5dad500d39be9fd42e1116b9f60e 2. f6121da1dd59ba4097a9c706b25d6fcbc9202279 Fixed GitHub Issues in 2.3-develop branch: - magento/magento2#10477: Cart price rule has failed if use dropdown attribute (reported by @minosss) --- .../Rule/Condition/Product/Subselect.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php b/app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php index 108cc341253ae..1e8fbf43ec3bc 100644 --- a/app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php +++ b/app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php @@ -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) { @@ -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);