discountFactory->create(); $itemPrice = $this->validator->getItemPrice($item); $baseItemPrice = $this->validator->getItemBasePrice($item); $itemOriginalPrice = $this->validator->getItemOriginalPrice($item); $baseItemOriginalPrice = $this->validator->getItemBaseOriginalPrice($item); $x = $rule->getDiscountStep(); $y = $rule->getDiscountAmount(); if (!$x || $y > $x) { return $discountData; } $buyAndDiscountQty = $x + $y; $fullRuleQtyPeriod = floor($qty / $buyAndDiscountQty); $freeQty = $qty - $fullRuleQtyPeriod * $buyAndDiscountQty; $discountQty = $fullRuleQtyPeriod * $y; if ($freeQty > $x) { $discountQty += $freeQty - $x; } $discountData->setAmount($discountQty * $itemPrice); $discountData->setBaseAmount($discountQty * $baseItemPrice); $discountData->setOriginalAmount($discountQty * $itemOriginalPrice); $discountData->setBaseOriginalAmount($discountQty * $baseItemOriginalPrice); return $discountData; } }