2

I'm looking for a simple search of the cart contents. If a specific item I am looking for is already in cart (which I can simply define by the entry ID since the products are entries), I want to change the price applied in my add_to_cart form on the page to 0 (instead of the product's "usual" price). How can I do this? I don't think i want to do it with the cart_items_info tags from CartThrob - they have much more to them than I suspect I need.

So I'm aiming for something like this:

{if cart_contains_item_a OR cart_contains_item_b OR cart_contains_item_c}
{exp:cartthrob:add_to_cart_form return="" entry_id="{entry_id}" price="0.00"}
<input type="submit" class="button" value="Add" />
{/exp:cartthrob:add_to_cart_form}
{if:else}
{exp:cartthrob:add_to_cart_form return="" entry_id="{entry_id}" price="{cf_prod_price}"}
<input type="submit" class="button" value="Add" />
{/exp:cartthrob:add_to_cart_form}
{/if}

I'm just looking for guidance on the simplest way to determine what to include in the conditional.

4

You could use the is_in_cart tag for the conditional:

{if {exp:cartthrob:is_in_cart entry_id="{entry_id}"}}
   in cart
{if:else}
   not in cart
{/if}
6
  • Nuts. It seemed to work at first, but then i tried with multiple entry IDs. Unfortunately with this particular tag pair, is appears only a single entry ID may be used. I actually need to match more than one product ID, since there are a couple of different items that, if already in cart, result in this other set of products being free instead of regular price. I've added that additional detail to my desired conditional above. – Jean St-Amand Dec 17 '12 at 16:19
  • Would any of the discount types work for this type of scenario since it's based off items in cart? Amount Off Product,Buy X Get X, Item specific discount limited by quantity – Siebird Dec 17 '12 at 16:24
  • It's not that "developed" a cart - it's basically just for a membership renewal in an association that has a few add-on items. And for a couple of member types - which are entries in the products channel - the price for the add-ons drops to zero. But this was something that was brought to my attention late in the process. – Jean St-Amand Dec 17 '12 at 16:44
  • How are you using the code above? Is it within the native Channel entries tag? Is it within a CartThrob tag? – Siebird Dec 17 '12 at 16:51
  • Yes, it was within the native entries loop, within which a cartthrob add to cart form was applied to each entry (product). – Jean St-Amand Dec 17 '12 at 16:54
1

This is what i managed to get to work. I wouldn't consider it the "right" answer without getting opinions from others, but it does work for me as intended:

{exp:cartthrob:cart_items_info entry_id="10|11|12|13" limit="1"}
{if no_results}
   INSERT MY ADD TO CART FORM WITH REGULAR PRICING
{/if}
   INSERT MY ADD TO CART BUTTON WITH DISCOUNTED PRICING
{/exp:cartthrob:cart_items_info}

In this particular case, because of how i add the items to cart, there will only ever be one of the entries indicated in the entry_id parameter present anyway, so for me, this worked as a way to loop through the entries and determine if the specified entry id was present, and if so, apply special pricing rather than regular pricing to the add to cart button/form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.