From ae9f2050e0cb5dad500d39be9fd42e1116b9f60e Mon Sep 17 00:00:00 2001 From: marina Date: Fri, 6 Oct 2017 17:03:42 +0300 Subject: [PATCH 1/2] Check cart rule subselect conditions against quote item children too 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 --- .../Model/Rule/Condition/Product/Subselect.php | 18 ++++++++++++++++-- 1 file changed, 16 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..51b5aea31143f 100644 --- a/app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php +++ b/app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php @@ -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); From f6121da1dd59ba4097a9c706b25d6fcbc9202279 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 24 Oct 2017 23:15:12 +0300 Subject: [PATCH 2/2] Add suppress warning for cyclomatic complexity threshold --- .../Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php | 1 + 1 file changed, 1 insertion(+) 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 51b5aea31143f..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) {