Quick Tip: Accept Multiple Vouchers in OpenCart 2.0

Quick Tip: Accept Multiple Vouchers in OpenCart 2.0

OpenCart is
an open-source, PHP-based online e-commerce
solution that allows you to accept orders online. It allows customers to shop using vouchers, but only one at a time by default. If you want to allow your customers to use multiple vouchers at once, you'll need to modify the code. I'll show you exactly how to do that in this tutorial.

How Do We Create a Gift Voucher?

Only admins and permitted back-end users are able to generate gift vouchers. OpenCart comes with a default module for doing it. The following screenshot shows the place where a back-end user can generate vouchers.

Dashboard

What Is the Problem?

If we have a voucher system implemented in OpenCart by default, what is the problem? Let's understand it with the help of an example:

Recently a
friend of mine wanted to buy a couple of items through OpenCart that cost $800, but she only had $500, and two gift vouchers worth $250 each. So she called me and asked for a solution. Because OpenCart only allows you to use a single voucher to shop at any one time, she couldn’t
buy the items.

A Solution

To resolve this problem, we need to add an option to use multiple vouchers so that customers can shop easily, without facing any difficulty.  Here is the solution, in which we will modify a few lines of code and it will help to solve this problem. 

This tutorial is divided into three main steps, which are:

  1. Change in Controller
  2. Change in Model
  3. Change in View

1. Controller File

  1. Navigate to catalog/controller/checkout/cart.php.
  2. Find the following code: 

Change the above code to:

2. Model File

  1. Navigate to catalog/model/total/voucher.php.
  2. Find the following lines of code:

We need to run an outer loop to fetch all of our vouchers that we maintained as array in Step 1. So we will place an outer loop after $this->load->model('checkout/voucher');.

So we will be looping our Session Vouchers Array to fetch all the vouchers we applied, and the code will be as shown below. Note that the following code is commented in order to make it easier to understand.

3. View File

  1. Navigate to catalog/view/theme/default/template/checkout/voucher.tpl.
  2. Find the following line of code:

Replace it with this:

We are done with our problem! In fact, we just made some simple code hacks to solve that big problem, so we didn't have to develop a new module or extension. We just modified some lines of codes to get it done.

Conclusion

In
this article we provided a successful solution for adding multiple vouchers in
our e-shop. Since OpenCart doesn’t allow shoppers to use multiple vouchers by default, we modified the code so that now they can use as
many vouchers as they want. That will help customers to shop easily
without any problem. 

In our next articles we will be implementing some real-world business tools in our OpenCart system, so stay subscribed and contribute your
valuable comments. Thanks!

Source: Tuts Plus

About the Author

Comments

  1. … [Trackback]

    […] Informations on that Topic: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  2. … [Trackback]

    […] Informations on that Topic: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  3. … [Trackback]

    […] Read More: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  4. … [Trackback]

    […] There you will find 84319 more Infos: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  5. … [Trackback]

    […] There you will find 92947 more Infos: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  6. … [Trackback]

    […] There you will find 38089 more Infos: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  7. … [Trackback]

    […] Informations on that Topic: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  8. … [Trackback]

    […] Find More Informations here: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  9. … [Trackback]

    […] Find More Informations here: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  10. porno says:

    … [Trackback]

    […] Read More here: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  11. … [Trackback]

    […] Read More here: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  12. available says:

    … [Trackback]

    […] Informations on that Topic: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  13. … [Trackback]

    […] There you will find 28674 more Infos: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  14. penis says:

    … [Trackback]

    […] Informations on that Topic: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  15. top steroids says:

    … [Trackback]

    […] There you will find 70064 more Infos: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  16. … [Trackback]

    […] Read More: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  17. … [Trackback]

    […] Informations on that Topic: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  18. eshopex says:

    … [Trackback]

    […] Find More Informations here: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  19. … [Trackback]

    […] Read More here: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]

  20. … [Trackback]

    […] Informations on that Topic: designncode.in/quick-tip-accept-multiple-vouchers-in-opencart-2-0/ […]