X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Editable coupons (https://forum.x-cart.com/showthread.php?t=35367)

sbkp 11-12-2007 01:34 PM

Editable coupons
 
This works in my modified 4.0.17 X-Cart. No warranty expressed or implied and all that sort of thing. It allows you to change the amount, times, and most importantly expiration date of a coupon. Changing the type isn't supported because I only use percentage coupons. But it seems pretty clear how to do it. When I finish upgrading to 4.1.19 (or whatever it is by the time I'm done), I'll post the update if no-one else beats me to it.

First, back up your coupons table (or whole DB). Or at least have a browser window open on your current coupon list. When I was developing this, an error led to the expiration time of all coupons being set to Dec 31, 1969. Don't let this happen to you... :)

provider/coupons.php:

Find

Code:

db_query("UPDATE $sql_tbl[discount_coupons] SET status='$v[status]' WHERE coupon='$coupon' $provider_condition");

Change to

Code:

$expire_time = mktime(0,0,0,$v[Month],$v[Day],$v[Year]);
db_query("UPDATE $sql_tbl[discount_coupons] SET status='$v[status]', discount='$v[discount]', expire='$expire_time', times='$v[times]' WHERE coupon='$coupon' $provider_condition");


Now, in skin1/modules/Discount_Coupons/coupons.tpl:

Find

Code:

<TD align="center">{if $coupons[prod_num].coupon_type eq "absolute"}{include file="currency.tpl" value=$coupons[prod_num].discount}{elseif  $coupons[prod_num].coupon_type eq "percent"}{$coupons[prod_num].discount}%{else}{$lng.lbl_coupon_freeship}{/if}</TD>
<TD align="center">{include file="currency.tpl" value=$coupons[prod_num].minimum}</TD>
<TD align="center">{$coupons[prod_num].times_used}/{$coupons[prod_num].times}</TD>
<TD align="center" nowrap>
{$coupons[prod_num].expire|date_format:$config.Appearance.datetime_format}
</TD>


Change to

Code:

<TD align="center" nowrap>{if $coupons[prod_num].coupon_type eq "free_ship"}{$lng.lbl_coupon_freeship}{else}<INPUT type="text" name="posted_data[{$coupons[prod_num].coupon}][discount]" value="{$coupons[prod_num].discount}" size="8">{if $coupons[prod_num].coupon_type eq "absolute"}{$config.General.currency_symbol}{else}%{/if}{/if}</TD>
<TD align="center">{include file="currency.tpl" value=$coupons[prod_num].minimum}</TD>
<TD align="center" nowrap>{$coupons[prod_num].times_used}/<INPUT type="text" name="posted_data[{$coupons[prod_num].coupon}][times]" value="{$coupons[prod_num].times}" size="8"></TD>
<TD align="center" nowrap>
{assign var=fieldname value=$coupons[prod_num].coupon}
{html_select_date prefix="" field_array="posted_data[$fieldname]" time=$coupons[prod_num].expire end_year="+5" month_format="%b"}
</TD>




For extra credit, if you would prefer to see newest (or longest time-to-live) coupons at the top of the list, then also in provider/coupons.php:

Find

Code:

$coupons = func_query("select * from $sql_tbl[discount_coupons] where 1 $provider_condition");

Change to

Code:

$coupons = func_query("select * from $sql_tbl[discount_coupons] where 1 $provider_condition order by expire desc");

fazzbech 03-17-2008 07:45 PM

Re: Editable coupons
 
Any update on this for 4.1.9 at all ? :)

sbkp 03-18-2008 07:16 PM

Re: Editable coupons
 
Sorry. Haven't upgraded yet. Is the coupon infrastructure significantly different? There's nothing particularly tricky about this change.

MrHeeltoe 10-23-2008 01:50 AM

Re: Editable coupons
 
Bad ass, thanks! I am plagued by a tendency to not give my coupons enough times, or listen to the bleeding hearts of procrastinators.

just_me 10-27-2008 11:44 PM

Re: Editable coupons
 
Great mod, thanks for sharing.
Now I can just update the expiration date and have a permanent "Free shipping on Tuesday orders".

If the coupon could be made day sensitive instead of date sensitive... it would be perfect. :D/

Any suggestions?

rahilpirani 01-09-2012 08:51 AM

Re: Editable coupons
 
Just thought I'd share this... but we were looking for a way to edit coupons (mass edit) to require a minimum for the coupons to be used (we have over 100 coupons active in our store)... so we logged into to phpMyAdmin (our database) and pasted the following code in the SQL field (obviously make sure to change the tablename and tablefield to match your db):

Code:

UPDATE tablename SET tablefield = replace(tablefield, "findstring", "replacestring");


In our case the code basically searches the xcart_discount_coupons table for a value of 0.00 in the minimum field and replaces it with 72.50 (our minimum order value for any coupons to be applied) so our code looked as such:

Code:

UPDATE xcart_discount_coupons SET minimum= replace(minimum, "0.00", "72.50");


PLEASE MAKE SURE TO BACKUP YOUR DB before making any changes!
Hope this helps!


All times are GMT -8. The time now is 12:37 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.