View Full Version : Determining if an item is in the cart
Brandon MUS
09-05-06, 11:08 PM
I want to display a message to a customer if a certain item is not in the cart. Is there a way for me to check using entities if an item is in the cart, and if it is, not display the message?
I know this is a far shot, but what would be even better is to see if they have ever purchased this item (and if they have, don't display the message).
SpaceMoose
09-07-06, 01:40 AM
I'm not a Miva guru, but here's a suggestion that might work If you only need to display this message during checkout or on the basket page..
This solution would require the use of Bill Wieland's Toolkit v5 module (http://www.emporiumplus.com/merchant2/merchant.mvc?Screen=PROD&Store_Code=wcw&Product_Code=1AA00223&Category_Code=1AAM5) in order to create your own variable so that you can temporarily 'tag' (or 'Flag') a product match, so to speak.
On the template code for displaying the basket contents, there is a 'foreach' loop that iterates for each item in a basket. I would compare the product code for the basket item being processed with the product code for the required product you are looking for. If at any point the procuct code you are looking for is matched, then I would set a user defined variable to 1 in order to 'flag' the match.
Then, at an appropriate point in the template code after the foreach loop (that is, after the basket list has been built and all basket items processed) you can check your user variable to see if the value is one or non-zero
- If it is, then display your message.
Obviously, because you require the basket display template code to execute first, you can only display the message under the basket contents display on the page.
Anyhow, sounds good on paper to me! :D
Perhaps it would do the trick?
Bruce - PhosphorMedia
09-07-06, 06:33 AM
Within the basket contents loop (<mvt:foreach iterator="item" array="basket:items">), you should be able to do a
<mvt:if expr="basketlist.d.code EQ 'Product_Code'";
Brandon MUS
09-07-06, 06:45 PM
Where is this best place to get inside of this loop without making my own? I'm trying to do this on the OSEL screen somewhere
SpaceMoose
09-08-06, 09:47 AM
Where is this best place to get inside of this loop without making my own? I'm trying to do this on the OSEL screen somewhere
Well, you'll find this loop in the Basket Contents template for the OSEL page. The Basket template is not part of the OSEL template itself, so you need to click on the 'Basket Contents' when you're on the Edit screen for the 'Checkout: Shipping/Payment Selection' page in order to get to the basket contents template for that page.
You need to put code in 3 places.
1) The first bit of code sets the test variable (using Weiland's Toolkit V5) which I've called 'in_the_basket'. I'd place this at the very begining of the Basket Contents template, before the loop happens:
<mvt:item name="toolkit" param="sassign|in_the_basket|0" />
2) Next, you need to test each basket item to see if the product you are looking for is one of the items in the basket. If one of the items in the basket matches, then set the 'in the basket variable to equal 1. You could put this code after the line within the ForEach loop which prints out the basket item's product codes -that'll be after the line containing &mvt:item:code;
<mvt:if expr="l.settings:item:code EQ 'Insert-Required-Product-Code-Here' ">
<mvt:item name="toolkit" param="sassign|in_the_basket|1" />
</mvt:if>
3) Finally, if no match was found for your particular product code out of all the items in the basket, then you'll want to print your message or whatever you want. Anyhow, if none of the items matched, then the variable 'in_the_basket' will still hold zero. I put this code at the very end of the Basket Contents template right after the basket's table gets closed:
<mvt:if expr="in_the_basket EQ 0">
<b>You don't have the Required/Recommended product included in your Basket</b>
</mvt:if>
And finally(really, this time), Note that because this solution uses weiland's Toolkit V5 module, you'll have to make sure that the Toolkit is enabled for the OSEL page by going to the Items tab for the OSEL page and ticking the Toolkit Item (probably the last item in the list). This will allow the toolkit to work on the OSEL page.
vBulletin® v3.7.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.