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

Checking if Product is already in cart

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 08-17-2008, 12:37 PM
 
JRC JRC is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 38
 

Default Checking if Product is already in cart

I would like to offer customers the option to purchase another product when they go to check out. I know there are some custom mods that do that, but my needs are simple and only needed for a few products.

I have it working as far as offering the "cross sell" product, but I only want to offer it if it's not already in the cart, which I can't figure out how to get working.

At the top of cart.tpl, I was trying to loop through the cart contents and set a variable to flag the 2nd if-then to not offer the "Widget" if it's already in the cart. Here's what I have, but that part isn't working:

The first loop searches if Widget (productid 16864) is in the cart and flags (or should flag) a variable if it's found. The second part checks if product 16236 (a nice compliment to Widget/16236) and offers Widget if 16864 is being purchased:

{section name=product loop=$products}
{if $products[product].productid eq 16864}
$smarty->assign('Widget', 'true');
{/if}
{/section}

{section name=product loop=$products}
{if $products[product].productid eq 16236 && $Widget ne 'true'}
<table width="100%" border="0" cellpadding="13" cellspacing="0" bgcolor="#EEEEEE">
<tr>
<td>
<div align="center">
<span style="color: #990000; font-size: 14pt;">*** SPECIAL OFFER ***</span><br>
<span style="color: #000033; font-size: 10pt;">Purchase the <i>Demo Test Widget Addon #1 Gadget</i> today and receive 25% off your entire purchase!</span>
<br />
<br />
<a href="{$xcart_web_dir}/cart.php?mode=add&productid=16864&amount=1"><img src="/images/YesPlease.png" width="118" height="48" alt="Yes Please"></a>
</div>
</td>
</tr>
</table>
{/if}
{/section}
________________________

I'm sure it's something simple I'm missing. I just don't have enought experience with php or smarty to see what I'm doing wrong. Thanks.

- JRC
__________________
X-Cart Pro 4.1.12 | Linux | MySQL
Reply With Quote
  #2  
Old 08-18-2008, 02:15 AM
  Piotr M.'s Avatar 
Piotr M. Piotr M. is offline
 

Senior Member
  
Join Date: Aug 2008
Posts: 134
 

Default Re: Checking if Product is already in cart

Try replacing
Code:
$smarty->assign('Widget', 'true');
with
Code:
{assign var=Widget value='true'}
__________________
Regards,
Piotr Markushin

X-Cart PDF Catalog Generator NEW
Professional X-Cart Skins Store (7 new skins added in August 2008!)

ahedOffice.com - Web 2.0 Online Groupware
Reply With Quote
  #3  
Old 08-18-2008, 07:38 AM
 
JRC JRC is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 38
 

Default Re: Checking if Product is already in cart

Thanks, that worked.
__________________
X-Cart Pro 4.1.12 | Linux | MySQL
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:45 PM.

   

 
X-Cart forums © 2001-2020