Skip to content
  1. Extras
  2. miniShop2
  3. Snippets
  4. msProducts

msProducts ​

Snippet for outputting products.

msProducts

Parameters ​

ParameterDefaultDescription
tpltpl.msProducts.rowChunk per result
limit10Max results
offset0Skip first N results
depth10Search depth from each parent
sortbyidSort field. For product fields use prefix "Data.", e.g. &sortby=`Data.price`
sortbyOptionsOptions to sort by, e.g. optionkey:integer,optionkey2:datetime. Available types: string (default), integer (int), number (decimal), date, datetime
sortdirASCSort direction
toPlaceholderIf set, save output to a placeholder instead of outputting.
toSeparatePlaceholdersIf set, each result goes to a placeholder named by this prefix + index (e.g. "myPl" → [[+myPl0]], [[+myPl1]]).
parentsComma-separated category ids. Default: current parent. Use 0 for no limit.
resourcesComma-separated product ids. Minus prefix excludes that id.
includeContentfalseInclude product "content" field.
includeTVsComma-separated TV list.
includeThumbsComma-separated thumbnail sizes (must exist in product gallery).
optionFiltersOption filters as JSON, e.g. {"optionkey:>":10}
whereExtra conditions as JSON.
linkProduct link id (from settings).
masterMain product id. If both master and slave are set, query uses master.
slaveLinked product id. Ignored if master is set.
tvPrefixPrefix for TV placeholders, e.g. "tv."
outputSeparator\nString between results.
returndataOutput format. Values: data — rendered chunks, ids — product id string, json — JSON data
returnIdsfalseReturn comma-separated product ids instead of chunk output.
showUnpublishedfalseInclude unpublished products.
showDeletedfalseInclude deleted products.
showHidden1Include products hidden from menu.
showZeroPrice1Include zero-price products.
wrapIfEmpty1Output wrapper chunk (tplWrapper) even when there are no results.
showLogfalseShow debug info. Only for users authorized in context "mgr".

Подсказка

You can also use other general pdoTools parameters.

Features ​

msProducts, like all miniShop2 snippets, uses pdoTools. Main parameters match pdoResources, with additions.

Multi-category support ​

An MS2 product has one physical parent but can belong to several categories. msProducts respects that.

Multi-category support

Images ​

Use &includeThumbs to load images from the product gallery. Comma-separated sizes:

modx
[[!msProducts?
  &parents=`0`
  &includeThumbs=`120x90,360x270`
]]

Placeholders [[+120x90]] and [[+360x270]] will be available in the chunk.

Use &link with &master or &slave to get related products:

modx
[[!msProducts?
  &parents=`0`
  &link=`1`
  &master=`15`
]]

This returns all products linked to product 15 via link type 1.

Options ​

msProducts adds all product options as placeholders [[+option_key]].

&optionFilters adds conditions to filter by options:

modx
[[!msProducts?
  &parents=`0`
  &optionFilters=`{"core_count:>":4}`
]]

This outputs products that have option core_count greater than 4.

For sorting by options use &sortbyOptions (option keys and types, comma-separated) and &sortby:

modx
&sortbyOptions=`core_count:number`
&sortby=`{"pagetitle":"ASC", "core_count":"DESC"}`

Aliases ​

msProducts joins related tables so you can use their data without extra queries:

  • msProduct — main class (extends modResource)
  • Data — msProductData: price, article, and other product fields
  • Vendor — msVendor: name, country, logo, etc.

Placeholders ​

To see all placeholders, omit the output chunk:

modx
<pre>
  [[!msProducts?
    &parents=`0`
    &tpl=``
  ]]
</pre>

Filter examples ​

Products with sale price:

modx
&where=`{"Data.old_price:!=":"0"}`

Products marked New:

modx
&where=`{"Data.new":"1"}`

Products marked Popular:

modx
&where=`{"Data.popular":"1"}`

Products marked Favorite:

modx
&where=`{"Data.favorite":"1"}`

Examples ​

All products from category 15:

modx
[[!msProducts?
  &parents=`15`
]]

With pagination:

modx
[[!pdoPage?
  &element=`msProducts`
  &parents=`15`
]]
[[!+page.nav]]

All products with price > 1000:

modx
[[!pdoPage?
  &element=`msProducts`
  &parents=`0`
  &where=`{"Data.price:>":1000}`
]]
[[!+page.nav]]

Products by vendor Sony:

modx
[[!pdoPage?
  &element=`msProducts`
  &parents=`0`
  &where=`{"Vendor.name":"Sony"}`
]]
[[!+page.nav]]

Sort by article:

modx
[[!pdoPage?
  &element=`msProducts`
  &parents=`0`
  &sortby=`Data.article`
  &sortdir=`asc`
]]
[[!+page.nav]]