Skip to content
  1. Extras
  2. ms3OptionsColor
  3. Storefront
  4. mFilter

mFilter ​

The package adds filter type ms3oc. Shoppers see color squares from the dictionary, not a plain value list. The package does not change the built-in mFilter type colors.

You need mFilter installed. Without it, OnMFilterInit never runs and type ms3oc will not appear.

Filter Set setup ​

  1. Create a Filter Set in mFilter and attach it to the catalog page.
  2. Add an option filter in the set JSON:
json
{
  "color": {
    "type": "ms3oc",
    "source": "option",
    "field": "color",
    "label": "Цвет",
    "tpl": "tplMFilterMs3OptionsColor",
    "multiple": true
  }
}
FieldPurpose
typeAlways ms3oc for dictionary swatches
sourceUsually option
fieldOption values and dictionary option_key. If field is empty, the Filter Set key is used
object keyMust match mFilterForm filters. Does not drive the dictionary when field is set
labelBlock label on the storefront
tplRow chunk: stock tplMFilterMs3OptionsColor or your own
multipleSeveral values at once

Dictionary option_key is field, otherwise the Filter Set key. Example: key color_swatch with "field": "color" looks up swatches by color (#1).

Call on the page ​

Run the results snippet (mFilter / baseIds) first, then the form:

fenom
{'!mFilterForm' | snippet : [
  'filters' => 'color',
  'tplItem' => 'tplMFilterMs3OptionsColor'
]}
modx
[[!mFilterForm?
  &filters=`color`
  &tplItem=`tplMFilterMs3OptionsColor`
]]

mFilter / mFilterForm parameters depend on your build. See mFilter snippets. ms3OptionsColor needs:

  • Filter Set with "type": "ms3oc"
  • filters matching the JSON key
  • mFilterForm passing hex / pattern / ral on each item (or flat $hex, $pattern, $ral)
  • &tplItem=tplMFilterMs3OptionsColor when your mFilter build needs it.

ms3oc filter

Chunk tplMFilterMs3OptionsColor ​

Two data shapes for the chunk:

SourceFields
demo / manual call$item.value, $item.label, $item.hex, $item.pattern, $item.ral, $item.count, $item.selected
mFilterFormflat $value, $label, $hex, $pattern, $ral, $count, $active

Minimal custom row (Fenom). Attributes data-ms3oc-filter-label and data-ms3oc-filter-count are hooks for package CSS (label and count).

fenom
<label data-ms3oc-filter{if $active?} data-selected{/if}>
  <input type="checkbox" name="{$key}[]" value="{$value | escape}" {if $active?}checked{/if}>
  <span data-ms3oc-swatch data-size="sm"
        {if !$hex && !$pattern}data-empty{/if}
        style="{if $hex}background-color:{$hex};{/if}{if $pattern}background-image:url('{$pattern}');{/if}"></span>
  <span data-ms3oc-filter-label>{$label ?: $value}</span>
  <span data-ms3oc-filter-count>{$count}</span>
</label>

Storefront CSS (ms3optionscolor_frontend_css) must be on. Otherwise the filter swatch often has no size.

Common issues ​

SymptomCheck
Text only, no swatchesFilter Set uses colors instead of ms3oc
Type ms3oc missingmFilter installed, cache cleared, plugin on OnMFilterInit
Value missing from the filterDictionary row has no HEX and no pattern. ms3oc skips it
Empty squaresCSS not loaded (frontend_css) or your chunk outputs an empty hex
No stylesms3optionscolor_frontend_css or a manual <link> to css/web/main.css

Screenshot flow: Flow G. General storefront: Frontend.