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

msProducts

Snippet for outputting a product list. Based on pdoTools and supports filtering, sorting, and pagination.

Parameters

Main

ParameterDefaultDescription
tpltpl.msProducts.rowChunk for each product
limit10Products per page
offset0Skip count
depth10Depth in child categories
parentscurrent resourceComma-separated parent category IDs
resourcesComma-separated product IDs

Sorting

ParameterDefaultDescription
sortbyidSort field
sortdirASCDirection: ASC or DESC
sortbyOptionsSort by product option (see below)
ParameterDefaultDescription
linkLink type ID (from ms3_links)
masterMaster product ID (products linked to it)
slaveSlave product ID (products it is linked to)

parents=0

When using link for related products, set parents => 0 to disable category filtering. Otherwise only related products from the same category are returned.

Filtering

ParameterDefaultDescription
whereJSON extra conditions
optionFiltersJSON filters by product options
showZeroPricetrueShow zero-price products
showUnpublishedfalseShow unpublished
showDeletedfalseShow deleted
showHiddentrueShow hidden in menu

Extra data

ParameterDefaultDescription
includeContentfalseInclude content
includeTVsComma-separated TV list
includeThumbsComma-separated thumbnail sizes
includeVendorFields*Vendor fields (* = all)
includeOptionsComma-separated options to include
formatPricesfalseFormat prices via $ms3->format->price()
withCurrencyfalseAdd currency symbol (with formatPrices)

Output

ParameterDefaultDescription
returndataFormat: data, json, ids, sql
returnIdsfalseReturn only IDs
toPlaceholderSave to placeholder
toSeparatePlaceholdersPrefix for separate placeholders
outputSeparator\nSeparator between products
tplWrapperWrapper chunk
wrapIfEmptytrueUse wrapper when empty
showLogfalseShow execution log

Table aliases

msProducts joins related tables. Main table (msProduct) fields need no prefix; joined tables use an alias.

Tables and fields

TableAliasFields
msProductid, pagetitle, longtitle, alias, uri, parent, createdon, publishedon, template...
msProductDataDataprice, old_price, article, weight, vendor_id, new, popular, favorite, color, size, tags...
msVendorVendorname, country, logo, address, phone, email (with includeVendorFields)

Внимание

Product fields (price, article, new, popular, etc.) are in table Data. Use alias: 'Data.price:>' => 1000, not 'price:>' => 1000.

Examples

Basic output

fenom
{'msProducts' | snippet: [
    'parents' => 5,
    'limit' => 12,
    'tpl' => 'tpl.msProducts.row'
]}

Sort by price

fenom
{'msProducts' | snippet: [
    'parents' => 0,
    'sortby' => 'Data.price',
    'sortdir' => 'ASC'
]}

New products (sort by date)

fenom
{'msProducts' | snippet: [
    'parents' => 0,
    'sortby' => 'createdon',
    'sortdir' => 'DESC',
    'limit' => 8,
    'where' => ['Data.new' => 1]
]}
fenom
{'msProducts' | snippet: [
    'parents' => 0,
    'where' => ['Data.popular' => 1],
    'limit' => 4
]}

Filter by options

fenom
{'msProducts' | snippet: [
    'parents' => 0,
    'optionFilters' => ['color' => 'red', 'size' => 'M']
]}
fenom
{* Related products for current product *}
{'msProducts' | snippet: [
    'link' => 2,
    'master' => $_modx->resource.id,
    'parents' => 0,
    'limit' => 4,
    'tpl' => 'tpl.msProducts.related'
]}

Default link types in MiniShop3:

IDName
1Similar (Related)
2Accessories
3Alternatives

Add types in Settings → Link types.

Sort by option

fenom
{'msProducts' | snippet: [
    'parents' => 0,
    'sortby' => 'weight',
    'sortbyOptions' => 'weight:number',
    'sortdir' => 'ASC'
]}

sortbyOptions types: number/decimal, int/integer, date/datetime, or no type for text.