0

I want to coupon code showing when discount amount is 0.00

enter image description here

enter image description here

Note: when discount coupon code is 0 or more then rule working fine

0

Edit: I am sorry this is for the admin part. I red the question too fast and didn't realise it was for the frontend. But i will leave the answer here since i think the same logic could apply for the frontend and that you might also want it in the backend.

In vendor/magento/module-sales/Block/Adminhtml/Totals.php in the function _initTotals you have some code like this :

    if ((double)$this->getSource()->getDiscountAmount() != 0) {
        if ($this->getSource()->getDiscountDescription()) {
            $discountLabel = __('Discount (%1)', $this->getSource()->getDiscountDescription());
        } else {
            $discountLabel = __('Discount');
        }
        $this->_totals['discount'] = new \Magento\Framework\DataObject(
            [
                'code' => 'discount',
                'value' => $this->getSource()->getDiscountAmount(),
                'base_value' => $this->getSource()->getBaseDiscountAmount(),
                'label' => $discountLabel,
            ]
        );
    }

You have to change the condition for

if ((double)$this->getSource()->getDiscountAmount() != 0)

To

if ((double)$this->getSource()->getDiscountAmount() != null)

Now since you should not change this directly in the core you can create an override on the class \Magento\Sales\Block\Adminhtml\Order\Totals like that :

<?php
namespace Vendor\ModuleName\Block\Adminhtml\Order;

class Totals extends \Magento\Sales\Block\Adminhtml\Order\Totals
{

    protected function _initTotals()
    {
        parent::_initTotals();

        /**
         * Add discount
         */
        if ($this->getSource()->getDiscountAmount() !== null) {
            if ($this->getSource()->getDiscountDescription()) {
                $discountLabel = __('Discount (%1)', $this->getSource()->getDiscountDescription());
            } else {
                $discountLabel = __('Discount');
            }
            $this->_totals['discount'] = new \Magento\Framework\DataObject(
                [
                    'code' => 'discount',
                    'value' => $this->getSource()->getDiscountAmount(),
                    'base_value' => $this->getSource()->getBaseDiscountAmount(),
                    'label' => $discountLabel,
                ]
            );
        }


        return $this;
    }
}

Edit 2 : For the front end you will have to do the exact same thing but you will have to override the file vendor/magento/module-sales/Block/Order/Totals.php instead of vendor/magento/module-sales/Block/Adminhtml/Totals.php.

  • i want to in frontend checkout order summery and also admin order summery – Rakesh Donga Oct 17 at 20:17
  • I edited my answer, to override the frontend you have to do the same override but on a different file. – Carlo Ricci Oct 17 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.