Skip to content
  1. Extras
  2. msAddLinked

msAddLinked

Description

Add related products as extra options with an increase in the added product's price. In any add-to-cart form you can show extra products that are added as options and increase the price. In the cart and in emails, added options are shown next to the product.

Important

The related list only shows products for which the current product (or the product passed to msAddLinked.input) is the main product in the relation.

Snippet msAddLinked.input

Outputs the list of related products and input fields. By default checkboxes are used; in theory any input type is possible. Types text and number are tested: entering a number there adds that quantity of options to the product in the cart.

msAddLinked.input parameters

NameDefaultDescription
&tpltpl.msAddLinked.inputChunk for output
&product0 (current product)ID of the main product
&link0 (all relations)Relation ID
&inputTypecheckboxInput type for each related product
&priceTarget#priceHTML selector for the updated price
&priceOrigTarget#msal_price_originalHTML selector for the original price
&fieldNamepagetitleResource field for the displayed name
&toPlaceholder0If set, result is saved to this placeholder instead of output

Snippet msAddLinked.info

Outputs the list of options added to the product in the cart and in emails.

msAddLinked.info parameters

NameDefaultDescription
&tpltpl.msAddLinked.inputChunk for output
&option{}Option value (linked products) as JSON
&fieldNamepagetitleResource field for the displayed name

Example call:

modx
[[!msAddLinked.info? &option=`[[+option.msal]]`]]

In Fenom:

fenom
{$_modx->runSnippet('msAddLinked.info', ['option' => $product.options.msal])}

If the cart shows other product options, replace this block:

fenom
{foreach $product.options as $option}
  {var $options = $options ~ $option ~ '; '}
{/foreach}

with:

fenom
{foreach $product.options as $k => $option}
  {if $k != 'msal'}
    {var $options = $options ~ $option ~ '; '}
  {/if}
{/foreach}

Standard options are shown like this:

fenom
<div class="small">
  {$product.options | join : '; '}
</div>

To avoid raw JSON in output, wrap like this:

fenom
{if $product.options.msal?}
  {var $msal = $product.options.msal}
  {unset $product.options.msal}
{/if}
<div class="small">
  {$product.options | join : '; '}
</div>
{if $msal?}
  {$_modx->runSnippet('msAddLinked.info', ['option' => $msal])}
  {unset $msal}
{/if}

System settings

NameDefaultDescription
&msal_frontend_js[[+jsUrl]]web/default.jsPath to JS file
&msal_variablemsalOption variable name