Page 1 of 1

Multiple Gift Voucher Redemption

Posted: Fri Apr 13, 2012 6:23 pm
by saintlade
Hi Guys,

had a look through the forums and can't find this, I would have thought someone else might have had the same issue?

Using 1.5.2 and as it stands customers can only redeem one gift voucher per order, has anybody come up with a mod so customers can redeem as many gift vouchers as they happen to have? Would have thought the ability to redeem multiple gift vouchers would be standard functionality, understand that you want to limit coupons to just one per order just not gift vouchers or is it just me? Can see some customers potentially getting annoyed by this and what to have it sorted before going live.

Many Thanks

Re: Multiple Gift Voucher Redemption

Posted: Tue Apr 24, 2012 7:03 pm
by bfer
Having the same issue

Re: Multiple Gift Voucher Redemption

Posted: Tue Apr 24, 2012 9:26 pm
by saintlade
Not figured this one out yet, got a few more things to be looking at but shall let you know here if I figure anything out.

Re: Multiple Gift Voucher Redemption

Posted: Fri May 04, 2012 10:07 am
by opcrat
By default Opencart is using a single session variable voucher for calculating voucher so it will overwrite if you try to add more than one. The best way to customize this is by converting that variable into array and store each entered eligible voucher code into that array and instead of calculating single voucher code into shopping cart (catalog/module/total/vourcher.php) calculate all entered voucher codes discount.

Re: Multiple Gift Voucher Redemption

Posted: Fri May 04, 2012 3:16 pm
by saintlade
Thanks for the tip, shall have a look but sounds a bit above my abilities.

Re: Multiple Gift Voucher Redemption

Posted: Wed Jun 20, 2012 5:07 pm
by spennyw
Hi,

It's reasonably simple.

Modify catalog/controller/checkout/cart.php

Find this code:

Code: Select all

if (isset($this->request->post['voucher']) && $this->validateVoucher()) { 
		$this->session->data['voucher'] = $this->request->post['voucher'];

Replace with:

Code: Select all

if (isset($this->request->post['voucher']) && $this->validateVoucher()) { 
		$this->session->data['voucher'][$this->request->post['voucher']] = $this->request->post['voucher'];
Then modify catalog/model/total/voucher.php

Find this code:

Code: Select all

$this->load->model('checkout/voucher');
			 
			$voucher_info = $this->model_checkout_voucher->getVoucher($this->session->data['voucher']);
			
			if ($voucher_info) {
				if ($voucher_info['amount'] > $total) {
					$amount = $total;	
				} else {
					$amount = $voucher_info['amount'];	
				}				
      			
				$total_data[] = array(
					'code'       => 'voucher',
        			'title'      => sprintf($this->language->get('text_voucher'), $this->session->data['voucher']),
	    			'text'       => $this->currency->format(-$amount),
        			'value'      => -$amount,
					'sort_order' => $this->config->get('voucher_sort_order')
      			);

				$total -= $amount;
And replace with

Code: Select all

      $this->load->model('checkout/voucher');
      foreach (array_unique($this->session->data['voucher']) as $voucher) {

        $voucher_info = $this->model_checkout_voucher->getVoucher($voucher);

        if ($voucher_info) {
          if ($voucher_info['amount'] > $total) {
            $amount = $total;	
          } else {
            $amount = $voucher_info['amount'];	
          }				

          $total_data[] = array(
            'code'       => 'voucher',
            'title'      => sprintf($this->language->get('text_voucher'), $voucher),
            'text'       => $this->currency->format(-$amount),
            'value'      => -$amount,
            'sort_order' => $this->config->get('voucher_sort_order')
          );

          $total -= $amount;
        } 
Note the extra closed bracket to ensure the foreach works properly


You'll also need to go into the template for the checkout.cart.tpl (depending on if you are using a custom one or the default) and remove the echo $voucher code from the input field i.e.

Code: Select all

 <input type="text" name="voucher" value="<?php echo $voucher; ?>" />
becomes

Code: Select all

<input type="text" name="voucher" value="<?php //echo $voucher; ?>" />
Kind regards, Spencer

Re: Multiple Gift Voucher Redemption

Posted: Fri Jun 22, 2012 8:01 am
by saintlade
Hey Spencer,

many thanks for looking at this and providing a fix, website building has stalled for the moment as I'm prepping for a big assessment, but looking forward to getting back to work on the website with one less thing to sort : )

Re: Multiple Gift Voucher Redemption

Posted: Wed Nov 14, 2012 12:20 pm
by wingsnut25
spennyw wrote:Hi,

It's reasonably simple.
Could the same process be applied to coupons instead of vouchers? The code looks very similar between them, but its also just enough off that I could not just replace the word Voucher with Coupon in all instances.

If you have the time to post the code to do it with coupons I would be grateful. If you are too busy, I would be willing to pay for your services.

Re: Multiple Gift Voucher Redemption

Posted: Thu Feb 21, 2013 4:37 am
by alfa69
spennyw wrote:...modify catalog/model/total/voucher.php

Code: Select all

      $this->load->model('checkout/voucher');
      foreach (array_unique($this->session->data['voucher']) as $voucher) {

        $voucher_info = $this->model_checkout_voucher->getVoucher($voucher);

        if ($voucher_info) {
          if ($voucher_info['amount'] > $total) {
            $amount = $total;	
          } else {
            $amount = $voucher_info['amount'];	
          }				

          $total_data[] = array(
            'code'       => 'voucher',
            'title'      => sprintf($this->language->get('text_voucher'), $voucher),
            'text'       => $this->currency->format(-$amount),
            'value'      => -$amount,
            'sort_order' => $this->config->get('voucher_sort_order')
          );

          $total -= $amount;
        } 
Kind regards, Spencer
Well, this not worked in my test Opencart 1.5.3 but I found working solution as well.

You need first set $voucher into array:

Code: Select all

      $this->load->model('checkout/voucher');

      $voucher = array();

      foreach (array_unique($this->session->data['voucher']) as $voucher) {

        $voucher_info = $this->model_checkout_voucher->getVoucher($voucher);

        if ($voucher_info) {
          if ($voucher_info['amount'] > $total) {
            $amount = $total;	
          } else {
            $amount = $voucher_info['amount'];	
          }				

          $total_data[] = array(
            'code'       => 'voucher',
            'title'      => sprintf($this->language->get('text_voucher'), $voucher),
            'text'       => $this->currency->format(-$amount),
            'value'      => -$amount,
            'sort_order' => $this->config->get('voucher_sort_order')
          );

          $total -= $amount;
        } 

Re: Multiple Gift Voucher Redemption

Posted: Mon Jul 07, 2014 12:33 pm
by DrDice
Any way to get this working with coupons instead of vouchers?

Re: Multiple Gift Voucher Redemption

Posted: Tue Apr 19, 2016 8:38 pm
by Lisaclarke
Hi I've been looking at extensions as I'm not familiar with coding. Can anyone suggest one that will allow the customer to enter 2 voucher codes in 1 order. Say 10% off one product group and 15% off another.