X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Checking if Product is already in cart (https://forum.x-cart.com/showthread.php?t=41807)

JRC 08-17-2008 12:37 PM

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

Piotr M. 08-18-2008 02:15 AM

Re: Checking if Product is already in cart
 
Try replacing
Code:

$smarty->assign('Widget', 'true');
with
Code:

{assign var=Widget value='true'}

JRC 08-18-2008 07:38 AM

Re: Checking if Product is already in cart
 
Thanks, that worked.


All times are GMT -8. The time now is 01:13 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.