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

Replace add to cart button with out of stock

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 04-20-2005, 09:58 AM
 
macker123 macker123 is offline
 

Advanced Member
  
Join Date: Mar 2004
Posts: 68
 

Default Replace add to cart button with out of stock

I want to replace my add to cart button with an out of stock button when my quantity is equal to 0 for that product. I am trying the following code below in my product.tpl file, but all that happens is no add to cart button appears at all even when quantity is not equal to 0.

Can you guys tell me the proper if else statement to use.

Code:
{if $products[product].avail ne 0} {if $product.forsale ne "B"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript:if (FormValidation()) document.orderform.submit()"} } {else} [img]{$ImagesDir}/outofstock.gif[/img] {/if}
__________________
Heavily Modified 4.0.8
http://www.hiphopcapital.com
Reply With Quote
  #2  
Old 04-20-2005, 10:28 AM
 
sportruck sportruck is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 70
 

Default

You've got a nested if statement. You need to put your {else} after a {/if} to have it execute in-line with the first if statement.

Example:

Code:
{if something}do this {if another thing} {/if} {else} do this thing instead{/if}
Reply With Quote
  #3  
Old 04-20-2005, 10:33 AM
 
macker123 macker123 is offline
 

Advanced Member
  
Join Date: Mar 2004
Posts: 68
 

Default

Quote:
Originally Posted by sportruck
You've got a nested if statement. You need to put your {else} after a {/if} to have it execute in-line with the first if statement.

Example:

Code:
{if something}do this {if another thing} {/if} {else} do this thing instead{/if}

Ok thank you, could you show me how to rearrange my code. I see the example, but still can't figure out my exact code I posted.
__________________
Heavily Modified 4.0.8
http://www.hiphopcapital.com
Reply With Quote
  #4  
Old 04-20-2005, 10:39 AM
 
sportruck sportruck is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 70
 

Default

Try this...

Code:
{if $products[product].avail ne 0} {if $product.forsale ne "B"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript:if (FormValidation()) document.orderform.submit()"} {/if} {else} [img]{$ImagesDir}/outofstock.gif[/img] {/if}
Reply With Quote
  #5  
Old 04-20-2005, 10:43 AM
 
macker123 macker123 is offline
 

Advanced Member
  
Join Date: Mar 2004
Posts: 68
 

Default

Quote:
Originally Posted by sportruck
Try this...

Code:
{if $products[product].avail ne 0} {if $product.forsale ne "B"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript:if (FormValidation()) document.orderform.submit()"} {/if} {else} [img]{$ImagesDir}/outofstock.gif[/img] {/if}

I get this error if I try that.

Fatal error: Smarty error: [in customer/main/product.tpl line 11]: syntax error: mismatched tag {/if}. (Smarty_Compiler.class.php, line 2221) in /home/hiphop/public_html/Smarty-2.6.3/Smarty.class.php on line 1082
__________________
Heavily Modified 4.0.8
http://www.hiphopcapital.com
Reply With Quote
  #6  
Old 04-20-2005, 11:01 AM
 
sportruck sportruck is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 70
 

Default

All your {if} and {/if} tags need to be matched up. Try removing the last {/if}. Since you didn't post a complete set of working code it is hard to tell what is wrong.

Post your whole code if that doesn't fix it.
Reply With Quote
  #7  
Old 04-20-2005, 11:06 AM
 
macker123 macker123 is offline
 

Advanced Member
  
Join Date: Mar 2004
Posts: 68
 

Default

Quote:
Originally Posted by sportruck
All your {if} and {/if} tags need to be matched up. Try removing the last {/if}. Since you didn't post a complete set of working code it is hard to tell what is wrong.

Post your whole code if that doesn't fix it.

Ya, that still didn't work. Here is my original code pasted. I put spaces between where I think the page should be edited for this.

Code:
{* $Id: product.tpl,v 1.96.2.8 2004/10/08 07:38:32 max Exp $ *} {include file="form_validation_js.tpl"} {if $product.product_type eq "C"} {include file="modules/Product_Configurator/pconf_customer_product.tpl"} {else} <font color=000000>Viewing:{include file="location.tpl"}</font> {capture name=dialog} <TABLE WIDTH=524 BORDER=0 align=center CELLPADDING=0 CELLSPACING=0><TR><TD style="border-right: 1px solid #999999" width=289 align=center valign=top><div align=center>{include file="detailed_popup_js.tpl"} {include file="ps_image_popup_js.tpl"} {if $thumbs} {include file="customer/main/ps_thumbnails.tpl"} {else} <img src=/image.php> {/if}</div></TD><TD width=281 ROWSPAN=2 valign=top><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=5%></td><td width=95%><h1>{$product.title}</h1> <SPAN>{if $product.fulldescr ne ""}{$product.fulldescr}{else}{$product.descr}{/if}</SPAN></p> <font class=prod>Code: {$product.productcode}</font></td></tr></table><FORM name=orderform method=post action={$psurl}/cart.php?mode=add OnSubmit="javascript: return FormValidation();"><TABLE border=0 width=100% cellpadding=0 cellspacing=0><input type=hidden name=amount value=1> <INPUT type=hidden name=productid value={$product.productid}><tr><td width=5%></td><TD width=95% valign=top align=left>{if $product.taxed_price ne 0 || $variants ne ''} <FONT class=prod>Price: {include file="currency.tpl" value=$product.taxed_price}</FONT> <FONT class=MarketPrice> </FONT>{else} <INPUT type=text size=7 name=price> {/if} </TD></tr>{if $active_modules.Product_Options ne ""} { include file="modules/Product_Options/customer_options.tpl"} {/if}<TR><TD colspan=2 align=left valign=middle><INPUT type=hidden name=mode value=add> {include file="customer/main/product_prices.tpl"} {if $config.General.unlimited_products eq "Y" or ($product.avail gt 0 and $product.avail ge $product.min_amount)} {if $js_enabled} {if $smarty.get.pconf ne ""} <INPUT type=hidden name=slot value={$smarty.get.slot}> <INPUT type=hidden name=addproductid value={$product.productid}> {include file="buttons/button.tpl" button_title=$lng.lbl_pconf_add_to_configuration style="button" href="javascript:if (FormValidation()) `$ldelim`document.orderform.productid.value='`$smarty.get.pconf`';document.orderform.action='pconf.php';document.orderform.submit()`$rdelim`"} {/if} {if $product.forsale ne "B"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript:if (FormValidation()) document.orderform.submit()"} {if $login ne "" and $active_modules.Wishlist ne ""} {include file="customer/add2wl.tpl"} {/if} {else} {$lng.txt_pconf_product_is_bundled} {/if} {else} {include file="submit_wo_js.tpl" value=$lng.lbl_add_to_cart} {/if} {/if} {if $active_modules.Feature_Comparison ne ""} {include file="modules/Feature_Comparison/product_buttons.tpl"} {/if} <INPUT type=image src={$ImagesDir}/null.gif width=10 height=10 border=0 valign=top> </TD></TR></TABLE></form> </TD></TR><TR><TD rowspan=2 valign=top><TABLE border=0>{foreach from=$thumbs item=v}<TR><TD>{if $active_modules.Detailed_Product_Images ne "" && $images}{/if}<img src=/images/IMAGE_05.gif width=167 height=38 border=0>{if $active_modules.Detailed_Product_Images ne "" && $images}{/if}</TD></TR>{/foreach}</TABLE> </TD></TR><TR><TD width=281></TD></TR><TR><TD COLSPAN=2><img src=/images/IMAGE_11.gif width=570 height=28></TD></TR><TR align=center valign=top><TD COLSPAN=2>{if $active_modules.Upselling_Products ne ""} {include file="modules/Upselling_Products/related_products.tpl" } {/if} {if $active_modules.Recommended_Products ne ""} {include file="modules/Recommended_Products/recommends.tpl" }</p>{/if}</TD></TR><TR><TD COLSPAN=2><img src=/images/IMAGE_13.gif width=570 height=26></TD></TR><TR valign=top><TD COLSPAN=2>{include file="customer/main/send_to_friend.tpl" }</TD></TR></TABLE>{/capture} {include file="dialogWHITE.tpl" title=$product.product content=$smarty.capture.dialog extra="width=100%"} {/if} {if $active_modules.Product_Options ne '' && $product_options ne ''} <SCRIPT type="text/javascript" language="JavaScript 1.2"> check_options(); </SCRIPT> {/if}</p>
__________________
Heavily Modified 4.0.8
http://www.hiphopcapital.com
Reply With Quote
  #8  
Old 04-20-2005, 05:56 PM
 
sportruck sportruck is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 70
 

Default

It's very difficult to read code without the whitespace! Anyway, I think I figured out this much:

Code:
{if $config.General.unlimited_products eq "Y" or ($product.avail gt 0 and $product.avail ge $product.min_amount)} {if $js_enabled} {if $smarty.get.pconf ne ""} <INPUT type=hidden name=slot value={$smarty.get.slot}> <INPUT type=hidden name=addproductid value={$product.productid}> {include file="buttons/button.tpl" button_title=$lng.lbl_pconf_add_to_configuration style="button" href="javascript:if (FormValidation()) `$ldelim`document.orderform.productid.value='`$smarty.get.pconf`';document.orderform.action='pconf.php';document.orderform.submit()`$rdelim`"} {/if} {if $product.forsale ne "B"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript:if (FormValidation()) document.orderform.submit()"} {if $login ne "" and $active_modules.Wishlist ne ""} {include file="customer/add2wl.tpl"} {/if} {else} {$lng.txt_pconf_product_is_bundled} {/if} {else} {include file="submit_wo_js.tpl" value=$lng.lbl_add_to_cart} {/if} {*** ADD OUT OF STOCK NOTICE ***} {elseif $product.avail eq 0 or $product.avail lt $product.min_amount} [img]{$ImagesDir}/outofstock.gif[/img] {*** END OUT OF STOCK NOTICE ***} {/if}
Reply With Quote
  #9  
Old 04-20-2005, 06:39 PM
 
macker123 macker123 is offline
 

Advanced Member
  
Join Date: Mar 2004
Posts: 68
 

Default

Quote:
Originally Posted by sportruck
It's very difficult to read code without the whitespace! Anyway, I think I figured out this much:

Code:
{if $config.General.unlimited_products eq "Y" or ($product.avail gt 0 and $product.avail ge $product.min_amount)} {if $js_enabled} {if $smarty.get.pconf ne ""} <INPUT type=hidden name=slot value={$smarty.get.slot}> <INPUT type=hidden name=addproductid value={$product.productid}> {include file="buttons/button.tpl" button_title=$lng.lbl_pconf_add_to_configuration style="button" href="javascript:if (FormValidation()) `$ldelim`document.orderform.productid.value='`$smarty.get.pconf`';document.orderform.action='pconf.php';document.orderform.submit()`$rdelim`"} {/if} {if $product.forsale ne "B"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript:if (FormValidation()) document.orderform.submit()"} {if $login ne "" and $active_modules.Wishlist ne ""} {include file="customer/add2wl.tpl"} {/if} {else} {$lng.txt_pconf_product_is_bundled} {/if} {else} {include file="submit_wo_js.tpl" value=$lng.lbl_add_to_cart} {/if} {*** ADD OUT OF STOCK NOTICE ***} {elseif $product.avail eq 0 or $product.avail lt $product.min_amount} [img]{$ImagesDir}/outofstock.gif[/img] {*** END OUT OF STOCK NOTICE ***} {/if}

Thanks for your help, although that doesn't seem to do it. It simply changes nothing. The add to cart still works and no out of stock image when I set the quantity to 0.
__________________
Heavily Modified 4.0.8
http://www.hiphopcapital.com
Reply With Quote
  #10  
Old 04-20-2005, 06:47 PM
 
sportruck sportruck is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 70
 

Default

Seems like your unlimited products could be on (disable inventory tracking)

Put {$config.General.unlimited_products} in your code and see what it returns.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 11:50 PM.

   

 
X-Cart forums © 2001-2020