How can I change a product form to show modifier stock when using Exp:resso's Store on Expression Engine?

StackOverflow https://stackoverflow.com/questions/13219826

  •  27-11-2021
  •  | 
  •  

When creating a product page for my shop, it's easy to show {total_stock}. But how can I display the stock of a modifier, or disable a modifier based on it's stock?

For instance, when selling clothes, I want to only enable the size that are in stock.

有帮助吗?

解决方案

The problem with this is that stock is linked to a SKU, and SKUs don't always map directly to a modifier. For example, if a "Shirt" product has both Size and Color, then you can't say definitively whether "Large" is out of stock, because it depends on the color as well.

That said, if your products only have a single modifier, then there is a 1-1 mapping. You should be able to access the stock level using {option_stock_level} inside the {modifier_options} loop, like so:

{modifiers}
    <select name="{modifier_input_name}">
        {modifier_options}
            <option value="{option_id}">
                {option_name} ({option_stock_level} remaining)
            </option>
        {/modifier_options}
    </select>
{/modifiers}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top