Last Updated on May 29, 2019 by Numinix Developer
Note: This article discusses a known bug in Zen Cart that is present in all versions up to and including version 1.3.9g. Hopefully after reading this, the Zen Cart team will implement this simple fix.
Today a client was trying to re-enable one of his old coupon codes that had expired by simply changing the start and finish dates. You’d be astonished to know this isn’t possible without deleting and recreating the coupon or by copying it and then using the copy. Basically, extra steps that a store owner shouldn’t have to do.
So, I did a quick search of the Zen-Cart.com forum and found this thread from 2007 explaining the steps above. http://www.zen-cart.com/forum/showthread.php?p=386571#post386571. Wow, this thread is from 2007 and the bug still hasn’t been fixed? So I looked into it and found it can be resolved with a single line of code. Took less time to fix than to perform the “recommended” rename/copy workaround.
Open admin/coupon_admin.php and find:
236 237 238 239 240 241 242 243 244 245 246 247 248 | $sql_data_array = array('coupon_code' => zen_db_prepare_input($_POST['coupon_code']), 'coupon_amount' => zen_db_prepare_input($_POST['coupon_amount']), 'coupon_type' => zen_db_prepare_input($coupon_type), 'uses_per_coupon' => zen_db_prepare_input((int)$_POST['coupon_uses_coupon']), 'uses_per_user' => zen_db_prepare_input((int)$_POST['coupon_uses_user']), 'coupon_minimum_order' => zen_db_prepare_input((float)$_POST['coupon_min_order']), 'restrict_to_products' => zen_db_prepare_input($_POST['coupon_products']), 'restrict_to_categories' => zen_db_prepare_input($_POST['coupon_categories']), 'coupon_start_date' => $_POST['coupon_startdate'], 'coupon_expire_date' => $_POST['coupon_finishdate'], 'date_created' => 'now()', 'date_modified' => 'now()', 'coupon_zone_restriction' => $_POST['coupon_zone_restriction']); |
Add after:
249 | if ( (date('Y-m-d',time()) >= $_POST['coupon_startdate']) && ( (date('Y-m-d',time()) < $_POST['coupon_finishdate']) || !isset($_POST['coupon_finishdate']) ) $sql_data_array['coupon_active'] = 'Y'; |
I love Zen Cart, but seriously, something like this should have been fixed a lot sooner…
I have over 200 coupons showing in status “Active Coupon” that the expiration date has already passed on…. what is keeping these coupons from going to Inactive? Running 1.5.4
That’s an unfortunate issue with how Zen Cart coded the coupon system. The expiration date seems to have no impact on the status column in the coupon table. We are working on our own plugin for better managing coupon codes and will definitely fix this issue in our plugin.
We’ve just updated this article with an improved condition for determining if a coupon should be active.
Ahhh I see that apparently in v1.5.x this has been addressed.. (At least I was able to reactivate a coupon by simply changing the expiration date..) Delete my previous comment.. **lol**
Found this little gem.. Thanks for it.. Can’t believe this STILL isn’t in the latest version of Zen Cart.. Anyway wanted to let you know that there is a slight “typo” in the code you posted here.. the “if” is missing the “i”..
if ( (date('Y-m-d',time()) >= $_POST['coupon_startdate']) && (date('Y-m-d',time()) < $_POST['coupon_finishdate']) ) $sql_data_array['coupon_active'] = 'Y';