/** * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo * @return $this */ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo) { $grandTotal = $creditmemo->getGrandTotal(); $baseGrandTotal = $creditmemo->getBaseGrandTotal(); $grandTotal += $creditmemo->getAdjustmentPositive(); $baseGrandTotal += $creditmemo->getBaseAdjustmentPositive(); $grandTotal -= $creditmemo->getAdjustmentNegative(); $baseGrandTotal -= $creditmemo->getBaseAdjustmentNegative(); $creditmemo->setGrandTotal($grandTotal); $creditmemo->setBaseGrandTotal($baseGrandTotal); $creditmemo->setAdjustment($creditmemo->getAdjustmentPositive() - $creditmemo->getAdjustmentNegative()); $creditmemo->setBaseAdjustment($creditmemo->getBaseAdjustmentPositive() - $creditmemo->getBaseAdjustmentNegative()); return $this; }
/** * 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()); }