View Single Post
  #1  
Old 11-12-2007, 01:34 PM
 
sbkp sbkp is offline
 

Advanced Member
  
Join Date: Jul 2005
Posts: 83
 

Default 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");
__________________
Gold 4.0.17
On Sale, Smart Search, X-AOM, X-SpecialOffers, XNews, DSEFU, and custom mods/tweaks
Reply With Quote