[1.5.x] Coupon History not working with Paypal, etc - FIXED!
15 posts
• Page 1 of 1
[1.5.x] Coupon History not working with Paypal, etc - FIXED!
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
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
Last edited by i2Paq on Thu Aug 23, 2012 11:04 am, edited 2 times in total.
Reason: Title adjusted
Reason: Title adjusted
- jolyonr
- Posts: 4
- Joined: Tue May 15, 2012 10:50 am
Re: Coupon History not working with Paypal, etc - design fla
Yes, that fixes it.
So to fix the coupon system, do this:
in catalog/model/checkout/coupon.php
chage
to
AND change
to
Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change
to
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
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
- jolyonr
- Posts: 4
- Joined: Tue May 15, 2012 10:50 am
Re: Coupon History not working with Paypal, etc - FIXED!
Thankyou. Works perfectly. 

- artisanweb
- Posts: 2
- Joined: Thu Jun 07, 2012 11:42 am
Re: Coupon History not working with Paypal, etc - FIXED!
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.
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.
- Attachments
-
cws_coupon_codes_fix.xml- (1005 Bytes) Downloaded 166 times
Web developer for Cotswold Web Services / Innuo Ltd
Need help with your Opencart website? Give us a call to see how we can help.
Need help with your Opencart website? Give us a call to see how we can help.
- innuoluke
- Posts: 11
- Joined: Sat Jun 18, 2011 8:36 am
Re: Coupon History not working with Paypal, etc - FIXED!
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?
- garydee77
- Posts: 13
- Joined: Thu Jun 23, 2011 11:51 am
Re: [1.5.x] Coupon History not working with Paypal, etc - FI
Norman in 't Veldt
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
First Things First: Opencart Check List.
Documentation: Our Documentation section.
BUGs?: Known BUGS for All OC Versions.
Problemen met de BTW?: [How to] BTW + Verzend & betaalmethodes.
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
First Things First: Opencart Check List.
Documentation: Our Documentation section.
BUGs?: Known BUGS for All OC Versions.
Problemen met de BTW?: [How to] BTW + Verzend & betaalmethodes.
-

i2Paq - Global Moderator
- Posts: 9764
- Joined: Mon Nov 09, 2009 11:00 am
- Location: Winkel - The Netherlands
Re: [1.5.x] Coupon History not working with Paypal, etc - FI
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
I use oc ver 1.5.1.3
thanks, and hope some one can help me with this issue
- jmasril
- Posts: 16
- Joined: Sat Nov 12, 2011 4:59 pm
Re: [1.5.x] Coupon History not working with Paypal, etc - FI
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?
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?
-

Fatbat - Posts: 45
- Joined: Mon Feb 06, 2012 9:29 pm
Re: [1.5.x] Coupon History not working with Paypal, etc - FI
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.
Norman in 't Veldt
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
First Things First: Opencart Check List.
Documentation: Our Documentation section.
BUGs?: Known BUGS for All OC Versions.
Problemen met de BTW?: [How to] BTW + Verzend & betaalmethodes.
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
First Things First: Opencart Check List.
Documentation: Our Documentation section.
BUGs?: Known BUGS for All OC Versions.
Problemen met de BTW?: [How to] BTW + Verzend & betaalmethodes.
-

i2Paq - Global Moderator
- Posts: 9764
- Joined: Mon Nov 09, 2009 11:00 am
- Location: Winkel - The Netherlands
Re: Coupon History not working with Paypal, etc - design fla
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.
- mygameauctions
- Posts: 6
- Joined: Mon Sep 10, 2012 7:11 pm
Re: Coupon History not working with Paypal, etc - design fla
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.
- pltceat
- Posts: 8
- Joined: Sun Sep 09, 2012 11:01 am
Re: Coupon History not working with Paypal, etc - FIXED!
innuoluke wrote:And here is a handy VQMod for those that would like itAll 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.
- pltceat
- Posts: 8
- Joined: Sun Sep 09, 2012 11:01 am
Re: [1.5.x] Coupon History not working with Paypal, etc - FI
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.
the system parses the (%) to get the coupon code to add to the history.
OpenCart®
Project Owner & Developer.
OpenCart commercial support now available!
Project Owner & Developer.
OpenCart commercial support now available!
-

Daniel - Administrator
- Posts: 5173
- Joined: Fri Nov 03, 2006 10:57 am
Re: [1.5.x] Coupon History not working with Paypal, etc - FI
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.
- pltceat
- Posts: 8
- Joined: Sun Sep 09, 2012 11:01 am
Re: [1.5.x] Coupon History not working with Paypal, etc - FI
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.
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)
Increase Page Speed (#1 rated commercial extension on OpenCart Marketplace)
15in1 Essential Extensions Value Pack Premium Customer Testimonials Reward Points Extended Admin Security Lockdown Suite

irc.freenode.net #opencart
15in1 Essential Extensions Value Pack Premium Customer Testimonials Reward Points Extended Admin Security Lockdown Suite

irc.freenode.net #opencart
-

Tcalp - Posts: 761
- Joined: Wed Jul 06, 2011 5:49 am
15 posts
• Page 1 of 1
Who is online
Users browsing this forum: m3xp2013, WilliamBD and 12 guests













