本文整理汇总了PHP中Magento\Sales\Model\Order\Creditmemo::getBaseShippingAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Creditmemo::getBaseShippingAmount方法的具体用法?PHP Creditmemo::getBaseShippingAmount怎么用?PHP Creditmemo::getBaseShippingAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order\Creditmemo
的用法示例。
在下文中一共展示了Creditmemo::getBaseShippingAmount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareOrder
/**
* Prepare order data for refund
*
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return void
*/
protected function prepareOrder(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
{
$order = $creditmemo->getOrder();
$baseOrderRefund = $this->priceCurrency->round($order->getBaseTotalRefunded() + $creditmemo->getBaseGrandTotal());
$orderRefund = $this->priceCurrency->round($order->getTotalRefunded() + $creditmemo->getGrandTotal());
$order->setBaseTotalRefunded($baseOrderRefund);
$order->setTotalRefunded($orderRefund);
$order->setBaseSubtotalRefunded($order->getBaseSubtotalRefunded() + $creditmemo->getBaseSubtotal());
$order->setSubtotalRefunded($order->getSubtotalRefunded() + $creditmemo->getSubtotal());
$order->setBaseTaxRefunded($order->getBaseTaxRefunded() + $creditmemo->getBaseTaxAmount());
$order->setTaxRefunded($order->getTaxRefunded() + $creditmemo->getTaxAmount());
$order->setBaseDiscountTaxCompensationRefunded($order->getBaseDiscountTaxCompensationRefunded() + $creditmemo->getBaseDiscountTaxCompensationAmount());
$order->setDiscountTaxCompensationRefunded($order->getDiscountTaxCompensationRefunded() + $creditmemo->getDiscountTaxCompensationAmount());
$order->setBaseShippingRefunded($order->getBaseShippingRefunded() + $creditmemo->getBaseShippingAmount());
$order->setShippingRefunded($order->getShippingRefunded() + $creditmemo->getShippingAmount());
$order->setBaseShippingTaxRefunded($order->getBaseShippingTaxRefunded() + $creditmemo->getBaseShippingTaxAmount());
$order->setShippingTaxRefunded($order->getShippingTaxRefunded() + $creditmemo->getShippingTaxAmount());
$order->setAdjustmentPositive($order->getAdjustmentPositive() + $creditmemo->getAdjustmentPositive());
$order->setBaseAdjustmentPositive($order->getBaseAdjustmentPositive() + $creditmemo->getBaseAdjustmentPositive());
$order->setAdjustmentNegative($order->getAdjustmentNegative() + $creditmemo->getAdjustmentNegative());
$order->setBaseAdjustmentNegative($order->getBaseAdjustmentNegative() + $creditmemo->getBaseAdjustmentNegative());
$order->setDiscountRefunded($order->getDiscountRefunded() + $creditmemo->getDiscountAmount());
$order->setBaseDiscountRefunded($order->getBaseDiscountRefunded() + $creditmemo->getBaseDiscountAmount());
if ($creditmemo->getDoTransaction()) {
$order->setTotalOnlineRefunded($order->getTotalOnlineRefunded() + $creditmemo->getGrandTotal());
$order->setBaseTotalOnlineRefunded($order->getBaseTotalOnlineRefunded() + $creditmemo->getBaseGrandTotal());
} else {
$order->setTotalOfflineRefunded($order->getTotalOfflineRefunded() + $creditmemo->getGrandTotal());
$order->setBaseTotalOfflineRefunded($order->getBaseTotalOfflineRefunded() + $creditmemo->getBaseGrandTotal());
}
$order->setBaseTotalInvoicedCost($order->getBaseTotalInvoicedCost() - $creditmemo->getBaseCost());
}
示例2: 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;
}
示例3: collect
/**
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return $this
*/
public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
{
$creditmemo->setDiscountAmount(0);
$creditmemo->setBaseDiscountAmount(0);
$order = $creditmemo->getOrder();
$totalDiscountAmount = 0;
$baseTotalDiscountAmount = 0;
/**
* Calculate how much shipping discount should be applied
* basing on how much shipping should be refunded.
*/
$baseShippingAmount = $creditmemo->getBaseShippingAmount();
if ($baseShippingAmount) {
$baseShippingDiscount = $baseShippingAmount * $order->getBaseShippingDiscountAmount() / $order->getBaseShippingAmount();
$shippingDiscount = $order->getShippingAmount() * $baseShippingDiscount / $order->getBaseShippingAmount();
$totalDiscountAmount = $totalDiscountAmount + $shippingDiscount;
$baseTotalDiscountAmount = $baseTotalDiscountAmount + $baseShippingDiscount;
}
/** @var $item \Magento\Sales\Model\Order\Invoice\Item */
foreach ($creditmemo->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}
$orderItemDiscount = (double) $orderItem->getDiscountInvoiced();
$baseOrderItemDiscount = (double) $orderItem->getBaseDiscountInvoiced();
$orderItemQty = $orderItem->getQtyInvoiced();
if ($orderItemDiscount && $orderItemQty) {
$discount = $orderItemDiscount - $orderItem->getDiscountRefunded();
$baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountRefunded();
if (!$item->isLast()) {
$availableQty = $orderItemQty - $orderItem->getQtyRefunded();
$discount = $creditmemo->roundPrice($discount / $availableQty * $item->getQty(), 'regular', true);
$baseDiscount = $creditmemo->roundPrice($baseDiscount / $availableQty * $item->getQty(), 'base', true);
}
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
$totalDiscountAmount += $discount;
$baseTotalDiscountAmount += $baseDiscount;
}
}
$creditmemo->setDiscountAmount(-$totalDiscountAmount);
$creditmemo->setBaseDiscountAmount(-$baseTotalDiscountAmount);
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $totalDiscountAmount);
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseTotalDiscountAmount);
return $this;
}
示例4: cancelCreditmemo
/**
* Cancel a creditmemo: substract its totals from the payment
*
* @param Creditmemo $creditmemo
* @return $this
*/
public function cancelCreditmemo($creditmemo)
{
$this->_updateTotals(['amount_refunded' => -1 * $creditmemo->getGrandTotal(), 'base_amount_refunded' => -1 * $creditmemo->getBaseGrandTotal(), 'shipping_refunded' => -1 * $creditmemo->getShippingAmount(), 'base_shipping_refunded' => -1 * $creditmemo->getBaseShippingAmount()]);
$this->_eventManager->dispatch('sales_order_payment_cancel_creditmemo', ['payment' => $this, 'creditmemo' => $creditmemo]);
return $this;
}
示例5: collect
/**
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return $this
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
{
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$totalTax = 0;
$baseTotalTax = 0;
$totalDiscountTaxCompensation = 0;
$baseTotalDiscountTaxCompensation = 0;
$order = $creditmemo->getOrder();
/** @var $item \Magento\Sales\Model\Order\Creditmemo\Item */
foreach ($creditmemo->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy() || $item->getQty() <= 0) {
continue;
}
$orderItemTax = (double) $orderItem->getTaxInvoiced();
$baseOrderItemTax = (double) $orderItem->getBaseTaxInvoiced();
$orderItemQty = (double) $orderItem->getQtyInvoiced();
if ($orderItemTax && $orderItemQty) {
/**
* Check item tax amount
*/
$tax = $orderItemTax - $orderItem->getTaxRefunded();
$baseTax = $baseOrderItemTax - $orderItem->getBaseTaxRefunded();
$discountTaxCompensation = $orderItem->getDiscountTaxCompensationInvoiced() - $orderItem->getDiscountTaxCompensationRefunded();
$baseDiscountTaxCompensation = $orderItem->getBaseDiscountTaxCompensationInvoiced() - $orderItem->getBaseDiscountTaxCompensationRefunded();
if (!$item->isLast()) {
$availableQty = $orderItemQty - $orderItem->getQtyRefunded();
$tax = $creditmemo->roundPrice($tax / $availableQty * $item->getQty());
$baseTax = $creditmemo->roundPrice($baseTax / $availableQty * $item->getQty(), 'base');
$discountTaxCompensation = $creditmemo->roundPrice($discountTaxCompensation / $availableQty * $item->getQty());
$baseDiscountTaxCompensation = $creditmemo->roundPrice($baseDiscountTaxCompensation / $availableQty * $item->getQty(), 'base');
}
$item->setTaxAmount($tax);
$item->setBaseTaxAmount($baseTax);
$item->setDiscountTaxCompensationAmount($discountTaxCompensation);
$item->setBaseDiscountTaxCompensationAmount($baseDiscountTaxCompensation);
$totalTax += $tax;
$baseTotalTax += $baseTax;
$totalDiscountTaxCompensation += $discountTaxCompensation;
$baseTotalDiscountTaxCompensation += $baseDiscountTaxCompensation;
}
}
$isPartialShippingRefunded = false;
if ($invoice = $creditmemo->getInvoice()) {
//recalculate tax amounts in case if refund shipping value was changed
if ($order->getBaseShippingAmount() && $creditmemo->getBaseShippingAmount()) {
$taxFactor = $creditmemo->getBaseShippingAmount() / $order->getBaseShippingAmount();
$shippingTaxAmount = $invoice->getShippingTaxAmount() * $taxFactor;
$baseShippingTaxAmount = $invoice->getBaseShippingTaxAmount() * $taxFactor;
$totalDiscountTaxCompensation += $invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
$baseTotalDiscountTaxCompensation += $invoice->getBaseShippingDiscountTaxCompensationAmnt() * $taxFactor;
$shippingDiscountTaxCompensationAmount = $invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
$baseShippingDiscountTaxCompensationAmount = $invoice->getBaseShippingDiscountTaxCompensationAmnt() * $taxFactor;
$shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
$totalDiscountTaxCompensation = $creditmemo->roundPrice($totalDiscountTaxCompensation);
$baseTotalDiscountTaxCompensation = $creditmemo->roundPrice($baseTotalDiscountTaxCompensation, 'base');
$shippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($shippingDiscountTaxCompensationAmount);
$baseShippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($baseShippingDiscountTaxCompensationAmount, 'base');
if ($taxFactor < 1 && $invoice->getShippingTaxAmount() > 0) {
$isPartialShippingRefunded = true;
}
$totalTax += $shippingTaxAmount;
$baseTotalTax += $baseShippingTaxAmount;
}
} else {
$orderShippingAmount = $order->getShippingAmount();
$baseOrderShippingAmount = $order->getBaseShippingAmount();
$baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$shippingDiscountTaxCompensationAmount = 0;
$baseShippingDiscountTaxCompensationAmount = 0;
$shippingDelta = $baseOrderShippingAmount - $baseOrderShippingRefundedAmount;
if ($shippingDelta > $creditmemo->getBaseShippingAmount()) {
$part = $creditmemo->getShippingAmount() / $orderShippingAmount;
$basePart = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
$shippingTaxAmount = $order->getShippingTaxAmount() * $part;
$baseShippingTaxAmount = $order->getBaseShippingTaxAmount() * $basePart;
$shippingDiscountTaxCompensationAmount = $order->getShippingDiscountTaxCompensationAmount() * $part;
$baseShippingDiscountTaxCompensationAmount = $order->getBaseShippingDiscountTaxCompensationAmnt() * $basePart;
$shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
$shippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($shippingDiscountTaxCompensationAmount);
$baseShippingDiscountTaxCompensationAmount = $creditmemo->roundPrice($baseShippingDiscountTaxCompensationAmount, 'base');
if ($part < 1 && $order->getShippingTaxAmount() > 0) {
$isPartialShippingRefunded = true;
}
} elseif ($shippingDelta == $creditmemo->getBaseShippingAmount()) {
$shippingTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
$baseShippingTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
//.........这里部分代码省略.........
示例6: 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;
}