0

I have two product types "standard" and "addon" these are just a custom field flag. An "addon" product can only be purchased if a "standard" product in in the cart.

How would I go about coding this up? Ideally it'd be great to have a conditional that I can run to disable the add to cart button for addon products till a standard product has been added to the cart. Soon as one standard product has been added to the cart any number of addons may be added.

I have seen this question but it's not the same. In this case it has to be a specific type of product not just any product.

Thanks,

Andy

  • I would create a custom EE or Cartthrob plugin that returns a true|false value depending on whether the specified product is in the cart, and enable|disable the button via this. – Bradley Flood Jun 20 '14 at 1:31
  • Thanks for the suggestion Bradley, unfortunately I wouldn't know where to start. – Andy Homan Jun 22 '14 at 13:30
1

I am going to assume (hopefully correctly) you are working with logged in users at the time of purchase, so that there is a way to check if the member in question has previously purchased a standard product.

You could do this several ways I think, but here’s what jumped into my head using the regular channel entries tag and not the query tag or something more complex.

If you did a search on the Purchased Items (not orders) channel using the logged in user’s ID and search:url_title="name-of-standard-product" it should return all of the purchases for that user, who had already purchased a standard product, to run a comparison against.

So if the page URI that contained your standard and addon products ended with "my-product-name" and you placed the above concept into a LowVariable for example (snippets, etc. could work too), I think it would look like this.

LowVar:

{exp:channel:entries 
  channel="purchased_items" 
  status="not Closed" 
  search:author_id="{user_id}" 
  search:url_title="{url_segment}" 
  dynamic="no" 
  limit="1" 
  disable="categories|member_data|pagination"
}
 true
{/exp:channel:entries}

In your template with the add to cart tags:

{if '{exp:low_variables:parse var="variable-name" preparse:user_id="{logged_in_user_id}" preparse:url_segment="{url_title}"}'=='true'}
**show the add to cart for addons**
{if:else}
**You must purchase the standard product first**
{/if}

You could do this with javascript too of course to disable the Add to Cart buttons, but hopefully this gets you started.

| improve this answer | |
  • Hi Derrick. Thanks for the feedback. Sorry No, the customer will NOT be logged in. I've actually just realised (it was late last night when I posted this) that the standard project only needs to be in the cart NOT purchased. Sorry for any confusion. I'll edit the question now to reflect this. – Andy Homan Jun 20 '14 at 0:38

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.