Post by saintlade » Fri Apr 13, 2012 6:23 pm

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

New member

Posts

Joined
Wed Oct 12, 2011 9:12 am

Post by bfer » Tue Apr 24, 2012 7:03 pm

Having the same issue

Newbie

Posts

Joined
Tue Dec 13, 2011 4:46 pm

Post by saintlade » Tue Apr 24, 2012 9:26 pm

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.

New member

Posts

Joined
Wed Oct 12, 2011 9:12 am

Post by opcrat » Fri May 04, 2012 10:07 am

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.

Most Useful Extensions || Most Selling Extensions
Opencart Development || Opencart Designing || eCommerce Project

✔ Join more than 5000 Happy Opencart Store Owners enjoying the extensions designed and developed by Opcrat, Opencart Partner.


User avatar
Active Member

Posts

Joined
Wed Dec 21, 2011 6:54 am

Post by saintlade » Fri May 04, 2012 3:16 pm

Thanks for the tip, shall have a look but sounds a bit above my abilities.

New member

Posts

Joined
Wed Oct 12, 2011 9:12 am

Post by spennyw » Wed Jun 20, 2012 5:07 pm

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

Newbie

Posts

Joined
Tue Jun 19, 2012 10:38 pm

Post by saintlade » Fri Jun 22, 2012 8:01 am

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 : )

New member

Posts

Joined
Wed Oct 12, 2011 9:12 am

Post by wingsnut25 » Wed Nov 14, 2012 12:20 pm

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.

Newbie

Posts

Joined
Thu Oct 11, 2012 4:03 am

Post by alfa69 » Thu Feb 21, 2013 4:37 am

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;
        } 

Newbie

Posts

Joined
Sun Dec 30, 2012 12:47 am

Post by DrDice » Mon Jul 07, 2014 12:33 pm

Any way to get this working with coupons instead of vouchers?

Newbie

Posts

Joined
Mon Jul 07, 2014 5:59 am

Post by Lisaclarke » Tue Apr 19, 2016 8:38 pm

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.

Newbie

Posts

Joined
Tue Apr 19, 2016 8:34 pm
Who is online

Users browsing this forum: No registered users and 25 guests