Page 1 of 2

[1.5.x] Coupon History not working with Paypal, etc - FIXED!

Posted: Mon May 21, 2012 11:51 pm
by jolyonr
Ok, seeing as I've heard nothing from the developers on this, I decided to try and figure out what is going wrong.

The symptoms are: Coupons work fine with a direct payment method (such as COD), but do NOT get recorded in coupon_history with PayPal, and other payment methods, such as 3rd party Realex.

The problem is that the system for coupons has a pretty major design flaw.

the function getCoupon($code) is called to get the coupon and validate it.

It relies on being able to identify the customer related to the order by using $this->customer->getId(); This gets the user ID based on the currently logged-in user.

Unfortunately, any script that uses a callback function to validate an order through a payment gateway (eg PayPal, realex, etc) will not be logged in as the user as it is called by the payment gateway rather than by the customer. So, no customer id, and every coupon will be regarded as invalid.

So the coupon works as far as providing the discount, but fails at the point when it needs to be recorded in the database.

Solutions? I'll look at that next. At the callback stage we could simply get the coupon without worrying about whether it's valid or not. We've already applied the discount, all we need to do is log it.

So a second parameter to getCoupon() of $donotverify would be a reasonable solutuion. Will work on that next.

Jolyon

Re: Coupon History not working with Paypal, etc - design fla

Posted: Tue May 22, 2012 12:04 am
by jolyonr
Yes, that fixes it.

So to fix the coupon system, do this:

in catalog/model/checkout/coupon.php

chage

Code: Select all

