Skip to content

ProductSelector

ProductSelector element is a select list with products.

product-selector

Build-in Validators

Element validate if chosen product exists.

Available Validators

Element has available validators:

Relations Support

Element does not support relations between elements.

Configuration output schema

schema
{
  "<element_type>" : "productSelector",
  "<element_name>" : string,
  "<element_label>" : string,
  "<element_labelDescription>" : string,
  "<element_isRequired>" : bool,
  "<element_isHidden>" : bool,
  "<element_defaultValue>" : int,
  "<element_validators>" : []
}
example
{
  "type" : "productSelector",
  "name" : "product",
  "label" : "Displayed product",
  "isRequired" : false,
  "isHidden" : false,
  "defaultValue" : 12,
  "validators": [
    { "type" : "lessEqThan", "options" : { "max" : 25 } }
  ]
}

Element value

If value is filled: int.

usage in module TWIG
{% if moduleConfig.product %}
    Displayed product ID: {{ moduleConfig.product }}
{% endif %}

Example of module

Twig

Twig
{% set productId = moduleConfig.selectedProductId %}
{% if productId %}
    {% set product = ObjectApi.getProduct(productId) %}
    {% if product %}
        <section>
            <div>
                <h2 class="h2">{{ product.name }}</h2>

                {% if moduleConfig.showDescription and product.description %}
                    <p>
                        {{ product.description|raw }}
                    </p>
                {% endif %}

                <div>
                    <a href="{{ product.url }}" class="btn btn_primary">
                        {{ translate("See product") }}
                    </a>
                </div>
            </div>
        </section>
    {% endif %}
{% endif %}

JSON configuration

JSON configuration
[
  {
    "label": "Product",
    "state": "unfolded",
    "elements": [
      {
        "name": "selectedProductId",
        "type": "productSelector",
        "label": "Select Product"
      },
      {
        "name": "showDescription",
        "type": "checkbox",
        "label": "Show product description"
      }
    ]
  }
]

JSON translations

JSON translations
{
  "module": {
    "pl_PL": {
      "See product": "Zobacz produkt"
    },
    "en_US": {
      "See product": "See product"
    }
  },
  "schema": {
    "pl_PL": {
      "Product" : "Produkt",
      "Select Product" : "Wybierz produkt",
      "Show product description" : "Pokaż opis produktu"
    },
    "en_US": {
      "Product" : "Product",
      "Select Product" : "Select Product",
      "Show product description" : "Show product description"
    }
  }
}