Skip to content
  1. Extras
  2. MiniShop3
  3. Snippets
  4. msOptions

msOptions

Snippet for outputting specific product options. When you know which options you need, use this snippet for best performance.

Parameters

ParameterDefaultDescription
productcurrent resourceProduct ID
optionsComma-separated option list
tpltpl.msOptionsLayout chunk
sortOptionValuesSort option values (see below)

Deprecated parameters

Backward compatibility

These parameters are deprecated and will be removed in future versions:

  • &input → use &product
  • &name → use &options

Examples

Output color and size for current product

fenom
{'msOptions' | snippet: [
    'options' => 'color,size'
]}

For specific product

fenom
{'msOptions' | snippet: [
    'product' => 123,
    'options' => 'color,size,material'
]}

Uncached call

fenom
{'!msOptions' | snippet: [
    'options' => 'color,size'
]}

Custom chunk

fenom
{'msOptions' | snippet: [
    'options' => 'color,size',
    'tpl' => 'myOptionsChunk'
]}

With value sorting

fenom
{'msOptions' | snippet: [
    'options' => 'color,size',
    'sortOptionValues' => 'size:SORT_ASC:SORT_STRING:M'
]}

Option value sorting

The sortOptionValues parameter sorts values within each option.

Format

option_name:direction:type:first_value
PartDescriptionValues
option_nameOption key to sortcolor, size, etc.
directionSort directionSORT_ASC, SORT_DESC
typeSort typeSORT_STRING, SORT_NUMERIC, SORT_NATURAL
first_value(optional) Value to put firstAny value from the list

Sorting examples

fenom
{* Sizes alphabetically *}
'sortOptionValues' => 'size:SORT_ASC:SORT_STRING'

{* Sizes alphabetically, M first *}
'sortOptionValues' => 'size:SORT_ASC:SORT_STRING:M'

{* Multiple options *}
'sortOptionValues' => 'size:SORT_ASC:SORT_STRING, color:SORT_DESC:SORT_STRING'

Placeholders in chunk

PlaceholderDescription
{$id}Product ID
{$options}Array of options and their values

Data structure

Returns an array of option values without metadata:

php
[
    'color' => ['Red', 'Blue'],
    'size' => ['S', 'M', 'L']
]

Default chunk

The default chunk tpl.msOptions outputs options as select elements:

fenom
{* tpl.msOptions *}
{foreach $options as $name => $values}
    <div class="form-group row align-items-center mb-4">
        <label class="col-6 col-md-3 text-right text-md-left col-form-label"
               for="option_{$name}">
            {('ms3_product_' ~ $name) | lexicon}:
        </label>
        <div class="col-6 col-md-9">
            <select name="options[{$name}]" class="form-select col-md-6" id="option_{$name}">
                {foreach $values as $value}
                    <option value="{$value}">{$value}</option>
                {/foreach}
            </select>
        </div>
    </div>
{/foreach}

Alternative chunk

Simple list output example:

fenom
{* tpl.myOptions *}
{if $options?}
    <div class="product-options">
        {foreach $options as $key => $values}
            <div class="option">
                <strong>{$key}:</strong>
                {if $values is iterable}
                    {$values | join: ', '}
                {else}
                    {$values}
                {/if}
            </div>
        {/foreach}
    </div>
{/if}

When to use

Use msOptionsUse msProductOptions instead
Only specific options neededNeed ALL product options
No metadata neededFilter by groups
Best performanceNeed option labels, categories

Comparison with msProductOptions

CriteriamsOptionsmsProductOptions
SpeedFasterSlower
FilteringOption list onlyGroups, options, sort
MetadataNoneFull (category, type)
FlexibilitySimpleAdvanced
Use caseFixed listDynamic list

For option metadata (categories, types, labels) use msProductOptions.