custom/apps/MableSW6AppV2Int/Resources/views/logic/wgs-business-logic-int.html.twig line 1

Open in your IDE?
  1. {% block wgs_business_logic_v2_int %}
  2.     <!-- WGS Business Logic 2.0 -->
  3.     {% set customerNumber = context.customer.customerNumber | default("") %}
  4.     {% set currOrder = page.order %}
  5.     {% set currProduct = page.product %}
  6.     {% set currCart = page.cart %}
  7.     {% set currency = context.currency.isoCode %}
  8.     {% set env='int' %}
  9.     {% set mableLogic = config('MableSW6AppV2Int.config.wgsLogicInt') %}
  10.     {% set paymentMethod = context.paymentMethod.name %}
  11.     {% if mableLogic %}
  12.         {{ mableLogic|raw }}
  13.         {# Session Logic #}
  14.         {% sw_include 'logic/wgs-session-logic-v2-int.html.twig' %}
  15.         {% set salesChannelData = {
  16.             id: context.salesChannel.id,
  17.             name: context.salesChannel.translated.name|default(context.salesChannel.name),
  18.             currencyIsoCode: context.currency.isoCode,
  19.             languageId: context.salesChannel.languageId,
  20.         } %}
  21.         <script type="text/javascript">
  22.             window.controllerName_v2 = '{{ controllerName|lower|default("") }}';
  23.             window.actionName_v2 = '{{ controllerAction|lower|default("") }}';
  24.             localStorage.setItem('wtag_sw_sales_channel_data', JSON.stringify({{ salesChannelData|json_encode|raw }}));
  25.         </script>
  26.         {% set WgsExtraV2 = {
  27.             currency: currency,
  28.             payment_method: paymentMethod,
  29.         } %}
  30.         {% if controllerName=='Product' and currProduct %}
  31.             {# Add Product wgs_extra.pv #}
  32.             {% set WgsExtraV2 = WgsExtraV2|merge({
  33.                 pv: {
  34.                     id: currProduct.id,
  35.                     br: currProduct.manufacturer.name,
  36.                     qty: currProduct.calculatedPrice.quantity,
  37.                     nam: currProduct.translated.name,
  38.                     prc: '%.2f' | format(currProduct.calculatedPrice.totalPrice),
  39.                     cur: currency,
  40.                     ids: {
  41.                         pid: currProduct.id,
  42.                         sku: currProduct.productNumber,
  43.                         pnu: currProduct.productNumber,
  44.                     }
  45.                 }
  46.             }) %}
  47.         {% elseif controllerAction == 'finishPage' and controllerName == 'Checkout' and currOrder %}
  48.             {% set totalQuantity = 0 %}
  49.             {% set totalProducts = [] %}
  50.             {% set totalDiscount = 0 %}
  51.             {% set discounts = [] %}
  52.             {% for lineItem in currOrder.lineItems %}
  53.                 {% if lineItem.type == 'promotion' %}
  54.                     {% set discount = {
  55.                         code: lineItem.payload.code,
  56.                         targets: '',
  57.                         targetType: lineItem.payload.discountScope,
  58.                         type: '',
  59.                         value: lineItem.payload.value|floatval,
  60.                         valueType: lineItem.payload.discountType,
  61.                     }
  62.                     %}
  63.                     {% set discounts = discounts|merge([discount]) %}
  64.                     {% set totalDiscount = totalDiscount + lineItem.totalPrice|abs %}
  65.                 {% else %}
  66.                     {% set product = {
  67.                             'id': lineItem.id,
  68.                             'nam': lineItem.label,
  69.                             'prc': "%.2f" | format(lineItem.price.unitPrice),
  70.                             'qty': lineItem.quantity,
  71.                             'cur': context.currency.isoCode,
  72.                             'var': null,
  73.                             'br': null,
  74.                             'cat': null,
  75.                             'ids': {
  76.                                 'pid': lineItem.id,
  77.                                 'pnu': lineItem.payload.productNumber,
  78.                             },
  79.                     } %}
  80.                     
  81.                     {% set totalProducts = totalProducts|merge([product]) %}
  82.                     {% set totalQuantity = totalQuantity + lineItem.quantity %}
  83.                 {% endif %}
  84.             {% endfor %}
  85.             {# Add Order wgs_extra.ord #}
  86.             {% set WgsExtraV2 = WgsExtraV2|merge({
  87.                 ord: {
  88.                     total: {
  89.                         price: currOrder.price.totalPrice,
  90.                         shipping: currOrder.shippingTotal,
  91.                         tax: (currOrder.amountTotal - currOrder.amountNet)|round(2, 'floor'),
  92.                         discount: totalDiscount,
  93.                     },
  94.                     currency: currency,
  95.                     products: totalProducts,
  96.                     quantity: totalQuantity,
  97.                     discounts: discounts,
  98.                 },
  99.                 ord_extra: {
  100.                     on: currOrder.orderNumber,
  101.                     oid: currOrder.id,
  102.                 }
  103.             }) %}
  104.             {% if currOrder.billingAddress %}
  105.                 {# Add Billing Address wgs_extra.add.bl #}
  106.                 {% set WgsExtraV2 = WgsExtraV2|merge({
  107.                     add: {
  108.                         bl: {
  109.                             fn: currOrder.billingAddress.firstName,
  110.                             ln: currOrder.billingAddress.lastName,
  111.                             em: currOrder.billingAddress.email,
  112.                             ph: currOrder.billingAddress.activeBillingAddress.phoneNumber,
  113.                             dob: currOrder.billingAddress.birthday,
  114.                             street: currOrder.billingAddress.street,
  115.                             zip: currOrder.billingAddress.zipcode,
  116.                             ct: currOrder.billingAddress.country.name,
  117.                             cc: currOrder.billingAddress.country.iso3,
  118.                             rg: currOrder.billingAddress.countryState.name,
  119.                             rc: currOrder.billingAddress.countryState.iso3,
  120.                             ge: currOrder.billingAddress.salutation.salutationKey == 'mr' ? 'm' : currOrder.billingAddress.salutation.salutationKey == 'mrs' ? 'f' : undefined,
  121.                             ds: 'billing',
  122.                         }
  123.                     }
  124.                 })%}
  125.             {% endif %}
  126.         {% endif %}
  127.         {% if context.customer %}
  128.             {# Add Customer wgs_extra.cus and wgs_extra.cus_extra #}
  129.             {% set WgsExtraV2 = WgsExtraV2|merge({
  130.                 cus: {
  131.                     fn: context.customer.firstName,
  132.                     ln: context.customer.lastName,
  133.                     em: context.customer.email,
  134.                     ph: context.customer.activeBillingAddress.phoneNumber,
  135.                     dob: context.customer.birthday,
  136.                     street: context.customer.activeBillingAddress.street,
  137.                     zip: context.customer.activeBillingAddress.zipcode,
  138.                     ct: context.customer.activeBillingAddress.country.name,
  139.                     cc: context.customer.activeBillingAddress.country.iso3,
  140.                     rg: context.customer.activeBillingAddress.countryState.name,
  141.                     rc: context.customer.activeBillingAddress.countryState.iso3,
  142.                     ge: context.customer.salutation.salutationKey == 'mr' ? 'm' : context.customer.salutation.salutationKey == 'mrs' ? 'f' : undefined,
  143.                     id: context.customer.id,
  144.                     ds: 'customer_billing',
  145.                 },
  146.                 cus_extra: {
  147.                     lastOrderDate: context.customer.lastOrderDate,
  148.                     lifeTimeOrders: context.customer.orderCount,
  149.                     number: context.customer.customerNumber,
  150.                     id: context.customer.id,
  151.                 }
  152.             }) %}
  153.         {% endif %}
  154.         <script type="text/javascript">
  155.             window.wgs_extra_v2 = {{ WgsExtraV2|json_encode|raw }};
  156.         </script>
  157.     {% endif %}
  158.     <!-- WGS Business Logic END -->
  159. {% endblock %}