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

msOptions

Simple snippet for outputting specific product options. When you know in advance 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 the current product

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

For a 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'
]}

Sorting option values

The sortOptionValues parameter lets you sort 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_valueValue to put first (optional)Any 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

SuitableNot suitable
Only specific options neededNeed ALL product options
No metadata requiredFilter by groups
Best performanceNeed option names and categories

Comparison with msProductOptions

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

If you need option metadata (categories, types, descriptions), use msProductOptions.