From 5980ef0467e129b5fd199cec4f0685c47f5c57e4 Mon Sep 17 00:00:00 2001 From: magentoabu Date: Wed, 9 Apr 2025 20:45:08 +0530 Subject: [PATCH 1/2] coupon code added 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 dc507f93887f5..4c9356c52d49f 100644 --- a/app/code/Magento/Sales/Block/Order/Totals.php +++ b/app/code/Magento/Sales/Block/Order/Totals.php @@ -7,6 +7,7 @@ use Magento\Framework\DataObject; use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Invoice; /** * Order totals. @@ -127,8 +128,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'); } @@ -136,7 +142,7 @@ protected function _initTotals() [ 'code' => 'discount', 'field' => 'discount_amount', - 'value' => $source->getDiscountAmount(), + 'value' => $discountSource->getDiscountAmount(), 'label' => $discountLabel, ] ); From 89261c16668114c84e894f626b00704effde01af Mon Sep 17 00:00:00 2001 From: magentoabu Date: Thu, 10 Apr 2025 11:34:52 +0530 Subject: [PATCH 2/2] static test fixed --- app/code/Magento/Sales/Block/Order/Totals.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Block/Order/Totals.php b/app/code/Magento/Sales/Block/Order/Totals.php index 4c9356c52d49f..17e067a878043 100644 --- a/app/code/Magento/Sales/Block/Order/Totals.php +++ b/app/code/Magento/Sales/Block/Order/Totals.php @@ -1,7 +1,7 @@