Exemplo n.º 1
1
 /**
  * @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate
  */
 public function testCalculate()
 {
     $this->rule->setData(['id' => 1, 'discount_amount' => 10.0]);
     $this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue([]));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
     $this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0));
     $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store));
     /** validators data */
     $this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->address->expects($this->once())->method('setCartFixedRules')->with([1 => 0.0]);
     $this->model->calculate($this->rule, $this->item, 1);
     $this->assertEquals($this->data->getAmount(), 10);
     $this->assertEquals($this->data->getBaseAmount(), 10);
     $this->assertEquals($this->data->getOriginalAmount(), 10);
     $this->assertEquals($this->data->getBaseOriginalAmount(), 100);
 }
Exemplo n.º 2
0
 /**
  * @param \Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData
  * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @return $this
  */
 protected function setDiscountData($discountData, $item)
 {
     $item->setDiscountAmount($discountData->getAmount());
     $item->setBaseDiscountAmount($discountData->getBaseAmount());
     $item->setOriginalDiscountAmount($discountData->getOriginalAmount());
     $item->setBaseOriginalDiscountAmount($discountData->getBaseOriginalAmount());
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Process "delta" rounding
  *
  * @param \Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData
  * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function deltaRoundingFix(\Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData, \Magento\Quote\Model\Quote\Item\AbstractItem $item)
 {
     $store = $item->getQuote()->getStore();
     $discountAmount = $discountData->getAmount();
     $baseDiscountAmount = $discountData->getBaseAmount();
     //TODO Seems \Magento\Quote\Model\Quote\Item\AbstractItem::getDiscountPercent() returns float value
     //that can not be used as array index
     $percentKey = $item->getDiscountPercent();
     if ($percentKey) {
         $delta = isset($this->_roundingDeltas[$percentKey]) ? $this->_roundingDeltas[$percentKey] : 0;
         $baseDelta = isset($this->_baseRoundingDeltas[$percentKey]) ? $this->_baseRoundingDeltas[$percentKey] : 0;
         $discountAmount += $delta;
         $baseDiscountAmount += $baseDelta;
         $this->_roundingDeltas[$percentKey] = $discountAmount - $this->priceCurrency->round($discountAmount);
         $this->_baseRoundingDeltas[$percentKey] = $baseDiscountAmount - $this->priceCurrency->round($baseDiscountAmount);
     }
     $discountData->setAmount($this->priceCurrency->round($discountAmount));
     $discountData->setBaseAmount($this->priceCurrency->round($baseDiscountAmount));
     return $this;
 }
Exemplo n.º 4
0
 /**
  * @param Rule\Action\Discount\Data $discountData
  * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item
  * @param float $qty
  * @return void
  */
 protected function minFix(\Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData, \Magento\Sales\Model\Quote\Item\AbstractItem $item, $qty)
 {
     $itemPrice = $this->getItemPrice($item);
     $baseItemPrice = $this->getItemBasePrice($item);
     $itemDiscountAmount = $item->getDiscountAmount();
     $itemBaseDiscountAmount = $item->getBaseDiscountAmount();
     $discountAmount = min($itemDiscountAmount + $discountData->getAmount(), $itemPrice * $qty);
     $baseDiscountAmount = min($itemBaseDiscountAmount + $discountData->getBaseAmount(), $baseItemPrice * $qty);
     $discountData->setAmount($discountAmount);
     $discountData->setBaseAmount($baseDiscountAmount);
 }