当前位置: 首页>>代码示例>>PHP>>正文


PHP Creditmemo::setBaseShippingAmount方法代码示例

本文整理汇总了PHP中Magento\Sales\Model\Order\Creditmemo::setBaseShippingAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Creditmemo::setBaseShippingAmount方法的具体用法?PHP Creditmemo::setBaseShippingAmount怎么用?PHP Creditmemo::setBaseShippingAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Sales\Model\Order\Creditmemo的用法示例。


在下文中一共展示了Creditmemo::setBaseShippingAmount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: collect

 /**
  * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     $allowedAmount = $order->getShippingAmount() - $order->getShippingRefunded();
     $baseAllowedAmount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded();
     $orderShippingAmount = $order->getShippingAmount();
     $orderBaseShippingAmount = $order->getBaseShippingAmount();
     $orderShippingInclTax = $order->getShippingInclTax();
     $orderBaseShippingInclTax = $order->getBaseShippingInclTax();
     $shippingAmount = $baseShippingAmount = $shippingInclTax = $baseShippingInclTax = 0;
     /**
      * Check if shipping amount was specified (from invoice or another source).
      * Using has magic method to allow setting 0 as shipping amount.
      */
     if ($creditmemo->hasBaseShippingAmount()) {
         $baseShippingAmount = $this->priceCurrency->round($creditmemo->getBaseShippingAmount());
         /*
          * Rounded allowed shipping refund amount is the highest acceptable shipping refund amount.
          * Shipping refund amount shouldn't cause errors, if it doesn't exceed that limit.
          * Note: ($x < $y + 0.0001) means ($x <= $y) for floats
          */
         if ($baseShippingAmount < $this->priceCurrency->round($baseAllowedAmount) + 0.0001) {
             $ratio = 0;
             if ($orderBaseShippingAmount > 0) {
                 $ratio = $baseShippingAmount / $orderBaseShippingAmount;
             }
             /*
              * Shipping refund amount should be equated to allowed refund amount,
              * if it exceeds that limit.
              * Note: ($x > $y - 0.0001) means ($x >= $y) for floats
              */
             if ($baseShippingAmount > $baseAllowedAmount - 0.0001) {
                 $shippingAmount = $allowedAmount;
                 $baseShippingAmount = $baseAllowedAmount;
             } else {
                 $shippingAmount = $this->priceCurrency->round($orderShippingAmount * $ratio);
             }
             $shippingInclTax = $this->priceCurrency->round($orderShippingInclTax * $ratio);
             $baseShippingInclTax = $this->priceCurrency->round($orderBaseShippingInclTax * $ratio);
         } else {
             $baseAllowedAmount = $order->getBaseCurrency()->format($baseAllowedAmount, null, false);
             throw new \Magento\Framework\Exception\LocalizedException(__('Maximum shipping amount allowed to refund is: %1', $baseAllowedAmount));
         }
     } else {
         $shippingAmount = $allowedAmount;
         $baseShippingAmount = $baseAllowedAmount;
         $allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
         $baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
         $shippingInclTax = $this->priceCurrency->round($allowedAmount + $allowedTaxAmount);
         $baseShippingInclTax = $this->priceCurrency->round($baseAllowedAmount + $baseAllowedTaxAmount);
     }
     $creditmemo->setShippingAmount($shippingAmount);
     $creditmemo->setBaseShippingAmount($baseShippingAmount);
     $creditmemo->setShippingInclTax($shippingInclTax);
     $creditmemo->setBaseShippingInclTax($baseShippingInclTax);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $shippingAmount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseShippingAmount);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:64,代码来源:Shipping.php

