Skip to content
11 changes: 11 additions & 0 deletions app/code/Magento/Sales/Model/Order/Creditmemo/Total/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Discount extends AbstractTotal
/**
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
{
Expand All @@ -26,6 +27,16 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
* basing on how much shipping should be refunded.
*/
$baseShippingAmount = $this->getBaseShippingAmount($creditmemo);

/**
* If credit memo's shipping amount is set and Order's shipping amount is 0,
* throw exception with differente message
Comment thread
Rus0 marked this conversation as resolved.
Outdated
*/
if ( $baseShippingAmount && $order->getBaseShippingAmount() <= 0 ) {
Comment thread
Rus0 marked this conversation as resolved.
Outdated
throw new \Magento\Framework\Exception\LocalizedException(
Comment thread
Rus0 marked this conversation as resolved.
new \Magento\Framework\Phrase("You can not refund shipping if there is no shipping amount.",[])
Comment thread
Rus0 marked this conversation as resolved.
Outdated
);
}
if ($baseShippingAmount) {
$baseShippingDiscount = $baseShippingAmount *
$order->getBaseShippingDiscountAmount() /
Expand Down