{% sw_extends '@Storefront/storefront/page/product-detail/index.html.twig' %}
{% block econda_header_content %}
function getQuantityPrice(quantity) {
{% for element in page.getProduct().getCalculatedPrices().elements %}
if (quantity <= {{ element.getQuantity() }}) {
return '{{ element.getUnitPrice() }}';
}
{% endfor %}
return {{ page.getProduct().getCalculatedPrices().elements|last.getUnitPrice() }}
}
function ecViewFunction(event) {
var allBasketActions = [];
var basketAction = { };
basketAction.type = event;
basketAction.count = '1';
if(event == 'view') {
{% if page.getProduct().getCalculatedPrices().elements is not empty %}
basketAction.price = '{{ page.getProduct().getCalculatedPrices().elements[0].unitPrice }}';
{% else %}
basketAction.price = '{{ page.getProduct().getCalculatedPrice().getUnitPrice() }}';
{% endif %}
}
if(event == 'c_add') {
if (jQuery("select.custom-select.product-detail-quantity-select").val() != 1) {
basketAction.count = jQuery("select.custom-select.product-detail-quantity-select").val();
}
{% if page.getProduct().getCalculatedPrices().elements is not empty %}
basketAction.price = getQuantityPrice(basketAction.count);
{% else %}
basketAction.price = '{{ page.getProduct().getCalculatedPrice().getUnitPrice() }}';
{% endif %}
}
basketAction.pid = '{{ page.extensions['ANA'].get('pid') }}';
basketAction.sku = '{{ page.getProduct().getProductNumber() }}';
basketAction.name = '{{ page.product.translated.name }}';
basketAction.group = '{{ page.extensions['ANA'].get('group') }}';
basketAction.var1 = '{{ page.extensions['ANA'].get('var1') }}';
basketAction.var2 = '{{ page.extensions['ANA'].get('var2') }}';
basketAction.var3 = '{{ page.extensions['ANA'].get('var3') }}';
allBasketActions.push(basketAction);
emospro.ec_Event = allBasketActions;
}
ecViewFunction('view');
{% endblock %}