CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Price Modifiers FieldType

See also: item options dedicated tag. The dedicated tag does not care about field name, and will output all item options found in your channel entry, regardless of name. The syntax is a bit easier to understand, so we highly recommend skipping right on over to it instead.

See also: price modifiers overview

CartThrob’s price modifiers custom fieldtype is used to display options from configurable products. These modifiers can be no-cost options, or they can add cost to the product. For more information, please see this article on configuring price_modifiers.

This page covers the standard Price Modifiers fieldtype. One field represents one independent option set, such as Color. It is not the Price Modifiers Configurator, where several groups resolve to one generated combination/SKU.

Inventory

The standard Price Modifiers field can be the inventory source for a product channel. Use it when stock belongs to one set of choices, such as Color:

  • Red: 2
  • Blue: 5
  • Green: 1

To enable modifier inventory:

  1. In CartThrob › Products, manage the product channel and map this Price Modifiers field as its Inventory field.
  2. Edit a product entry. CartThrob displays the Inventory column on the mapped Price Modifiers field; enter stock for each option row.
  3. Submit the customer’s selection using item_options[FIELD_SHORT_NAME].

When a customer selects Green, CartThrob validates the Green row and reduces only that row after the order completes. A positive value is available and 0 is sold out. Modifier inventory is tracked only when the selected row has an explicit numeric inventory value. A missing inventory column, null, or a blank value means unlimited inventory.

An entry with no option rows is also unlimited. Option selection remains optional by default, matching CartThrob 9.0.1 behavior. If the add-to-cart form omits this field, CartThrob records no selection or price adjustment from the field and does not assign or reduce a specific modifier row. With no options selected, the item uses the product’s base price. When the form explicitly submits a value, it must match an option_value stored in the field; unknown and malformed submitted values are invalid.

Requiring a storefront choice

Creating or inventory-mapping a Price Modifiers field does not automatically make it required. Require a choice in the storefront template when the merchant cannot fulfill an open-ended order:

{exp:cartthrob:add_to_cart_form
    entry_id="{entry_id}"
    required="item_options[product_color]"}
    ...
{/exp:cartthrob:add_to_cart_form}

This requires one value from the choices in product_color. To require one value from each of several option fields, list every field separated by |:

required="item_options[product_color]|item_options[product_size]"

See add_to_cart_form: Requiring product option choices for complete behavior, validation syntax, and examples.

This standard-field rule is different from Configurator inventory. When a Configurator is mapped as Inventory, CartThrob must resolve all of its selectable groups to one valid generated combination/SKU; see Price Modifiers Configurator: Inventory.

A product channel has only one Inventory mapping. Mapping this field means a separate product-wide inventory field and other modifier fields are not checked or reduced for the same purchase.

If stock belongs to a complete combination such as Large + Green instead of to Color alone, use the Price Modifiers Configurator. It creates one inventory row for each generated combination/SKU.

Make sure you are using the short name of your price modifiers field. For this example we’re using “price_modifier” as the name of the custom field.

Although the price_modifier “tag” is really a standard channel custom field, we’re treating it like a tag here. You can output some basic information about the structure and content of the price_modifier field.

Variables

YOUR_FIELD:label

The full name of the price modifier field.

{product_color:label}

YOUR_FIELD:total_results

The total number of options to choose from.

{product_color:total_results}

Variable Pairs

YOUR_FIELD

You can use your item_options field as a variable pair to output your item_options data.

{product_color} {option_value} {option_name} {price} {inventory} {/product_color}

Conditionals

{if first_row}

Checks to see if this is the first option

{product_color}{if first_row}<select name="item_options[product_color]">{/if}{/product_color}

{if last_row}

Checks to see if this is the last option

{product_color}{if last_row}</select>{/if}{/product_color}

Examples

{exp:channel:entries channel="shirts" }
    {if product_color:total_results}
        {product_color:label} has {product_color:total_results} options available
        {product_color}
            {if first_row}
            <select name="item_options[product_color]">
            {/if}
            <option value="{option_value}"{if inventory == "0"} disabled{/if}>
                {option_name} $ {price}
                {if inventory != ""} — {inventory} in stock{/if}
            </option>
            {if last_row}
            </select>
            {/if}
        {/product_color}

        <ul>
            {product_color}
                <li>{option_value} {option_name} {price} {inventory}</li>
            {/product_color}
        </ul>
    {/if}
{/exp:channel:entries}