0

I'm having a problem with the inventory field in a product in cartthrob. For my product, there are color variations for each product and the inventory is assigned accordingly.

When displaying the products on the "add to cart" page, the cartthrob options tag will check for inventory and only display the color if it's in stock.

The problem is that if the inventory reaches 0 on both color variations, the options will still show the product (with an empty select tag).

How can I have this product not show up in my template logic if there is no inventory left for any of the variations?

{options}
{if inventory !=0 }

<select>
<option name="item_options[product_color]" value="{option_value}">{option_name}</option>
</select>
{/if}

{/options}

enter image description here

Ideally, if all inventory is at 0 in these product fields, I'd like a message to show the product is out of stock and not allow the add to cart functionality.

  • We're looking to do the exact same check for the exact same issue. We looked through the CartThrob docs and haven't come across anything useful. I have a feeling a custom plugin might be needed. – Ryan Masuga Dec 10 '13 at 17:10
  • Hmm, just thinking off the top of my head: I know you can setup PM fields as a matrix field. Not sure if that's the most efficient with your current case, but ultimately with matrix you could just run a search conditional on the matrix column. Food for thought – Siebird Dec 10 '13 at 17:24
  • Just an idea which, admittedly, I haven't fully thought out: Maybe you could write an extension which, once the field hits zero, it removes the zero so it's just a blank field. According to this it will show if blank but not if zero and hopefully at that point you could get the conditional {if inventory ==""} to work. – Natetronn Dec 10 '13 at 18:18
  • I will follow up with this shortly and explain how i worked around this – Chris M Dec 10 '13 at 19:05
  • In our case, we ended up using the cartthrob_product_reduce_inventory_method hook to check if all the item options have run out when someone places their order. If there is no inventory for the item at all, we close the entry. – Ryan Masuga Dec 10 '13 at 21:30

Your Answer

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

Browse other questions tagged or ask your own question.