Loyalty Product Prices¶
loyalty_product_prices
module is used to display prices for a given product. This module is only available in a loyalty program context.
Configuration parameters¶
showPriceOutsideLoyaltyProgram¶
boolean
if set to true
a price of a given product outside the loyalty program will be displayed.
Module source code¶
{% from "@macros/loyalty_product_price.twig" import loyalty_product_price %}
{% set globalPricesSettings = ObjectApi.getProductPricesSettings() %}
{% set loyaltyProgramSettings = ObjectApi.getLoyaltyProgramSettings() %}
{% set shopUrls = ObjectApi.getShopUrls() %}
{% set product = ObjectApi.getProduct(product_id) %}
{% if product.variants.count == 1 %}
{% set product = product.variants[0] %}
{% endif %}
{% set price = product.price %}
{% set shouldShowNetPrice = globalPricesSettings.showNetPrice and not globalPricesSettings.showGrossPrice %}
{% set showLoyaltyTaxInfo = globalPricesSettings.showNetPrice and globalPricesSettings.showGrossPrice %}
{% if loyaltyProgramSettings.productsForThePoints %}
{% set exchangePrice = loyaltyProgramSettings.productsForThePoints.exchangePrice %}
{% endif %}
{% if product.hasUnitPriceCalculation and globalPricesSettings.showUnitPrice %}
{% set unitPrice = product.hasSpecialOffer ? product.specialOfferUnitPrice : product.unitPrice %}
{% endif %}
{% set showDifferentCurrency = product.hasDifferentCurrency and product.currency.id != currency_id %}
{% set prices %}
<loyalty-product-price
class="product-prices"
product-id="{{ product.id }}"
slot="logged-in">
{% if shouldShowNetPrice %}
<span
name="price-net-{{ moduleInstance }}"
class="js__product-price-net"
>
<span class="js__product-price" name="shop-current-currency-{{ moduleInstance }}">
{{ loyalty_product_price({
loyaltyPrice: "#{product.variant.loyaltyPointsCost.points} #{translate('pts')}",
exchangePrice: exchangePrice.formatNet,
priceOutsideLoyaltyProgram: product.variant.price.formatNet,
url: product.url
}, {
showPriceWithoutShippingCostInfo: globalPricesSettings.showAdditionalTaxInfo,
showPriceOutsideLoyaltyProgram: moduleConfig.showPriceOutsideLoyaltyProgram
}) }}
</span>
</span>
{% else %}
<span
name="price-gross-{{ moduleInstance }}"
class="js__product-price-gross"
>
<span class="js__product-price" name="shop-current-currency-{{ moduleInstance }}">
{{ loyalty_product_price({
loyaltyPrice: "#{product.variant.loyaltyPointsCost.points} #{translate('pts')}",
priceFormatTax: price.formatTax,
exchangePrice: exchangePrice.grossValue > 0 ? exchangePrice.formatGross : '',
priceOutsideLoyaltyProgram: product.variant.price.formatGross,
url: product.url
}, {
showLoyaltyTaxInfo,
showPriceWithoutShippingCostInfo: globalPricesSettings.showAdditionalTaxInfo,
showPriceOutsideLoyaltyProgram: moduleConfig.showPriceOutsideLoyaltyProgram
}) }}
</span>
</span>
{% endif %}
</loyalty-product-price>
{% if globalPricesSettings.showPricesToUnregistered %}
{% set priceSpecifications = [] %}
{% set specialOfferStartDate = product.hasSpecialOffer ? specialOffer.getDetails().startDate.dateShort : null %}
{% set specialOfferEndDate = product.hasSpecialOffer ? specialOffer.getDetails().endDate.dateShort : null %}
{% if globalPricesSettings.showGrossPrice %}
{% set priceSpecifications = priceSpecifications|merge([
{
"@type": "PriceSpecification",
"price": price.grossValue,
"priceCurrency": price.currency,
"valueAddedTaxIncluded": true,
"validFrom": specialOfferStartDate,
"validThrough": specialOfferEndDate
}
]) %}
{% if unitPrice %}
{% set priceSpecifications = priceSpecifications|merge([
{
"@type": "UnitPriceSpecification",
"price": unitPrice.grossValue,
"priceCurrency": unitPrice.currency.code,
"unitText": product.unitPriceCalculationUnit.name,
"valueAddedTaxIncluded": true,
"validFrom": specialOfferStartDate,
"validThrough": specialOfferEndDate
}
]) %}
{% endif %}
{% if showDifferentCurrency %}
{% set priceSpecifications = priceSpecifications|merge([
{
"@type": "PriceSpecification",
"price": priceInCurrency.netValue,
"priceCurrency": product.currency.code,
"valueAddedTaxIncluded": false,
"validFrom": specialOfferStartDate,
"validThrough": specialOfferEndDate
}
]) %}
{% endif %}
{% endif %}
{% if globalPricesSettings.showNetPrice %}
{% set priceSpecifications = priceSpecifications|merge([
{
"@type": "PriceSpecification",
"price": price.netValue,
"priceCurrency": price.currency,
"valueAddedTaxIncluded": false,
"validFrom": specialOfferStartDate,
"validThrough": specialOfferEndDate
}
]) %}
{% if unitPrice %}
{% set priceSpecifications = priceSpecifications|merge([
{
"@type": "UnitPriceSpecification",
"price": unitPrice.netValue,
"priceCurrency": unitPrice.currency.code,
"unitText": product.unitPriceCalculationUnit.name,
"valueAddedTaxIncluded": false,
"validFrom": specialOfferStartDate,
"validThrough": specialOfferEndDate
}
]) %}
{% endif %}
{% if showDifferentCurrency %}
{% set priceSpecifications = priceSpecifications|merge([
{
"@type": "PriceSpecification",
"price": priceInCurrency.netValue,
"priceCurrency": product.currency.code,
"valueAddedTaxIncluded": false,
"validFrom": specialOfferStartDate,
"validThrough": specialOfferEndDate
}
]) %}
{% endif %}
{% endif %}
{% set productPricesJsonLd = {
"@context": [
"http://schema.org/",
{
"@base": "#{shopUrls.mainPageUrl.absolute}"
}
],
"@id": "#{product.url.relative}",
"offers": {
"@id": "#{product.url.relative}",
"@type": "Offer",
"priceValidUntil": specialOfferEndDate,
"PriceSpecification": priceSpecifications
}
}%}
<script type="application/ld+json">
{{ productPricesJsonLd | json_encode | raw }}
</script>
{% endif %}
{% endset %}
{% if globalPricesSettings.showPricesToUnregistered %}
{{ prices }}
{% else %}
<auth-controller>
{{ prices }}
</auth-controller>
{% endif %}
Macros reference¶
Webcomponents reference¶
Used Object Api methods¶
Used styles¶
Module configuration schema¶
[
{
"state": "unfolded",
"label": "General settings",
"elements": [
{
"type": "infobox",
"name": "infobox",
"options": {
"type": "blank",
"message": "%s Related settings in the admin panel%s- changing phrases in [translations](%s)%s- enable product redemption fee in [loyalty program settings - redemption of points](%s)",
"placeholderValues": [
"####",
"\n",
"\/admin\/configLanguages\/list",
"\n",
"\/admin\/configLoyalty"
]
}
},
{
"type": "checkbox",
"name": "showPriceOutsideLoyaltyProgram",
"label": "Display \"Price outside of the loyalty program\"",
"defaultValue": 1
}
]
}
]