public function getCoupon($code) {
to

Code: Select all

public function getCoupon($code,$noverify=0) {
AND change

Code: Select all

	if ($status) {
			return array(
to

Code: Select all

	if (($status)||($noverify)) {
			return array(

Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code);
to

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
This should fix logging of coupons (and the problems with coupons being used more times than they were set to be used for) with payment systems using callbacks.

Jolyon

Re: Coupon History not working with Paypal, etc - FIXED!

Posted: Thu Jun 07, 2012 7:49 pm
by artisanweb
Thankyou. Works perfectly. :)

Re: Coupon History not working with Paypal, etc - FIXED!

Posted: Wed Jul 18, 2012 8:38 pm
by innuoluke
And here is a handy VQMod for those that would like it :) All credit to jolyonr for working out how to fix the problem, I just made it into a VQMod as I have to update lots of client websites with the same changes!

This is only tested in v1.5.1.3, but I would imagine it will work with any version > 1.5 as it is such a small amend.

Please post a reply to let other people know if it successfully works in other versions of OpenCart.

Re: Coupon History not working with Paypal, etc - FIXED!

Posted: Thu Aug 23, 2012 12:05 am
by garydee77
surprised this hasn't been fixed in the latest version of the cart - using 1.5.4.1 and just noticed that my coupons set up to only be used ONCE - are able to be used multiple times.... not good eh?

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Thu Aug 23, 2012 7:07 pm
by i2Paq

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Mon Aug 27, 2012 9:03 am
by jmasril
After make all the changes that i read above, still nothing.
I use oc ver 1.5.1.3

thanks, and hope some one can help me with this issue

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Wed Aug 29, 2012 6:34 pm
by Fatbat
1.5.3.1 here.

So I've been given instructions to run a coupon usage report for the last three months for company management, and when I go to the coupon history, there isn't any despite the fact that many customers have been successfully using our coupons with their purchases.

No history at all...

This is terribly disappointing. Has this issue been fixed in 1.5.4.X or not?

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Sun Sep 02, 2012 6:03 pm
by i2Paq
Fatbat wrote:Has this issue been fixed in 1.5.4.X or not?
Just checked my 1.5.4.1 install and the old, not working, code is still there.

You have to change the code manually.

Re: Coupon History not working with Paypal, etc - design fla

Posted: Thu Oct 04, 2012 2:57 pm
by mygameauctions
jolyonr wrote:Yes, that fixes it.

So to fix the coupon system, do this:

in catalog/model/checkout/coupon.php

chage

Code: Select all

public function getCoupon($code) {
to

Code: Select all

public function getCoupon($code,$noverify=0) {
AND change

Code: Select all

	if ($status) {
			return array(
to

Code: Select all

	if (($status)||($noverify)) {
			return array(

Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code);
to

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
This should fix logging of coupons (and the problems with coupons being used more times than they were set to be used for) with payment systems using callbacks.

Jolyon


I am running 1.5.4 and this has fixed the issue with the coupon report. Thank you so much for posting this and resolving the issue.

Re: Coupon History not working with Paypal, etc - design fla

Posted: Thu Nov 22, 2012 12:22 am
by pltceat
jolyonr wrote:Yes, that fixes it.

So to fix the coupon system, do this:

in catalog/model/checkout/coupon.php

chage

Code: Select all

public function getCoupon($code) {
to

Code: Select all

public function getCoupon($code,$noverify=0) {
AND change

Code: Select all

	if ($status) {
			return array(
to

Code: Select all

	if (($status)||($noverify)) {
			return array(

Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code);
to

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
This should fix logging of coupons (and the problems with coupons being used more times than they were set to be used for) with payment systems using callbacks.

Jolyon

Hi,
I'm using 1.5.4. Have tried the changes you have listed and it's still not working. I can't figure what's wrong...can you help? Thank you.

Re: Coupon History not working with Paypal, etc - FIXED!

Posted: Thu Nov 22, 2012 12:26 am
by pltceat
innuoluke wrote:And here is a handy VQMod for those that would like it :) All credit to jolyonr for working out how to fix the problem, I just made it into a VQMod as I have to update lots of client websites with the same changes!

This is only tested in v1.5.1.3, but I would imagine it will work with any version > 1.5 as it is such a small amend.

Please post a reply to let other people know if it successfully works in other versions of OpenCart.

Hi, I'm using 1.5.4. This VQMod doesn't work for me....I've tried manually changing the code as well. Still don't have any Coupon History and still have unlimited uses for coupon even though I've set the usage to 1 for each specific customer. My payment options are only COD and bank transfer. I can't figure out what I'm doing wrong. Can anyone help? Thank you.

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Thu Nov 22, 2012 7:01 pm
by Daniel
nice to hear you guys blame opencart. actually i have found that problems are caused by not translating the order copon language file properly. check under catalog/language/total/coupon and make sure there is (%) in the translation for the total title.

the system parses the (%) to get the coupon code to add to the history.

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Fri Nov 23, 2012 12:33 pm
by pltceat
Daniel wrote:nice to hear you guys blame opencart. actually i have found that problems are caused by not translating the order copon language file properly. check under catalog/language/total/coupon and make sure there is (%) in the translation for the total title.

the system parses the (%) to get the coupon code to add to the history.

Hi,
My language files have (%), and still doesn't have coupon history, nor does it limit coupon usage, even when set to one use per customer, one use per coupon.
Any help you can offer would be greatly appreciated. Thanks.

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Fri May 17, 2013 9:04 am
by Tcalp
For anyone who has run into this bug and needs to correct historical orders placed en-mass the following SQL will do the trick. Be advised ,this is a VERY SLOW query, run at off-peak times and may require root database/system access if you are on shared hosting with a large database.

Designed for 1-off coupons, adjust appropriately if using table prefixes.

Code: Select all

INSERT INTO coupon_history (coupon_id, order_id, customer_id, amount, date_added)
SELECT coupon.coupon_id, order.order_id, order.customer_id, ABS(order_total.value), order.date_added
FROM `order`, `order_total`, `coupon` 
WHERE order.order_id = order_total.order_id 
AND coupon.code = REPLACE(REPLACE(title,'Coupon(',''),')','')
AND order.order_status_id >0 
AND title LIKE  'Coupon(%' AND REPLACE(REPLACE(title,'Coupon(',''),')','') NOT  IN 
(SELECT code FROM coupon, coupon_history WHERE coupon.coupon_id = coupon_history.coupon_id AND uses_total =1 AND uses_customer =1)

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Tue Feb 11, 2014 3:49 am
by solaris955
I am having this problem right now. I use version 1.5.6.

Coupon codes work generally fine - PayPal and Amazon Payments both process them, register appropriate deductions and reduce the order total.

The problem starts appearing when I am trying to integrate my affiliate software - iDev Affiliate - with my OpenCart installation.

I want to use a coupon commissioning functionality with iDev. This software needs to retrieve coupon code history from OpenCart database, and OpenCart fails to record such history.

Has anyone managed to sort this issue out?

I am not sure how to move forward with this.

I will appreciate any help here.

Thanks very much in advance,
Irina

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Tue Feb 11, 2014 3:55 am
by solaris955
By the way, here is the content of my coupon.php file:

<?php
// Text
$_['text_coupon'] = 'Coupon(%s)';
?>

So, it does have % in it.

Is that the correct code? - Thanks very much in advance.

Re: Coupon History not working with Paypal, etc - design fla

Posted: Tue May 13, 2014 10:37 am
by olfactorymaven
pltceat wrote:
jolyonr wrote:Yes, that fixes it.

So to fix the coupon system, do this:

in catalog/model/checkout/coupon.php

chage

Code: Select all

public function getCoupon($code) {
to

Code: Select all

public function getCoupon($code,$noverify=0) {
AND change

Code: Select all

	if ($status) {
			return array(
to

Code: Select all

	if (($status)||($noverify)) {
			return array(

Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code);
to

Code: Select all

$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
This should fix logging of coupons (and the problems with coupons being used more times than they were set to be used for) with payment systems using callbacks.

Jolyon

Hi,
I'm using 1.5.4. Have tried the changes you have listed and it's still not working. I can't figure what's wrong...can you help? Thank you.
I discovered this error after a few customers were able to use a coupon code more than once. Came across this solution today. Happy that I did. It works for 1.5.5.1

Many thanks.

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Sun Dec 21, 2014 3:44 am
by chaserich
Sorry to revive an old thread, but I tried this XML and it's still allowing coupons to be used multiple times. Here is an example:

Sub-Total: $33.99
Priority Mail Small Flat Rate: $5.95
Coupon (FF10OFF) Remove Coupon: $-3.06
Coupon (ff10OfF) Remove Coupon: $-3.40
Pennsylvania State Tax: $2.01
Total: $35.49

Can anyone recommend any other solutions? I'm using 1.5.6.4.

Thanks in advance!

-Chase

Re: [1.5.x] Coupon History not working with Paypal, etc - FI

Posted: Tue Jun 23, 2015 3:57 am
by IP_CAM