Skip to content

Commit 4cf4884

Browse files
committed
Resolves issue 6731 by adding a custom message for refunding shipping
1 parent eb27ac2 commit 4cf4884

File tree

1 file changed

+11
-0
lines changed
  • app/code/Magento/Sales/Model/Order/Creditmemo/Total

1 file changed

+11
-0
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Total/Discount.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Discount extends AbstractTotal
1010
/**
1111
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
1212
* @return $this
13+
* @throws \Magento\Framework\Exception\LocalizedException
1314
*/
1415
public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
1516
{
@@ -26,6 +27,16 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
2627
* basing on how much shipping should be refunded.
2728
*/
2829
$baseShippingAmount = $this->getBaseShippingAmount($creditmemo);
30+
31+
/**
32+
* If credit memo's shipping amount is set and Order's shipping amount is 0,
33+
* throw exception with differente message
34+
*/
35+
if ( $baseShippingAmount && $order->getBaseShippingAmount() <= 0 ) {
36+
throw new \Magento\Framework\Exception\LocalizedException(
37+
new \Magento\Framework\Phrase("You can not refund shipping if there is no shipping amount.",[])
38+
);
39+
}
2940
if ($baseShippingAmount) {
3041
$baseShippingDiscount = $baseShippingAmount *
3142
$order->getBaseShippingDiscountAmount() /

0 commit comments

Comments
 (0)