Page 2 of 2
Re: Direct coupon/discount code via URL
Posted: Tue Oct 18, 2016 4:25 pm
by stagosal
Hello there i am using Opencart 2.2 here. This method works perfectly but with one problem. I would like the user to click on a popup link and redirect to to the custom link at /index.php?coupon=XXXXX. But unfortunately if no product is in the user's cart the coupon is not applied at checkout. So the user has to have at least one product in his cart and then apply the link for the coupon to be applied. Is there a way for someone to first visit the coupon link, then add products at his cart and then at the checkout the coupon to be applied?
Thank you in advance.
Re: Direct coupon/discount code via URL
Posted: Wed Feb 08, 2017 3:38 am
by JeremyColvin
Qphoria wrote:Updated my first post for 2.2.x
Hi there! First, THANK YOU for taking the time to put this fix up here!
Second, I can't seem to get it to work in OpenCart 2.1.0.1 - I don't have a "framework.php" so I tried putting it in the index.php where described, but when I try the URL / coupon it does nothing.
Any thoughts?
Re: Direct coupon/discount code via URL
Posted: Fri May 12, 2017 11:53 pm
by ritaylo3
Hi,
I tried adding the 2.2 code in framework.php of 2.3.0.2 and it doesn't work. Does anyone have a solution for 2.3.0.2?
Thanks,
ritaylo3
Re: Direct coupon/discount code via URL
Posted: Sat Mar 31, 2018 3:32 pm
by Sokonomi
I'm lurking the forum for a solution like this for 3.0.2.0. Any chance one of you know how to slip this trick into that version?
Re: Direct coupon/discount code via URL
Posted: Sat Mar 31, 2018 9:14 pm
by straightlight
OC v3.0.2.0 . In catalog/controller/startup/startup.php file,
find:
add above:
Code: Select all
// Coupon
if (!empty($this->request->get['coupon'])) {
$this->session->data['coupon'] = strip_tags(html_entity_decode(trim($this->request->get['coupon']), ENT_QUOTES, 'UTF-8'));
}
Then, in system/framework.php file,
find:
Add above:
Code: Select all
// Coupon in url
if (!empty($_GET['coupon'])) {
$session->data['coupon'] = strip_tags(html_entity_decode(trim($_GET['coupon']), ENT_QUOTES, 'UTF-8'));
}
This should resolved the issue.
Re: Direct coupon/discount code via URL
Posted: Sat Aug 22, 2020 8:00 pm
by kaliyas
This was really helpful !
Thanks a lot
Re: Direct coupon/discount code via URL
Posted: Mon Nov 21, 2022 6:38 pm
by aitechbg
OCMOD from what straightlight says

All credits to straightlight!
<modification>
<name>Coupon and affilate via url</name>
<version>1.0.0</version>
<link>https://forum.opencart.com</link>
<author><![CDATA[Coupon and affilate via url]]></author>
<code>coupon_affilate_via_url</code>
<file path="catalog/controller/startup/startup.php" error="skip" info="Coupon and affilate via url">
<operation>
<search><![CDATA[// Currency]]></search>
<add position="before"><![CDATA[
// Coupon
if (!empty($this->request->get['coupon'])) {
$this->session->data['coupon'] = strip_tags(html_entity_decode(trim($this->request->get['coupon']), ENT_QUOTES, 'UTF-8'));
}
]]></add>
</operation>
</file>
<file path="system/framework.php" error="skip" info="Coupon and affilate via url">
<operation>
<search><![CDATA[// Dispatch]]></search>
<add position="before"><![CDATA[
// Coupon in url
if (!empty($_GET['coupon'])) {
$session->data['coupon'] = strip_tags(html_entity_decode(trim($_GET['coupon']), ENT_QUOTES, 'UTF-8'));
}
]]></add>
</operation>
</file>
</modification>
Re: Direct coupon/discount code via URL
Posted: Thu Jun 13, 2024 8:32 pm
by Georgee
In Opencart 3.0.3.9 PHP 8.1 there is an error 404 "Too many redirects" when adding this OCMOD. The discount code is applied but page is white.
Can anyone help?
Re: Direct coupon/discount code via URL
Posted: Thu Jun 13, 2024 10:23 pm
by ADD Creative
Georgee wrote: ↑Thu Jun 13, 2024 8:32 pm
In Opencart 3.0.3.9 PHP 8.1 there is an error 404 "Too many redirects" when adding this OCMOD. The discount code is applied but page is white.
Can anyone help?
Check both your OpenCart and PHP error logs.
Re: Direct coupon/discount code via URL
Posted: Wed Jul 10, 2024 5:25 pm
by Georgee
ADD Creative wrote: ↑Thu Jun 13, 2024 10:23 pm
Georgee wrote: ↑Thu Jun 13, 2024 8:32 pm
In Opencart 3.0.3.9 PHP 8.1 there is an error 404 "Too many redirects" when adding this OCMOD. The discount code is applied but page is white.
Can anyone help?
Check both your OpenCart and PHP error logs.
In Opencart Log nothing added when this error occurs.
In PHP logs just 20x Code 301 GET /?coupon=XXXXX HTTP/1.0
No errors. Any idea how to solve this?
Re: Direct coupon/discount code via URL
Posted: Wed Jul 10, 2024 6:50 pm
by ADD Creative
Georgee wrote: ↑Wed Jul 10, 2024 5:25 pm
In Opencart Log nothing added when this error occurs.
In PHP logs just 20x Code 301 GET /?coupon=XXXXX HTTP/1.0
No errors. Any idea how to solve this?
I've just tested the post code and it did work fine. However it has an XSS vulnerability so I would remove the code immediately.
It looks like you have a redirect somewhere when ?coupon=XXXXX is in the URL, maybe in your htaccess.