File tree 1 file changed +17
-2
lines changed
app/code/Magento/SalesRule/Model/Rule/Condition/Product
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ public function asHtml()
136
136
*
137
137
* @param \Magento\Framework\Model\AbstractModel $model
138
138
* @return bool
139
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
139
140
*/
140
141
public function validate (\Magento \Framework \Model \AbstractModel $ model )
141
142
{
@@ -145,8 +146,22 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
145
146
$ attr = $ this ->getAttribute ();
146
147
$ total = 0 ;
147
148
foreach ($ model ->getQuote ()->getAllVisibleItems () as $ item ) {
148
- if (parent ::validate ($ item )) {
149
- $ total += $ item ->getData ($ attr );
149
+ $ hasValidChild = false ;
150
+ $ useChildrenTotal = ($ item ->getProductType () == \Magento \Catalog \Model \Product \Type::TYPE_BUNDLE );
151
+ $ childrenAttrTotal = 0 ;
152
+ $ children = $ item ->getChildren ();
153
+ if (!empty ($ children )) {
154
+ foreach ($ children as $ child ) {
155
+ if (parent ::validate ($ child )) {
156
+ $ hasValidChild = true ;
157
+ if ($ useChildrenTotal ) {
158
+ $ childrenAttrTotal += $ child ->getData ($ attr );
159
+ }
160
+ }
161
+ }
162
+ }
163
+ if ($ hasValidChild || parent ::validate ($ item )) {
164
+ $ total += (($ hasValidChild && $ useChildrenTotal ) ? $ childrenAttrTotal : $ item ->getData ($ attr ));
150
165
}
151
166
}
152
167
return $ this ->validateAttribute ($ total );
You can’t perform that action at this time.
0 commit comments