Page 1 of 1

[solved] {if} statements and multiple conditions in modules

Posted: Sun Dec 27, 2009 8:50 am
by kurashiki_ben
Hi,

I am stuck with a general issue regarding {if} statements in one module.

In the cart module, I want to display different messages depending on how many products are in the cart.

{if no products}
you have no products
{else}{if number of products >10}
sorry, maximum of 10 products for an online order, please call
{else}
display cart
{/if}
{/if}

I have used:
{if !isset($cartitems) || count($cartitems) >10 }
[CONTENT]
{else}
{if !isset($cartitems) || count($cartitems) == 0 }
[CONTENT]
{else}
[CART]
{/if}
{/if}

However, the {if !isset($cartitems) || count($cartitems) >10 } isn't taken into account at all.
The cart works as if that condition wasn't present.
If it is empty, it displays the empty message, but I can add as many items as I want without it displaying the >10 please call message.

Can you help me with the syntax please?

Regards

Ben

Re: {if} statements and multiple conditions in modules

Posted: Sun Dec 27, 2009 3:34 pm
by Peciura
Try

Code: Select all

{if count($cartitems)==0}
   [cart is empty]
{elseif count($cartitems)>0 && count($cartitems)<=10 }
   [CART]
{else}
   [invalid number of items]
{/if}

Re: {if} statements and multiple conditions in modules

Posted: Mon Dec 28, 2009 10:51 am
by kurashiki_ben
Peciura wrote: Try

Code: Select all

{if count($cartitems)==0}
   [cart is empty]
{elseif count($cartitems)>0 && count($cartitems)<=10 }
   [CART]
{else}
   [invalid number of items]
{/if}
Yep, that works a treat!
Actually, I needed $cart_itemcount not count($cartitems).

Final solution

Code: Select all

{if count($cartitems)==0}
   [cart is empty]
{elseif ($cart_itemcount)>0 && ($cart_itemcount)<=10}
   [CART]
{else}
   [invalid number of items]
{/if}
==> [solved]
Thanks!!

Ben

Re: [solved] {if} statements and multiple conditions in modules

Posted: Mon Dec 28, 2009 1:27 pm
by jmcgin51
great - please add [solved] to the subject line of your original post, so that others will know it this issue is solved

Re: [solved] {if} statements and multiple conditions in modules

Posted: Mon Dec 28, 2009 1:33 pm
by kurashiki_ben
jmcgin51 wrote: great - please add [solved] to the subject line of your original post, so that others will know it this issue is solved
already is  ;D see your re: [solved]  ;)