![]() |
Cart modification: how to hide option if product already in cart?
I've created a snippet of code to add a giftwrap option to the shopping cart (a hidden product, click to opt-in).
However, I want this NOT to show up if there is already giftwrap in the cart. Obviously the basic structure I'm after is something like: {if [cart contents] [does not contain] [product 3491]} {include file="customer/main/gift_wrap.tpl"} {/if} but I'm not sure what variables to use in the if statement, or indeed, what expression Smarty uses for a "does not contain" match (so far I've just seen equals, not equals, greater than, less than etc. etc.) Can anyone advise here? Many thanks, Rachael |
Re: Cart modification: how to hide option if product already in cart?
Still hoping that someone out there has the answer to this... There must be some of this logic used somewhere in X-Cart because of the "give products for free" if a certain product is added to the card special-offers thing.
Cheers, Rachael |
Re: Cart modification: how to hide option if product already in cart?
If you want the include after the list of products you can check in the loop that lists the products. Change this:
Code:
{section name=product loop=$products} Code:
{assign var="gwfound" value="n"} Then after the {/section} wherever you want it add: Code:
{if $gwfound eq "n"} If you want it before the list of products you'll probably have to add a second {section} {/section} block to loop through the array just to check for it. |
Re: Cart modification: how to hide option if product already in cart?
Hi Ralph,
Thanks so much - that works beautifully. This is a very elementary question, but I am really new to this: Why does the check need to be assigned to a separate variable for the evaluation to work? Previously, I had: Code:
{if $products[product].productid ne "3491"} but although it was including the file fine, it was doing it regardless of the existence of product 3491. Though I guess that could be (a) the double quotes round the product ID (b) the fact that I had the evaluation happening outside the products section?? It would be useful to know why this works for future ref... Cheers, Rachael |
Re: Cart modification: how to hide option if product already in cart?
Quote:
|
All times are GMT -8. The time now is 01:30 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.