コード例 #1
0
ファイル: Utility.php プロジェクト: zhangjiachao/magento2
 /**
  * Process "delta" rounding
  *
  * @param \Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData
  * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item
  * @return $this
  */
 public function deltaRoundingFix(\Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData, \Magento\Sales\Model\Quote\Item\AbstractItem $item)
 {
     $store = $item->getQuote()->getStore();
     $discountAmount = $discountData->getAmount();
     $baseDiscountAmount = $discountData->getBaseAmount();
     //TODO Seems \Magento\Sales\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;
 }