protected function applyRule($item, $rule) { $qty = 2; $discountCalc = $this->getMock('Magento\\SalesRule\\Model\\Rule\\Action\\Discount', ['fixQuantity', 'calculate'], [], '', false); $discountData = $this->getMock('Magento\\SalesRule\\Model\\Rule\\Action\\Discount\\Data', [], ['amount' => 30, 'baseAmount' => 30, 'originalAmount' => 30, 'baseOriginalAmount' => 30], '', false); $this->validatorUtility->expects($this->any())->method('getItemQty')->with($this->anything(), $this->anything())->will($this->returnValue($qty)); $discountCalc->expects($this->any())->method('fixQuantity')->with($this->equalTo($qty), $this->equalTo($rule))->will($this->returnValue($qty)); $discountCalc->expects($this->any())->method('calculate')->with($this->equalTo($rule), $this->equalTo($item), $this->equalTo($qty))->will($this->returnValue($discountData)); $this->calculatorFactory->expects($this->any())->method('create')->with($this->anything())->will($this->returnValue($discountCalc)); }
/** * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item * @param \Magento\SalesRule\Model\Rule $rule * @return Rule\Action\Discount\Data */ protected function getDiscountData($item, $rule) { $qty = $this->_getItemQty($item, $rule); $discountCalculator = $this->calculatorFactory->create($rule->getSimpleAction()); $qty = $discountCalculator->fixQuantity($qty, $rule); $discountData = $discountCalculator->calculate($rule, $item, $qty); $this->eventFix($discountData, $item, $rule, $qty); $this->deltaRoundingFix($discountData, $item); /** * We can't use row total here because row total not include tax * Discount can be applied on price included tax */ $this->minFix($discountData, $item, $qty); return $discountData; }