Jump to content

coupon code stopped working


Recommended Posts

I have version 6 installed. Not sure how to find my exact version number.

I have not updated since installed a few years ago. Coupon codes have been working fine, but haven't used them since July 2020.

I created a new code. When I save it. everything looks ok except the actual name of the coupon code is missing. That field is blank.

Checked the database and it was missing. I manually added it to the db and it showed up in the admin page properly. If I edit that code, to change the percentage for example and save it, the name disappears both in the coupon code page and the db.

I tried changing a previous coupon code that used to work, but the same thing happened.

Even after manually entering the code into the db, customers get the 'sorry, coupon code doesn't exist' error.

Coupon is set to apply to all products.

Did search the forums, but fixed didn't seem to apply to my version.

Since nothing has changed on my part, I'm baffled as to why they don't work all of a sudden.

Link to post
Share on other sites

Technical Details

CubeCart Version

6.2.5

PHP Version (7.2 Recommended)

7.3.22

MySQL Version

10.1.40-MariaDB-cll-lve

Image folder size

Calculate

Download folder size

Calculate

Max. Upload filesize

999M

Browser user-agent

Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4 Lightning/5.4

Server Software

Apache

 

Hope this helps

Link to post
Share on other sites

In that issue report, there are two links to code changes:

#2308 - Strict PSRE2 support for PHP 7.3
https://github.com/cubecart/v6/commit/8ddd8a3e3f48b400ba5888fe524fa699e6043cac

#2308 - Further PSRE2 support 
https://github.com/cubecart/v6/commit/979c13574353ace4d5255b55312f65fb9617b0e5

To solve your immediate problem, per the code changes mentioned above, in the admin file /sources/products.coupons.inc.php, near line 55:

Find:
'code'   => preg_replace('/[^\w-_]/', '', $_POST['coupon']['code']),

Replace with:
'code'   => preg_replace('/[^\w\-\_]/g', '', $_POST['coupon']['code']),

Also, in /classes/cart.class.php, near line 519:

