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

{if} {else} statement tweaking

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-14-2013, 09:15 AM
 
MAPerformance MAPerformance is offline
 

Senior Member
  
Join Date: Dec 2005
Posts: 145
 

Default {if} {else} statement tweaking

I am using a {if} {else} statement to show or hide a Free Shipping graphic on certain items on our shop.

Code:
{if $product.price >= 99.99 && $product.productid ne 20786 && $product.productid ne 17302} <img src="image.jpg" /> {else} <img src="_spacer.gif"/> {/if}
This shows my free shipping graphic on items that are $99.99 or more, and shows a blank spacer image if it's less. The problem is I have a handful of items that don't qualify for free shipping even though they are over $99.99. You can see what I did do in the code there to account for those items, but I'm wondering of there's a shorter way of declaring the $productid of these exception items other than what I've already done?

Also, maybe this can be used as a reference for someone else looking to do this
__________________
www.maperformance.com

X-Cart Version: 4.4.3 Gold
Reply With Quote
  #2  
Old 03-14-2013, 10:21 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: {if} {else} statement tweaking

Quote:
Originally Posted by MAPerformance
I am using a {if} {else} statement to show or hide a Free Shipping graphic on certain items on our shop.

Code:
{if $product.price >= 99.99 && $product.productid ne 20786 && $product.productid ne 17302} <img src="image.jpg" /> {else} <img src="_spacer.gif"/> {/if}
This shows my free shipping graphic on items that are $99.99 or more, and shows a blank spacer image if it's less. The problem is I have a handful of items that don't qualify for free shipping even though they are over $99.99. You can see what I did do in the code there to account for those items, but I'm wondering of there's a shorter way of declaring the $productid of these exception items other than what I've already done?

Also, maybe this can be used as a reference for someone else looking to do this

You may want to check this condition in PHP code (in_array() function will be useful) and then assign result to a boolean flag in $product array. It will allow you to check the same condition as something like this in Smarty:

HTML Code:
{if $product.my_free_shipping_flag eq 'Y'} <img src="image.jpg" /> {else} <img src="_spacer.gif"/> {/if}

Guess, it looks more elegant.
Reply With Quote
  #3  
Old 03-14-2013, 11:44 AM
 
MAPerformance MAPerformance is offline
 

Senior Member
  
Join Date: Dec 2005
Posts: 145
 

Default Re: {if} {else} statement tweaking

Thanks for the response. That actually makes me think... maybe we can use the "extra fields" functionality to do something like this? I don't really know how to implement your suggestion without more explicit instructions.
__________________
www.maperformance.com

X-Cart Version: 4.4.3 Gold
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:01 PM.

   

 
X-Cart forums © 2001-2020