custom/apps/MableSW6AppV2Int/Resources/views/storefront/layout/header/actions/cart-widget.html.twig line 1

Open in your IDE?
  1. {% sw_extends '@Storefront/storefront/layout/header/actions/cart-widget.html.twig' %}
  2. {% block layout_header_actions_cart_widget %}
  3. {{ parent() }}
  4. {% if page.cart %}
  5.     {% set totalCount = 0 %}
  6.     {% set products = [] %}
  7.     {% set discounts = [] %}
  8.     {% set totalDiscount = 0 %}
  9.     {% for lineItem in page.cart.lineItems.elements %}
  10.         {% if lineItem.type == 'promotion' %}
  11.             {% set discount = {
  12.                 code: lineItem.payload.code,
  13.                 targets: '',
  14.                 targetType: lineItem.payload.discountScope,
  15.                 type: '',
  16.                 value: lineItem.payload.value|floatval,
  17.                 valueType: lineItem.payload.discountType,
  18.             }
  19.             %}
  20.             {% set discounts = discounts|merge([discount]) %}
  21.             {% set totalDiscount = totalDiscount + lineItem.price.totalPrice|abs %}
  22.         {% else %}
  23.             {% set product = {
  24.                     'id': lineItem.id,
  25.                     'nam': lineItem.label,
  26.                     'prc': '%.2f' | format(lineItem.price.unitPrice),
  27.                     'qty': lineItem.quantity,
  28.                     'cur': context.currency.isoCode,
  29.                     'var': null,
  30.                     'br': null,
  31.                     'cat': null,
  32.                     'ids': {
  33.                         'pid': lineItem.id,
  34.                         'pnu': lineItem.payload.productNumber,
  35.                     },
  36.             } %}
  37.             
  38.             {% set products = products|merge([product]) %}
  39.             {% set totalCount = totalCount + lineItem.quantity %}
  40.         {% endif %}
  41.     {% endfor %}
  42.     {%
  43.         set cartData = {
  44.             'quantity': totalCount,
  45.             'currency': context.currency.isoCode,
  46.             'total': {
  47.                 'price': page.cart.price.totalPrice,
  48.                 'tax': page.cart.price.calculatedTaxes.elements[0].tax,
  49.                 'discount': totalDiscount,
  50.                 'shipping': null,
  51.             },
  52.             'products': products,
  53.             'discounts': discounts
  54.         } 
  55.     %}
  56.     <data id="mable_cart_data" data-cart='{{cartData|json_encode()|raw}}' style="display:none;"></data>
  57. {% endif %}
  58. {% endblock %}