From d84562bedb5a5de6cb91d886836af78541a04c48 Mon Sep 17 00:00:00 2001 From: silinmykola Date: Tue, 20 Apr 2021 21:00:33 +0300 Subject: [PATCH] 23832 add coupon code to totals model --- app/code/Magento/Sales/Block/Order/Totals.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Block/Order/Totals.php b/app/code/Magento/Sales/Block/Order/Totals.php index 80ce5e2e689c6..65579f3c9cc52 100644 --- a/app/code/Magento/Sales/Block/Order/Totals.php +++ b/app/code/Magento/Sales/Block/Order/Totals.php @@ -6,6 +6,7 @@ namespace Magento\Sales\Block\Order; use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Invoice; /** * Order totals. @@ -126,8 +127,13 @@ protected function _initTotals() * Add discount */ if ((double)$this->getSource()->getDiscountAmount() != 0) { - if ($this->getSource()->getDiscountDescription()) { - $discountLabel = __('Discount (%1)', $source->getDiscountDescription()); + if ($this->getSource() instanceof Invoice) { + $discountSource = $this->getSource()->getOrder(); + } else { + $discountSource = $this->getSource(); + } + if ($this->getSource()->getCouponCode()) { + $discountLabel = __('Discount (%1)', $discountSource->getCouponCode()); } else { $discountLabel = __('Discount'); } @@ -135,7 +141,7 @@ protected function _initTotals() [ 'code' => 'discount', 'field' => 'discount_amount', - 'value' => $source->getDiscountAmount(), + 'value' => $discountSource->getDiscountAmount(), 'label' => $discountLabel, ] );