Issue with Promo codes Perch Shop

  • Hi guys, I'm hoping someone here can help me.


    I have a Perch Shop install where I've created some promo codes. All work fine on my local version. When I upload the site to a staging area and copy over the database the promo codes no longer work. The environments are the same as far as I know and everything else works fine.


    I've turned the Perch debug on, and when saving a promo code in the admin panel on the staging site, it saves and the database is updated, but I get a red perf bad debug message:


    SQL
    1. SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1


    On my local install when saving a promo code this isn't red. It is yellow (warning) though. It's the only difference between the two copies I can find and I suspect it's what's stopping the codes from working. Does anyone know what this means?


    When actually entering the promo code in the basket I don't get any errors, it just doesn't apply it. In the debug on that page after submitting the promo code I get:


    SQL
    1. SELECT * FROM perch3_shop_promotions WHERE promoFrom<='2021-11-23 18:38:00' AND promoTo>'2021-11-23 18:38:00' AND promoActive=1 AND promoDeleted IS NULL ORDER BY promoOrder ASC


    In the debug. Which should match the promo code saved in the database, and does on my local copy. But on my staging site I just get:


    Code
    1. Promo (£10) skipped: discount code not applied.


    Directly after it.


    If anyone could point me in the right direction that would be a great help. I've really no clue what's going on. ||

  • The check that happens before that line appears is

    Code
    1. if(strtoupper($data['discount_code'])!=strtoupper($code))

    Where $data is the cart info, and the $code is the Promotions discount code. Would be worth checking the promotion is set up correctly on the staging site, and then checking the result from the query is what you expect it to be.

    SQL
    1. SELECT * FROM perch3_shop_promotions WHERE promoFrom<='2021-11-23 18:38:00' AND promoTo>'2021-11-23 18:38:00' AND promoActive=1 AND promoDeleted IS NULL ORDER BY promoOrder ASC
  • Thanks Byron.


    I'm almost certain that the discount code is set up correctly, as I have the exact same site on my local server and that works as you would expect. How would I go about checking the result from the query?


    On my local site between the SELECT * FROM query and the Promo skipped (or in the local sites case Promo qualifies) there's another query:


    SQL
    1. SELECT COUNT(*) FROM perch3_shop_order_promotions WHERE promoID=1


    Which doesn't appear at all on the staging site. I assume this is just because it's not picking up any promo code to apply? If that's the case I'm pretty sure the issue is that on the staging site it's not matching the promo code entered with the promo code stored in the database for some reason.


    I've got the staging and local sites side by side and I have noticed a warning on the staging site in the admin panel under shop, which doesn't appear on the local site:


    Code
    1. Deprecated
    2. : Function money_format() is deprecated in
    3. /public_html/perch/core/lib/PerchTemplate.class.php
    4. on line
    5. 1664


    Both sites are running Perch 3.1.7. local is running PHP 7.4.21 and staging is 7.4.25. Is that likely to be an issue do you think? That small PHP version change causes the deprecated warning above? If I drop the PHP on the staging site down to 7.3 the deprecated warning in the admin panel goes away but the discount codes still don't work.


    The MySQL on local is 5.7.34 and staging is 5.7.32-35 but I don't think I can change the MySQL version anyway.


    Also on the staging site under the shop tab it shows Revenue and Recent orders where's on the local it only shows Recent orders which is strange as both these sites are the same. I literally copied all the files and the database from my local server and uploaded them to a staging server yesterday.


    Thanks again for the reply.

  • If you open up your DB in phpmyadmin or another DB management tool, you should be able to execute the query.


    That count query is a check to see if the promotion code limit has been reached, so the issue is stemming from perch not being able to find/verify the promotion code.


    Whilst the SQL versions might be the same, the sql_mode could be different which could be making queries fail, though perch should log that in the debug. You can check this with the following query. Depending on your servers you might not be able to change this, but it might give you a bit more info

    SQL
    1. SELECT @@GLOBAL.sql_mode;
  • Yes, I think you're correct as if I enter some code which doesn't exist on the local site I get the same debug messages as I get on the staging site when I enter a code that does exist. I will have a look at the database in phpmyadmin as you suggest.


    Another thing I've just noticed in the debug on the the cart page after entering the discount code and submitting the form there's this right at the bottom of the page. This appears on the staging site but not on my local site.


    Code
    1. Array
    2. (
    3. [type] => 8
    4. [message] => Trying to access array offset on value of type bool
    5. [file] => /public_html/perch/addons/apps/perch_shop/lib/PerchShop_Cart.class.php
    6. [line] => 662
    7. )


    I've looked in that file at line 662 and it seems to be something to do with tax. Which again I don't get this on the local copy. Do you know what it's trying to do here?


    Thanks for your help :)

  • I seem to have solved it. It is to do with PHP versions. If I drop the PHP version down to 7.3 on the server and create a new promo code, that will work, even if I then bump it up to 7.4 afterwards. But if I edit or create a promo code on 7.4 that breaks it, even if I drop down to 7.3 after it's still broken until I delete it and create a new one. So it's something at the point of creating or editing a promo code on 7.4.25 specifically that doesn't work. 7.4.21 on my local server works fine, but I only have 7.4.25 on my staging server or 7.3.32.


    I don't know if anyone else is running shop on 7.4.25 and can test to confirm that?


    The warnings and other errors to do with tax and the money format are all gone on 7.3 as well. I guess Shop just doesn't work on 7.4, which isn't great.


    Once the site is done I will update Perch 3.2 and see if that makes any difference. I'm hesitant to do that at the moment though as from what I gather it was a rushed update by the new developers to silence some of the complaints on the forum.

  • Scrap that it's stopped working again. Worked this morning. Came back this afternoon and nothing. Ugh ;(


    Edit:


    Ok I think I've finally found the issue. If I use a private browsing window (Safari) the promo codes work fine, and if I go into Safari settings and clear all website data then back to the shop and use a code it works!.. Which has me stumped to be honest. Are form submits effected at all by things like cookies? Does Perch store any data in the browser that would effect the promo codes?


    I'm not sure why it worked earlier now, unless changing the PHP version and creating a new promo code had some effect on something stored by the browser when revisiting the site. Again why I didn't run into this issue on the local copy of the site using the same browser I don't know. Honestly feel like binning the whole thing right now. It's always the last 1% of a site which ends up being the most time consuming!