1.5 (30.77%) 13 votes

Here are the steps that you will follow in this How to add a custom discount in Magento 2 (Magento 2.3)? – Magento 2 Custom Discount:

  1. Register a total in the file sale.xml
  2. Add discount to change the grandtotal in the model
  3. Add the total in the layout file
  4. View model knockout

Add a Custom Discount in Magento 2 (Magento 2.3)

  • First, we will register a total in the file sale.xml
    app/code/Magestore/Webpos/etc/sales.xml:

  • And then, we will add discount to change the grandtotal in the model app/code/Magestore/Webpos/Model/Total/Quote/Custom.php:

  • Now, you will see the Grand Total was changed. But there is no total discount information. Because the magento use knockout js to show the total. We need to add the total in the layout file app/code/Magestore/Webpos/view/frontend/layout/checkout_cart_index.xml:

  • It will call view model knockout app/code/Magestore/Webpos/view/frontend/web/js/view/checkout/summary/customdiscount.js

  • And the total discount will be show in the template knockout app/code/Magestore/Webpos/view/frontend/web/template/checkout/summary/customdiscount.html:

  • You will see it like my screenshot:

7135f9c81dc2420c9a1c693677f2e356

Thank you very much !

You may want to try the Magento 2 Demo to fully experience its new awesome features. And of course, please feel free to find more Magento 2 Tutorials by our Experts.

Your Magento website needs a powerful Magento ERP for stock control.

DON'T MISS THE CHANCE!

magento erp

How to Setup Cron Job in Magento 2? (Magento 2.3)
How to Create Simple Grid Listing in Magento 2 Admin with UI Component - Magento 2.3

Leave a Reply

Your email address will not be published. Required fields are marked *