Skip to content

Commit

Permalink
#26622 - Reduce cyclomatic complexity of initTotals function
Browse files Browse the repository at this point in the history
  • Loading branch information
aligent-lturner committed Feb 5, 2020
1 parent 90c3540 commit 5f4cc5f
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions app/code/Magento/SalesRule/Model/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,7 @@ public function initTotals($items, Address $address)

foreach ($items as $item) {
//Skipping child items to avoid double calculations
if ($item->getParentItemId() || $item->getParentItem()) {
continue;
}
if (!$rule->getActions()->validate($item)) {
continue;
}
if (!$this->canApplyDiscount($item)) {
if (!$this->isValidItemForRule($item, $rule)) {
continue;
}
$qty = $this->validatorUtility->getItemQty($item, $rule);
Expand All @@ -409,6 +403,32 @@ public function initTotals($items, Address $address)
return $this;
}

/**
* Determine if quote item is valid for a given sales rule
* @param AbstractItem $item
* @param Rule $rule
* @return bool
*/
protected function isValidItemForRule(
AbstractItem $item,
Rule $rule
) {
/** @var AbstractItem $item */
if ($item->getParentItemId()) {
return false;
}
if ($item->getParentItem()) {
return false;
}
if (!$rule->getActions()->validate($item)) {
return false;
}
if (!$this->canApplyDiscount($item)) {
return false;
}
return true;
}

/**
* Return item price
*
Expand Down

0 comments on commit 5f4cc5f

Please sign in to comment.