Skip to content

loyalty_product_price

The loyalty_product_price macro is used to render data about the product price in the lopyalty program context.

Definition

{% loyalty_product_price(product, options) %}

Input parameters

product

product represents an object with parameters regarding product prices:

Option key Type Default Required Description
product.loyaltyPrice string "" no A price in a loyalty program declared in points
product.exchangePrice string "" no An additional fee for exchanging products in the loyalty program
product.priceFormatTax string "" no The tax percentage, eg. 12%
product.priceOutsideLoyaltyProgram string "" no Base price of a product outaide the loyalty program
product.url string "" no Url to the main product page

options

options parameter represents an object with parameters regarding visibility of some price section:

Option key Type Default Required Description
settings.showPriceOutsideLoyaltyProgram boolean false no If set to true the base price of the product outside the loyalty program info will be displayed
settings.showLoyaltyTaxInfo boolean false no If set to true the tax info will be displayed
settings.showPriceWithoutShippingCostInfo boolean false no If set to true the info about shipping costs not being accounted will be displayed

Example

In this example we render a loyalty product price.

{% from "@macros/loyalty_product_price.twig" import loyalty_product_price %}

{{ loyalty_product_price({
   loyaltyPrice: '120 pts',
}) }}

Example

In this example we use a Product object to determine specific loyalty product prices attributes.

{% from "@macros/loyalty_product_price.twig" import loyalty_product_price %}

{% set product = ObjectApi.getProduct(product_id) %}

{{ loyalty_product_price({
    loyaltyPrice: "#{product.variant.loyaltyPointsCost.points} #{translate('pts')}",
    exchangePrice: loyaltyProgramSettings.productsForThePoints.exchangePrice.formatGross,
}) }}

Example

In this example we display product prices with the usage of a Product object and additional options modifying visibility of some elements.

{% from "@macros/loyalty_product_price.twig" import loyalty_product_price %}

{% set product = ObjectApi.getProduct(product_id) %}

{{ loyalty_product_price({
    loyaltyPrice: "#{product.variant.loyaltyPointsCost.points} #{translate('pts')}",
    priceFormatTax: product.price.formatTax,
    exchangePrice: loyaltyProgramSettings.productsForThePoints.exchangePrice.formatGross,
    priceOutsideLoyaltyProgram: product.variant.price.formatGross,
    url: product.url
}, {
    showLoyaltyTaxInfo: true,
    showPriceOutsideLoyaltyProgram: true
}) }}

Macro source code

{% macro loyalty_product_price(product, options) %}
    {% from "@macros/price_product_regular.twig" import price_product_regular %}

    <div class="product-price loyalty-product-price">
        {% if product.loyaltyPrice %}
            <div class="product-price__loyalty-price loyalty-product-price__loyalty-price">
                {{ price_product_regular(product.loyaltyPrice) }}

                {% if product.exchangePrice %} {{ price_product_regular("+ #{product.exchangePrice}") }} {% endif %}
            </div>
        {% endif %}

        {% if options.showPriceOutsideLoyaltyProgram %}
            <div
                class="
                    product-price__price-outside-loyalty-program
                    loyalty-product-price__price-outside-loyalty-program
                "
            >
                <div class="price price_s">
                    <span class="price__label">
                        {{ translate('Product price outside the loyalty program') }}{% if not options.showLoyaltyTaxInfo %}:{% endif %}

                        {% if options.showLoyaltyTaxInfo %}
                            <span class="p_xs">
                                {{ translate(
                                    'with %s VAT',
                                    "<span class='js__price-vat-value'>#{product.priceFormatTax}</span>"
                                ) }}:
                            </span>
                        {% endif %}
                    </span>

                    <span class="price__value js__price-outside-loyalty-program">
                        {{ product.priceOutsideLoyaltyProgram }}
                    </span>
                </div>

                <a class="link p_s product-price__price-outside-loyalty-program-link" href="{{ product.url }}">
                    {{ translate('Go to product') }}
                </a>
            </div>
        {% endif %}

        {% if options.showPriceWithoutShippingCostInfo %}
            <p
                class="
                    p_no-margin
                    p_s
                    product-price__shipping-cost-info
                    loyalty-product-price__shipping-cost-info
                "
            >
                {{ translate('Shipping costs are not included in the price.') }}
            </p>
        {% endif %}
    </div>
{% endmacro %}