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
Reason: Title adjusted
So to fix the coupon system, do this:
in catalog/model/checkout/coupon.php
chage
Code: Select all
public function getCoupon($code) {
Code: Select all
public function getCoupon($code,$noverify=0) {
Code: Select all
if ($status) {
return array(
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);
Code: Select all
$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
Jolyon
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.
Norman in 't Veldt
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
[How to] BTW + Verzend + betaal setup.
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?
Just checked my 1.5.4.1 install and the old, not working, code is still there.Fatbat wrote:Has this issue been fixed in 1.5.4.X or not?
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!.
[How to] BTW + Verzend + betaal setup.
jolyonr wrote:Yes, that fixes it.
So to fix the coupon system, do this:
in catalog/model/checkout/coupon.php
chage
toCode: Select all
public function getCoupon($code) {
AND changeCode: Select all
public function getCoupon($code,$noverify=0) {
toCode: Select all
if ($status) { return array(
Code: Select all
if (($status)||($noverify)) { return array(
Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change
toCode: Select all
$coupon_info = $this->model_checkout_coupon->getCoupon($code);
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.Code: Select all
$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
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.
jolyonr wrote:Yes, that fixes it.
So to fix the coupon system, do this:
in catalog/model/checkout/coupon.php
chage
toCode: Select all
public function getCoupon($code) {
AND changeCode: Select all
public function getCoupon($code,$noverify=0) {
toCode: Select all
if ($status) { return array(
Code: Select all
if (($status)||($noverify)) { return array(
Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change
toCode: Select all
$coupon_info = $this->model_checkout_coupon->getCoupon($code);
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.Code: Select all
$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
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.
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.
the system parses the (%) to get the coupon code to add to the history.
OpenCart®
Project Owner & Developer.
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.
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
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
<?php
// Text
$_['text_coupon'] = 'Coupon(%s)';
?>
So, it does have % in it.
Is that the correct code? - Thanks very much in advance.
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.1pltceat wrote:jolyonr wrote:Yes, that fixes it.
So to fix the coupon system, do this:
in catalog/model/checkout/coupon.php
chage
toCode: Select all
public function getCoupon($code) {
AND changeCode: Select all
public function getCoupon($code,$noverify=0) {
toCode: Select all
if ($status) { return array(
Code: Select all
if (($status)||($noverify)) { return array(
Next, in catalog/model/total/coupon.php in the confirm function right near the bottom change
toCode: Select all
$coupon_info = $this->model_checkout_coupon->getCoupon($code);
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.Code: Select all
$coupon_info = $this->model_checkout_coupon->getCoupon($code,1);
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.
Many thanks.
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
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Users browsing this forum: No registered users and 1 guest