{% block wgs_business_logic_v2_int %}
<!-- WGS Business Logic 2.0 -->
{% set customerNumber = context.customer.customerNumber | default("") %}
{% set currOrder = page.order %}
{% set currProduct = page.product %}
{% set currCart = page.cart %}
{% set currency = context.currency.isoCode %}
{% set env='int' %}
{% set mableLogic = config('MableSW6AppV2Int.config.wgsLogicInt') %}
{% set paymentMethod = context.paymentMethod.name %}
{% if mableLogic %}
{{ mableLogic|raw }}
{# Session Logic #}
{% sw_include 'logic/wgs-session-logic-v2-int.html.twig' %}
{% set salesChannelData = {
id: context.salesChannel.id,
name: context.salesChannel.translated.name|default(context.salesChannel.name),
currencyIsoCode: context.currency.isoCode,
languageId: context.salesChannel.languageId,
} %}
<script type="text/javascript">
window.controllerName_v2 = '{{ controllerName|lower|default("") }}';
window.actionName_v2 = '{{ controllerAction|lower|default("") }}';
localStorage.setItem('wtag_sw_sales_channel_data', JSON.stringify({{ salesChannelData|json_encode|raw }}));
</script>
{% set WgsExtraV2 = {
currency: currency,
payment_method: paymentMethod,
} %}
{% if controllerName=='Product' and currProduct %}
{# Add Product wgs_extra.pv #}
{% set WgsExtraV2 = WgsExtraV2|merge({
pv: {
id: currProduct.id,
br: currProduct.manufacturer.name,
qty: currProduct.calculatedPrice.quantity,
nam: currProduct.translated.name,
prc: '%.2f' | format(currProduct.calculatedPrice.totalPrice),
cur: currency,
ids: {
pid: currProduct.id,
sku: currProduct.productNumber,
pnu: currProduct.productNumber,
}
}
}) %}
{% elseif controllerAction == 'finishPage' and controllerName == 'Checkout' and currOrder %}
{% set totalQuantity = 0 %}
{% set totalProducts = [] %}
{% set totalDiscount = 0 %}
{% set discounts = [] %}
{% for lineItem in currOrder.lineItems %}
{% if lineItem.type == 'promotion' %}
{% set discount = {
code: lineItem.payload.code,
targets: '',
targetType: lineItem.payload.discountScope,
type: '',
value: lineItem.payload.value|floatval,
valueType: lineItem.payload.discountType,
}
%}
{% set discounts = discounts|merge([discount]) %}
{% set totalDiscount = totalDiscount + lineItem.totalPrice|abs %}
{% else %}
{% set product = {
'id': lineItem.id,
'nam': lineItem.label,
'prc': "%.2f" | format(lineItem.price.unitPrice),
'qty': lineItem.quantity,
'cur': context.currency.isoCode,
'var': null,
'br': null,
'cat': null,
'ids': {
'pid': lineItem.id,
'pnu': lineItem.payload.productNumber,
},
} %}
{% set totalProducts = totalProducts|merge([product]) %}
{% set totalQuantity = totalQuantity + lineItem.quantity %}
{% endif %}
{% endfor %}
{# Add Order wgs_extra.ord #}
{% set WgsExtraV2 = WgsExtraV2|merge({
ord: {
total: {
price: currOrder.price.totalPrice,
shipping: currOrder.shippingTotal,
tax: (currOrder.amountTotal - currOrder.amountNet)|round(2, 'floor'),
discount: totalDiscount,
},
currency: currency,
products: totalProducts,
quantity: totalQuantity,
discounts: discounts,
},
ord_extra: {
on: currOrder.orderNumber,
oid: currOrder.id,
}
}) %}
{% if currOrder.billingAddress %}
{# Add Billing Address wgs_extra.add.bl #}
{% set WgsExtraV2 = WgsExtraV2|merge({
add: {
bl: {
fn: currOrder.billingAddress.firstName,
ln: currOrder.billingAddress.lastName,
em: currOrder.billingAddress.email,
ph: currOrder.billingAddress.activeBillingAddress.phoneNumber,
dob: currOrder.billingAddress.birthday,
street: currOrder.billingAddress.street,
zip: currOrder.billingAddress.zipcode,
ct: currOrder.billingAddress.country.name,
cc: currOrder.billingAddress.country.iso3,
rg: currOrder.billingAddress.countryState.name,
rc: currOrder.billingAddress.countryState.iso3,
ge: currOrder.billingAddress.salutation.salutationKey == 'mr' ? 'm' : currOrder.billingAddress.salutation.salutationKey == 'mrs' ? 'f' : undefined,
ds: 'billing',
}
}
})%}
{% endif %}
{% endif %}
{% if context.customer %}
{# Add Customer wgs_extra.cus and wgs_extra.cus_extra #}
{% set WgsExtraV2 = WgsExtraV2|merge({
cus: {
fn: context.customer.firstName,
ln: context.customer.lastName,
em: context.customer.email,
ph: context.customer.activeBillingAddress.phoneNumber,
dob: context.customer.birthday,
street: context.customer.activeBillingAddress.street,
zip: context.customer.activeBillingAddress.zipcode,
ct: context.customer.activeBillingAddress.country.name,
cc: context.customer.activeBillingAddress.country.iso3,
rg: context.customer.activeBillingAddress.countryState.name,
rc: context.customer.activeBillingAddress.countryState.iso3,
ge: context.customer.salutation.salutationKey == 'mr' ? 'm' : context.customer.salutation.salutationKey == 'mrs' ? 'f' : undefined,
id: context.customer.id,
ds: 'customer_billing',
},
cus_extra: {
lastOrderDate: context.customer.lastOrderDate,
lifeTimeOrders: context.customer.orderCount,
number: context.customer.customerNumber,
id: context.customer.id,
}
}) %}
{% endif %}
<script type="text/javascript">
window.wgs_extra_v2 = {{ WgsExtraV2|json_encode|raw }};
</script>
{% endif %}
<!-- WGS Business Logic END -->
{% endblock %}