Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Editable coupons

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #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
  #2  
Old 03-17-2008, 07:45 PM
 
fazzbech fazzbech is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 52
 

Default Re: Editable coupons

Any update on this for 4.1.9 at all ?
__________________
Fayette

X-Cart Pro v4.1.6
Reply With Quote
  #3  
Old 03-18-2008, 07:16 PM
 
sbkp sbkp is offline
 

Advanced Member
  
Join Date: Jul 2005
Posts: 83
 

Default Re: Editable coupons

Sorry. Haven't upgraded yet. Is the coupon infrastructure significantly different? There's nothing particularly tricky about this change.
__________________
Gold 4.0.17
On Sale, Smart Search, X-AOM, X-SpecialOffers, XNews, DSEFU, and custom mods/tweaks
Reply With Quote
  #4  
Old 10-23-2008, 01:50 AM
 
MrHeeltoe MrHeeltoe is offline
 

eXpert
  
Join Date: Jan 2006
Posts: 206
 

Default 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.
Reply With Quote
  #5  
Old 10-27-2008, 11:44 PM
  just_me's Avatar 
just_me just_me is offline
 

Advanced Member
  
Join Date: Oct 2005
Location: Spain
Posts: 69
 

Wink 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.

Any suggestions?
__________________
Cordially,
Just me
X-Cart Gold
Version 4.2.3
Multilingual shop: Spanish, French and US English

Last edited by just_me : 10-28-2008 at 12:51 AM. Reason: additional information
Reply With Quote
  #6  
Old 01-09-2012, 08:51 AM
 
rahilpirani rahilpirani is offline
 

Newbie
  
Join Date: Dec 2010
Posts: 1
 

Default 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!
__________________
Version 4.1.11
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:57 PM.

   

 
X-Cart forums © 2001-2020