示例2: _initCreditmemoData

 /**
  * Initialize creditmemo state based on requested parameters
  *
  * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
  * @param array $data
  * @return void
  */
 protected function _initCreditmemoData($creditmemo, $data)
 {
     if (isset($data['shipping_amount'])) {
         $creditmemo->setBaseShippingAmount((double) $data['shipping_amount']);
     }
     if (isset($data['adjustment_positive'])) {
         $creditmemo->setAdjustmentPositive($data['adjustment_positive']);
     }
     if (isset($data['adjustment_negative'])) {
         $creditmemo->setAdjustmentNegative($data['adjustment_negative']);
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Order.php

示例3: collect

 /**
  * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     // amounts without tax
     $orderShippingAmount = $order->getShippingAmount();
     $orderBaseShippingAmount = $order->getBaseShippingAmount();
     $allowedAmount = $orderShippingAmount - $order->getShippingRefunded();
     $baseAllowedAmount = $orderBaseShippingAmount - $order->getBaseShippingRefunded();
     // amounts including tax
     $orderShippingInclTax = $order->getShippingInclTax();
     $orderBaseShippingInclTax = $order->getBaseShippingInclTax();
     $allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
     $baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
     $allowedAmountInclTax = $allowedAmount + $allowedTaxAmount;
     $baseAllowedAmountInclTax = $baseAllowedAmount + $baseAllowedTaxAmount;
     // for the credit memo
     $shippingAmount = $baseShippingAmount = $shippingInclTax = $baseShippingInclTax = 0;
     // Check if the desired shipping amount to refund was specified (from invoice or another source).
     if ($creditmemo->hasBaseShippingAmount()) {
         // For the conditional logic, we will either use amounts that always include tax -OR- never include tax.
         // The logic uses the 'base' currency to be consistent with what the user (admin) provided as input.
         $useAmountsWithTax = $this->isSuppliedShippingAmountInclTax($order);
         // Since the user (admin) supplied 'desiredAmount' it already has tax -OR- does not include tax
         $desiredAmount = $this->priceCurrency->round($creditmemo->getBaseShippingAmount());
         $maxAllowedAmount = $useAmountsWithTax ? $baseAllowedAmountInclTax : $baseAllowedAmount;
         $originalTotalAmount = $useAmountsWithTax ? $orderBaseShippingInclTax : $orderBaseShippingAmount;
         // Note: ($x < $y + 0.0001) means ($x <= $y) for floats
         if ($desiredAmount < $this->priceCurrency->round($maxAllowedAmount) + 0.0001) {
             // since the admin is returning less than the allowed amount, compute the ratio being returned
             $ratio = 0;
             if ($originalTotalAmount > 0) {
                 $ratio = $desiredAmount / $originalTotalAmount;
             }
             // capture amounts without tax
             // Note: ($x > $y - 0.0001) means ($x >= $y) for floats
             if ($desiredAmount > $maxAllowedAmount - 0.0001) {
                 $shippingAmount = $allowedAmount;
                 $baseShippingAmount = $baseAllowedAmount;
             } else {
                 $shippingAmount = $this->priceCurrency->round($orderShippingAmount * $ratio);
                 $baseShippingAmount = $this->priceCurrency->round($orderBaseShippingAmount * $ratio);
             }
             $shippingInclTax = $this->priceCurrency->round($orderShippingInclTax * $ratio);
             $baseShippingInclTax = $this->priceCurrency->round($orderBaseShippingInclTax * $ratio);
         } else {
             $maxAllowedAmount = $order->getBaseCurrency()->format($maxAllowedAmount, null, false);
             throw new \Magento\Framework\Exception\LocalizedException(__('Maximum shipping amount allowed to refund is: %1', $maxAllowedAmount));
         }
     } else {
         $shippingAmount = $allowedAmount;
         $baseShippingAmount = $baseAllowedAmount;
         $shippingInclTax = $this->priceCurrency->round($allowedAmountInclTax);
         $baseShippingInclTax = $this->priceCurrency->round($baseAllowedAmountInclTax);
     }
     $creditmemo->setShippingAmount($shippingAmount);
     $creditmemo->setBaseShippingAmount($baseShippingAmount);
     $creditmemo->setShippingInclTax($shippingInclTax);
     $creditmemo->setBaseShippingInclTax($baseShippingInclTax);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $shippingAmount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseShippingAmount);
     return $this;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:67,代码来源:Shipping.php


注:本文中的Magento\Sales\Model\Order\Creditmemo::setBaseShippingAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。