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

Cart modification: how to hide option if product already in cart?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-11-2007, 03:25 AM
 
ben@lrb.co.uk ben@lrb.co.uk is offline
 

Member
  
Join Date: Feb 2006
Posts: 29
 

Default 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
__________________
--
X-cart Version 4.1.9
Reply With Quote
  #2  
Old 10-15-2007, 06:54 AM
 
ben@lrb.co.uk ben@lrb.co.uk is offline
 

Member
  
Join Date: Feb 2006
Posts: 29
 

Default 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
__________________
--
X-cart Version 4.1.9
Reply With Quote
  #3  
Old 10-15-2007, 08:14 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default 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}
To this:
Code:
{assign var="gwfound" value="n"} {section name=product loop=$products} {if $products[product].productid eq 3491} {assign var="gwfound" value="y"} {/if}

Then after the {/section} wherever you want it add:
Code:
{if $gwfound eq "n"} {include file="customer/main/gift_wrap.tpl"} {/if}

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.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #4  
Old 10-18-2007, 04:16 AM
 
ben@lrb.co.uk ben@lrb.co.uk is offline
 

Member
  
Join Date: Feb 2006
Posts: 29
 

Default 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"} {include file="customer/main/gift_wrap.tpl"}

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
__________________
--
X-cart Version 4.1.9
Reply With Quote
  #5  
Old 10-18-2007, 06:18 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Re: Cart modification: how to hide option if product already in cart?

Quote:
Originally Posted by ben@lrb.co.uk
Previously, I had:

Code:
{if $products[product].productid ne "3491"} {include file="customer/main/gift_wrap.tpl"}

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
The double quotes are OK but not necessary - smarty/PHP is very forgiving about converting between strings and numbers. $products is an array containing all of the products in the cart. The {section} {/section} loop repeats whats inbetween them changing $product each time to point to the next product within $products. Outside of the {section} {/section} loop the value of $product isn't defined so your test of $products[product].productid won't work. You could have moved it inside the {section}{/section} but then it would include the file once for each product that isn't 3491 in the cart - not what you want. There is no simple function to just ask if productid 3491 exists in the $products array so you have to loop through the array and check every item in the cart. Hence the need for the assign within the {section}{/section} loop to set a flag if product 3491 is found.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
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 01:52 AM.

   

 
X-Cart forums © 2001-2020