Skip to content

Loyalty Program

The loyalty-program module is used to display information about the loyalty program for a given product.

Configuration parameters

displayPointsRequired

int If set to 1, the number of points required to purchase a product within the loyalty program will be displayed.

displayPointsEarned

int If set to 1, the number of points earned from purchasing a product within the loyalty program will be displayed.

Module source code

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

{% set globalPricesSettings = ObjectApi.getProductPricesSettings() %}
{% set loyaltyProgramSettings = ObjectApi.getLoyaltyProgramSettings() %}

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

{% set shouldDisplayLoyaltyProgramAvailabilityInfo =
    moduleConfig.displayPointsRequired and 
    loyaltyProgramSettings.productsForThePoints and 
    product.isUsedInLoyaltyProgram %}

{% set shouldDisplayLoyaltyProgramPointsEarnedInfo =
    moduleConfig.displayPointsEarned and 
    loyaltyProgramSettings.ordersMode %}

{% set loyaltyProgramModalName = 'loyalty-program-modal-' ~ moduleInstance %}

{% if loyaltyProgramSettings.isActive %}
    <div class="loyalty-program">
        <loyalty-program-points 
            class='loyalty-program-points'>
            {% if shouldDisplayLoyaltyProgramAvailabilityInfo %}
                <auth-controller hidden>
                    <div class="loyalty-program__points-required" slot="logged-in">
                        {{ translate('The product is available within the loyalty program for')}}
                        <span class="js__points-required loyalty-program__points">
                            {{ product.variant.loyaltyPointsCost.points }} {{ translate('pts') }}</span>.
                        <a href="{{ product.loyaltyUrl }}" class="link_no-underline">
                            {{ translate('Go to the offer') }}
                        </a>
                    </div>
                </auth-controller>
            {% endif %}

            {% if shouldDisplayLoyaltyProgramPointsEarnedInfo %}
                <div class="loyalty-program__points-earned">
                    {{ translate('By purchasing the product, you will receive') }}
                    <span class="js__points-earned loyalty-program__points">
                        {{ product.variant.loyaltyPointsEarnedForBuy.points }} {{ translate('pts') }}</span>.
                </div>
            {% endif %}

            <div class="loyalty-program__info">
                {{ translate('Find out') }}
                <h-modal-opener
                    name="{{loyaltyProgramModalName}}" 
                    class="loyalty-program__modal-opener link link_no-underline"
                >
                    {{ translate('more about the loyalty program')}}.
                </h-modal-opener>
            </div>
        </loyalty-program-points>
    </div>

    {{
        loyalty_program_modal({
            modalName: loyaltyProgramModalName
        })
    }}
{% endif %}

Used ObjectApi methods

Used macros

Used webcomponents

Used styles

Module configuration schema

[
    {
        "label": "General settings",
        "state": "unfolded",
        "elements": [
            {
                "name": "infobox",
                "type": "infobox",
                "options": {
                    "type": "blank",
                    "message": "#### Related settings in the admin panel%s- changing phrases in [translations](%s) %s- enabling [the loyalty program](%s) %s- conditions for earning and redeeming points in [the loyalty program settings](%s)",
                    "placeholderValues": ["\n", "\/admin\/configLanguages\/list", "\n", "\/admin\/configLoyalty", "\n", "\/admin\/configLoyalty"]
                }
            },
            {
                "name": "pointsDisplaySettings",
                "type": "header",
                "label": "Display the number of points:",
                "children": [
                    {
                        "name": "displayPointsRequired",
                        "type": "checkbox",
                        "hint": "Only logged-in customers will see information about the possibility of redeeming loyalty points for a product.",
                        "label": "required to receive a product",
                        "defaultValue": 1
                    },
                    {
                        "name": "displayPointsEarned",
                        "type": "checkbox",
                        "label": "earned per product purchase",
                        "defaultValue": 1
                    }
                ]
            }
        ]
    }
]