
ms3ProductSets
Dynamic product sets for MiniShop3


{'mspsLexiconScript' | snippet}
<link rel="stylesheet" href="{'assets_url' | option}components/ms3productsets/css/productsets.css">
<script src="{'assets_url' | option}components/ms3productsets/js/productsets.js"></script>[[!mspsLexiconScript]]
<link rel="stylesheet" href="[[++assets_url]]components/ms3productsets/css/productsets.css">
<script src="[[++assets_url]]components/ms3productsets/js/productsets.js"></script>{set $msps_buy_together = 'ms3ProductSets' | snippet : [
'type' => 'buy_together',
'resource_id' => $_modx->resource.id,
'max_items' => 6,
'tpl' => 'tplSetItem'
]}
{if $msps_buy_together}
<section class="product-set">
<h2>Frequently bought together</h2>
{$msps_buy_together}
</section>
{/if}[[!ms3ProductSets?
&type=`buy_together`
&resource_id=`[[*id]]`
&max_items=`6`
&tpl=`tplSetItem`
&toPlaceholder=`msps_buy_together`
]]
[[+msps_buy_together:notempty=`
<section class="product-set">
<h2>Frequently bought together</h2>
[[+msps_buy_together]]
</section>
`]]{'ms3ProductSets' | snippet : [
'type' => 'auto',
'category_id' => 5,
'resource_id' => 0,
'max_items' => 8,
'tpl' => 'tplSetItem'
]}[[!ms3ProductSets?
&type=`auto`
&category_id=`5`
&resource_id=`0`
&max_items=`8`
&tpl=`tplSetItem`
]]ms3productsets.vip_set_1.{'ms3ProductSets' | snippet : [
'type' => 'vip',
'set_id' => 1,
'max_items' => 6,
'tpl' => 'tplSetVIP'
]}[[!ms3ProductSets?
&type=`vip`
&set_id=`1`
&max_items=`6`
&tpl=`tplSetVIP`
]]By default the block is hidden when the set is empty.
{'ms3ProductSets' | snippet : [
'type' => 'similar',
'resource_id' => $_modx->resource.id,
'hideIfEmpty' => 0,
'emptyTpl' => 'tplSetEmpty'
]}[[!ms3ProductSets?
&type=`similar`
&resource_id=`[[*id]]`
&hideIfEmpty=`0`
&emptyTpl=`tplSetEmpty`
]]<div id="msps-auto"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
if (window.ms3ProductSets) {
window.ms3ProductSets.render('#msps-auto', {
type: 'auto',
category_id: 5,
max_items: 8,
tpl: 'tplSetItem'
});
}
});
</script><button type="button" data-add-to-cart="{$id}" data-count="1">Add to cart</button><button type="button" data-add-to-cart="[[+id]]" data-count="1">Add to cart</button>productsets.js sends the request to connector.php.
Button with data-add-set adds all set products to cart. Used in chunks tplSetVIP and tplSetWrapper (when count > 0). Set container must have elements with data-product-id (cards from tplSetItem). JS finds container from the button (.msps__vip-set, .msps__wrapper or [data-set-type]) and calls addToCart for each product in sequence.
<button type="button" class="msps__add-all-button" data-add-set="1">
{$_modx->lexicon('msproductsets_add_all_to_cart')}
</button><button type="button" class="msps__add-all-button" data-add-set="1">
[[%msproductsets_add_all_to_cart]]
</button>mspsLexiconScript, productsets.css, productsets.js.ms3ProductSets is called with valid resource_id or category_id.vip, vip_set_1 or manual links in table are set.