Need help with a tricky IF statement...

Hi all,



I’m trying to get a “.tpl” with a modified cart status to load on the top of the “content.tpl”, but I need to set some exceptions… This is what I’m trying to do:



If customer has something in his cart, then the “cart_status_top.tpl” gets loaded on the top of everything else in the “content.tpl”.



But this “cart_status_top.tpl” should not show when the user is viewing any of these:



cart

checkout

invoice

orders

order_details



Looking at the Smarty IF statement reference here, I came up with this:


{if $cart_amount and ( $content != "cart" || $content != "checkout" || $content != "invoice" || $content != "orders" || $content != "order_details" ) }
whatever I want to do
{/if}




in other words:



IF (cart is full) AND (the content loaded is NOT “cart” NOR “checkout” NOR “invoice” NOR “orders” NOR “order_details”)

DO THIS



Is this correct? The “whatever I want to do” is working fine, but I can still see the “cart_status_top.tpl” whenever I have something in the cart, even though I am in the “checkout” page - or any other pages I’m not supposed to see if the statement is working as it should.



Advices?

You might try using $target instead of $content

yea you’ll want to use $target but you also need some additional code to tell the cart is full, not sure off the top of my head the exact code but it would be something similar to $cart_amount = ‘0’ show template ect… that way when any amount other then 0 exists your template will not show ect…like at the smarty tutorials ($amount < 0 or $amount > 1000) it looks like you can use something similar like $cart_amount < 0 or $cart_amount > 1000 ect…

I just tried it on our testing version, and couldn’t get it to work until I changed up the structure a bit. Got it working like this


{if ($cart_amount > 0) and ($target != "cart") and ($target != "checkout") and ($target != "invoice") and ($target != "orders") and ($target != "order_details")}
What you want to do
{/if}




That might not be the most streamlined way to accomplish it, but once I worded it like that, it worked just fine. Hope that helps

not tested but this should work too:


{if $cart_amount > 0 and $target != "cart" || $target != "checkout" || $target != "invoice" || $target != "orders" || $target != "order_details"}
What you want to do
{/if}

[quote name=‘bpaulette’]I just tried it on our testing version, and couldn’t get it to work until I changed up the structure a bit. Got it working like this


{if ($cart_amount > 0) and ($target != "cart") and ($target != "checkout") and ($target != "invoice") and ($target != "orders") and ($target != "order_details")}
What you want to do
{/if}




That might not be the most streamlined way to accomplish it, but once I worded it like that, it worked just fine. Hope that helps[/QUOTE]



The “$cart_amount” is a variable that only comes up when the cart already has at least a product in it. It’s the variable used in the “cart_pages/cart_status.tpl” to show the cart status in the cart sidebox. So there’s no need for a “> 0”.



I tried everything, but only after I modified bpaulette’s code to this:


{if $cart_amount and ( $target != "cart" ) and ( $target != "checkout" ) and ( $target != "invoice" ) and ( $target != "orders" ) and ( $target != "order_details" ) }



It did work. Thanks a lot for this brainstorming guys, this really helped!



@snoroket: I had a hard time not understanding why the “||” (or) wasn’t working, but since I tried it in several different combinations and still didn’t get it to work, I tried bpaulette’s alternative. It worked just fine after I took away the “> 0” and a couple of parenthesis.



@bpaulette: cheeeeers!



You can see the modification live in our store at http://www.illusion.no (you’ll have to add something to the cart to see it.



The purpose was to make the cart status more visible for customers. I modified the cart sidebox as well to show a green background when the cart is full. Next step is to apply the ajax refresh to the top cart status :wink:



Cheers!

Glad it worked out. I was a little confused that the ||'s weren’t working when I tried it out as well. oh well



That’s a good idea - when the green box pops up, it definitely cathes your eye.