Post by jolyonr » Mon May 21, 2012 11:51 pm

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
Last edited by i2Paq on Thu Aug 23, 2012 7:04 pm, edited 2 times in total.
Reason: Title adjusted

Newbie

Posts

Joined
Tue May 15, 2012 6:50 pm

Post by jolyonr » Tue May 22, 2012 12:04 am

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

Newbie

Posts

Joined
Tue May 15, 2012 6:50 pm

Post by artisanweb » Thu Jun 07, 2012 7:49 pm

Thankyou. Works perfectly. :)

Newbie

Posts

Joined
Thu Jun 07, 2012 7:42 pm

Post by innuoluke » Wed Jul 18, 2012 8:38 pm

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.

Web developer for Cotswold Web Services / Innuo Ltd
Need help with your Opencart website? Give us a call to see how we can help.


Newbie

Posts

Joined
Sat Jun 18, 2011 4:36 pm

Post by garydee77 » Thu Aug 23, 2012 12:05 am

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?

New member

Posts

Joined
Thu Jun 23, 2011 7:51 pm

Post by i2Paq » Thu Aug 23, 2012 7:07 pm


Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

UPGRADE to 2.x: Contemplate before thou begins!

Our FREE search: Find your answer FAST!.

BUGs?: Known BUGS for All OC Versions.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by jmasril » Mon Aug 27, 2012 9:03 am

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

Newbie

Posts

Joined
Sun Nov 13, 2011 12:59 am

Post by Fatbat » Wed Aug 29, 2012 6:34 pm

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?

User avatar
New member

Posts

Joined
Tue Feb 07, 2012 5:29 am

Post by i2Paq » Sun Sep 02, 2012 6:03 pm

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 _________________

UPGRADE to 2.x: Contemplate before thou begins!

Our FREE search: Find your answer FAST!.

BUGs?: Known BUGS for All OC Versions.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by mygameauctions » Thu Oct 04, 2012 2:57 pm

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.


Posts

Joined
Tue Sep 11, 2012 3:11 am

Post by pltceat » Thu Nov 22, 2012 12:22 am

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.

Newbie

Posts

Joined
Sun Sep 09, 2012 7:01 pm

Post by pltceat » Thu Nov 22, 2012 12:26 am

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.

Newbie

Posts

Joined
Sun Sep 09, 2012 7:01 pm

Post by Daniel » Thu Nov 22, 2012 7:01 pm

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.

OpenCart®
Project Owner & Developer.
OpenCart commercial support now available!


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by pltceat » Fri Nov 23, 2012 12:33 pm

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.

Newbie

Posts

Joined
Sun Sep 09, 2012 7:01 pm

Post by Tcalp » Fri May 17, 2013 9:04 am

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)

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

Image
irc.freenode.net #opencart


User avatar
Active Member

Posts

Joined
Wed Jul 06, 2011 1:49 pm

Post by solaris955 » Tue Feb 11, 2014 3:49 am

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

Newbie

Posts

Joined
Wed Oct 09, 2013 5:32 pm

Post by solaris955 » Tue Feb 11, 2014 3:55 am

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.

Newbie

Posts

Joined
Wed Oct 09, 2013 5:32 pm

Post by olfactorymaven » Tue May 13, 2014 10:37 am

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.

New member

Posts

Joined
Fri Apr 19, 2013 3:35 am


Post by chaserich » Sun Dec 21, 2014 3:44 am

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

New member

Posts

Joined
Mon Nov 10, 2014 2:42 pm

Post by IP_CAM » Tue Jun 23, 2015 3:57 am


Ernie's OpenCart v.1.5.6.5 LIGHT + OpenShop Admin v.1.75 Test Sites
http://www.bigmax.ch - http://www.evelo.li - http://www.openshop.li
Image


User avatar
Guru Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 14 guests