Find:
if (($coupon = $GLOBALS['db']->select('CubeCart_coupons', '*', "`code` = '".preg_replace('/[^\w-_]/', '', $code)."' AND `status` = 1", false, 1, false, false)) !== false) {

Replace with:
if (($coupon = $GLOBALS['db']->select('CubeCart_coupons', '*', "`code` = '".preg_replace('/[^\w\-\_]/g', '', $code)."' AND `status` = 1", false, 1, false, false)) !== false) {

 

Link to post
Share on other sites

Thanks for the detailed response.

I made the changes, confirmed the files were changed, tried to check out and still getting the error. Do I have to restart something or ?

The following errors were detected:

  • Sorry, that code does not exist.

Tried to add code. Code is called "superdeal" @ 60percent. Still doesn't show up.

 

image.png.ebf3d5a9ede9cc33abda4e0c140a1829.png

 

Database:

image.png.1e3bedf9b0e8abc8d23105773bab62ba.pngimage.png.ebf3d5a9ede9cc33abda4e0c140a1829.png

Link to post
Share on other sites

It looks like the only coupon enabled still has no Code (or, Name) for it.

Please edit the 60% coupon "Code" (using only letters, numbers, and a dash or underscore) and save.

Then have CubeCart clear it's internal cache. You can do this in admin, Maintenance, Rebuild tab, check the Clear cache box and then Submit.

 

Link to post
Share on other sites

I think that's the main problem. The name never shows up in the database or the promotional code page. Tried editing it. Tried adding new code. Same problem.

Additional information.

I haven't changed anything in Cubecart for over 2 years.

When I add the code name manually to the database, it does show up in the admin section, but still gets error on checkout.

After adding code to database manually, then go to the admin section and edit and save it, the name disappears in both places.

It's as if the 'save' button sql is missing the 'name' field. But that doesn't explain why it doesn't work if I add it manually.

Link to post
Share on other sites

Having made the changes to the PHP files should have been all that was necessary. (A restart is not required, but clearing CubeCart's cache is required for the storefront. While in admin, the cache is never used.)

You can verify that the form is POSTing the correct data by using the browser's developer tools. Use the Network panel to inspect the request having the POST method, after saving the changes to the form.

 

Edited by bsmither
Link to post
Share on other sites

I want to thank you for taking so much time to try and help me. it means a lot to me. Sorry I got the last post wrong.

Hopefully I got it right this time.

image.png.10cb7a27199027e2d2f33023619e46c2.png

Content-Type: multipart/form-data; boundary=---------------------------8483554229233913531803576152
Content-Length: 2038

-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[code]"

superdeal
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[description]"


-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="discount_type"

percent
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="discount_value"

60.00
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[expires]"

0000-00-00
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[allowed_uses]"

0
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[min_subtotal]"

0.00
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[shipping]"

0
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[free_shipping]"


-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[coupon_id]"

9
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="coupon[cart_order_id]"


-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="product[]"


-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="incexc"

exclude
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="save"


-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="previous-tab"

#edit-coupon
-----------------------------8483554229233913531803576152
Content-Disposition: form-data; name="token"

a8ed2df937caf4385ddebe46d05359bf
-----------------------------8483554229233913531803576152--


If that's wrong, I'm sorry. I'm trying.

Link to post
Share on other sites

We see that your browser is correctly POSTing: "coupon[code]" = "superdeal".

We need to now refocus our attention to the edits made to the code in the admin script /sources/products.coupons.inc.php.

From the above, I see that your site is current enough to be using the new syntax for the administration file and folder: admin_aBcDeF.php and /admin_uVwXyZ/ (where the nonsensical letters are random).

So, allow me to ask, do you have more than one PHP file that starts with admin? Do you have more than one folder that starts with admin?

If so, did you edit the file in the correct administration folder? (Sorry, I have to ask because this misunderstanding happens more often than you would think.)

Edited by bsmither
Link to post
Share on other sites

I installed it and did some small edits on the look of it in templates files. There is an admin.bak directory that I created to keep the original files in, in case I needed to make changes to any file.

That's not the directory I changed the files in. Should I delete that directory? To the best of my knowledge, I never did any editing on anything related to admin stuff unless you told me to for some reason in the forum. I can't remember if you did.

One thing to keep in mind. This has been working as late as July 2020. I haven't touched it since then.

The only other weird situation is that everything BUT the name gets put into the database when I click on 'save', as you can see from above the 'code' name is blank.

One more thing I just noticed. In the db, there is an 'exclude' word under 'product id'. When I created the older codes, I never went into the tab where you included or excluded products. However, when I created the new code now, I clicked on that tab and noticed that it said  "Promotional code applies to all EXCEPT above products", which I selected since I had no products listed. The old codes worked without selecting "Promotional code applies to all EXCEPT above products"

Link to post
Share on other sites

You do not need to delete the /admin.bak/ directory.

The 'include' and 'exclude' does not affect why the name is not getting databased.

Please let me see the code from products.coupons.inc.php, from lines 52 to 60.

Link to post
Share on other sites

   $coupon_id = (isset($_POST['coupon']['coupon_id'])) ? (int)$_POST['coupon']['coupon_id'] : null;

    $record  = array(
        'code'   => preg_replace('/[^\w\-\_]/g', '', $_POST['coupon']['code']),
        'product_id' => null,
        'expires'  => $_POST['coupon']['expires'],
        'allowed_uses' => (int)$_POST['coupon']['allowed_uses'],
        'min_subtotal' => $_POST['coupon']['min_subtotal'],
        'shipping'  => $_POST['coupon']['shipping'],
        'description' => $_POST['coupon']['description'],
        'free_shipping' => $_POST['coupon']['free_shipping'],
        ## Temporary reset
        'discount_percent' => 0,
        'discount_price' => 0
    );

Link to post
Share on other sites

This is interesting. PHP 7.4 is complaining about an unknown modifier /g for preg_replace().

Looking into this.

Well, I was mislead. So, please do this:

To solve your immediate problem, per the code changes mentioned above, in the admin file /sources/products.coupons.inc.php, near line 55:

Find:
'code'   => preg_replace('/[^\w-_]/', '', $_POST['coupon']['code']),

Replace with:
'code'   => preg_replace('/[^\w\-\_]/', '', $_POST['coupon']['code']),

Also, in /classes/cart.class.php, near line 519:

Find:
if (($coupon = $GLOBALS['db']->select('CubeCart_coupons', '*', "`code` = '".preg_replace('/[^\w-_]/', '', $code)."' AND `status` = 1", false, 1, false, false)) !== false) {

Replace with:
if (($coupon = $GLOBALS['db']->select('CubeCart_coupons', '*', "`code` = '".preg_replace('/[^\w\-\_]/', '', $code)."' AND `status` = 1", false, 1, false, false)) !== false) {


The above is a copy of my instruction at the very beginning - the only difference is that the g after the second slash cannot be there.

I am so sorry.

Edited by bsmither
Link to post
Share on other sites
  • 3 weeks later...

I think we can say that CubeCart is finding the reference to the coupon in the database. Otherwise, a "Coupon not found" message would be displayed.

An "expired" code should reflect that this coupon has been used its max number of times or has reached its expiration date. Can you verify?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...