Skip to content
  1. Extras
  2. ms3Variants
  3. Snippets

Snippets

msProductVariants

Snippet for outputting product variants on the product page.

Parameters

ParameterDefaultDescription
productcurrent resourceProduct ID
tplms3_variantsWrapper chunk for all variants
tplRowms3_variants_rowChunk for a single variant
activeOnly1Only active variants (1/0)
sortbypositionSort field: position, price, sku, count
sortdirASCDirection: ASC or DESC
includeJs1Include JavaScript (1/0)
includeCss1Include CSS (1/0)
outputSeparator\nSeparator between variants
returnData0Return data as array instead of HTML (1/0)

Basic call

fenom
{'msProductVariants' | snippet}

With custom chunks

fenom
{'msProductVariants' | snippet : [
    'tpl' => 'my_variants_wrapper',
    'tplRow' => 'my_variant_item'
]}

Sort by price

fenom
{'msProductVariants' | snippet : [
    'sortby' => 'price',
    'sortdir' => 'ASC'
]}

For another product

fenom
{'msProductVariants' | snippet : [
    'product' => 42
]}

Get data into a variable

fenom
{set $variantsData = 'msProductVariants' | snippet : ['returnData' => 1]}

{if $variantsData.total > 0}
    <p>{$variantsData.total} variants available</p>

    {foreach $variantsData.variants as $variant}
        <div>{$variant.sku}{$variant.price} ₽</div>
    {/foreach}
{/if}

Placeholders in tpl (wrapper)

PlaceholderTypeDescription
{$product_id}intProduct ID
{$rows}stringRendered variant rows
{$variants}arrayArray of variants for Fenom
{$available_options}arrayUnique options with values
{$total}intNumber of variants
{$options_json}stringJSON of available options
{$variants_json}stringJSON variant mapping

Placeholders in tplRow (variant row)

PlaceholderTypeDescription
{$id}intVariant ID
{$product_id}intProduct ID
{$sku}stringSKU
{$price}floatPrice
{$old_price}floatOld price
{$count}intStock
{$weight}floatWeight
{$active}boolActive flag
{$position}intPosition
{$in_stock}boolIn stock
{$image_url}stringImage URL
{$options}arrayOptions array [{key, value}, ...]
{$options_string}stringOptions as string: "Red, XL"
{$options_array}arrayAssociative array {color: 'red', size: 'XL'}
{$idx}intIndex

Integration with msProducts

To output variants in the catalog, use the standard msProducts snippet with the usePackages parameter.

usePackages parameter

fenom
{'msProducts' | snippet : [
    'parents' => 0,
    'usePackages' => 'ms3Variants'
]}

With usePackages => 'ms3Variants' the plugin loads variants for all products in one query and adds data to each product.

Product placeholders with variants

PlaceholderTypeDescription
{$has_variants}boolWhether product has variants
{$variants_count}intNumber of variants
{$variants_json}stringJSON array of variants
{$variants}arrayArray of variants for Fenom

Catalog output example

fenom
{'msProducts' | snippet : [
    'parents' => 0,
    'usePackages' => 'ms3Variants',
    'includeThumbs' => 'small,medium',
    'tpl' => 'ms3_products_row_variants'
]}

Variant structure in array

php
[
    'id' => 1,
    'product_id' => 42,
    'sku' => 'ABC-123-red-XL',
    'price' => 1500.00,
    'old_price' => 2000.00,
    'count' => 10,
    'weight' => 0.5,
    'active' => true,
    'in_stock' => true,
    'image_url' => '/assets/images/products/42/product.jpg',
    'small' => '/assets/images/products/42/small/product.jpg',
    'medium' => '/assets/images/products/42/medium/product.jpg',
    'options_array' => [
        'color' => 'red',
        'size' => 'XL'
    ]
]

With image thumbnails

To load variant thumbnails, pass includeThumbs:

fenom
{'msProducts' | snippet : [
    'parents' => 0,
    'usePackages' => 'ms3Variants',
    'includeThumbs' => 'small,medium'
]}

The variant array will include small, medium, etc. with thumbnail URLs.