Custom Code
Custom Code
- Include PDP functionality
- In: /app_storefront_core/cartridge/js/pages/product/variant.js
- Where: function updateContent(), at the end of the $.ajax() callback function
Code:
if (window.EXT_GLOBAL_SWITCH) {
window.extendPDP();
}
- Include Upsell / cross-sell modal functionality
- In: */app_storefront_core/cartridge/js/pages/product/addToCart.js
- Where: function addToCart(), after the $form variable declaration and before addItemToCart()
Code:
// Extend Integration
if ($('#extend-offer').length) {
extendAddToCart($form, page, minicart, dialog, addItemToCart);
return;
}
- Import extendHelpers.js in CartModel.js
- In: */app_storefront_controllers/cartridge/scripts/models/CartModel.js
- Where: include this script at the API Includes section
Code:
// Import Extend Script Helpers
var extendHelpers = require('*/cartridge/scripts/extend');
- Include Extend line item creation in CartModel.js
- In: */app_storefront_controllers/cartridge/scripts/models/CartModel.js
- Where: function addProductToCart(), before the return statement
Code:
// Extend Create Warranty LineItem
extendHelpers.createExtendLineItem(cart, params, Product, Transaction);
- Import extendHelpers.js in Cart
- In: */app_storefront_controllers/cartridge/controllers/Cart.js
- Where: include this script at the API Includes section
Code:
var extendHelpers = require('*/cartridge/scripts/extendHelpers');
- Add functionality to remove Extend warranty line items in Cart.js
- In: */app_storefront_controllers/cartridge/controllers/Cart.js
- Where: ‘deleteProduct’ action handler; replace this entire function with the following code
Code:
'deleteProduct': function (formgroup) {
// EXTEND - Check if there is a warranty associated with the product that is being deleted
var warrantyLineItem = extendHelpers.checkForWarrantyLI(cart, formgroup.getTriggeredAction().object);
Transaction.wrap(function () {
cart.removeProductLineItem(formgroup.getTriggeredAction().object);
// EXTEND - if there is a warranty associated with the product remove the corresponding warranty
if (warrantyLineItem) {
cart.removeProductLineItem(warrantyLineItem);
}
});
return {
cart: cart
};
}
- Add contract generation snippet to COPlaceOrder.js
- In: */app_storefront_controllers/cartridge/controllers/COPlaceOrder.js
- Where: function submit(), in the if (!orderPlacementStatus.error) statement
Code:
// Add Extend products to Contracts queue
var extendHelpers = require('*/cartridge/scripts/extend');
addContractToQueue(order.object);
- CartView.js
- In: /cartridges/app_storefront_controllers/cartridge/scripts/views/CartView.js
- Where: line 38
- Move the following code snippet from line 38 to line 33 to ensure the warranty price is recalculated before displaying in the cart.
Code:
// Refreshes the cart calculation
Transaction.wrap( function () {
Cart.get(cart).calculate();
})
See screenshots below:
Code location before:
Code location after:
- Include ExtendAnalyticsHelpers in CartView.js
- In: /cartridges/app_storefront_controllers/cartridge/scripts/views/CartView.js
- Where: top of the file
Code:
var extendAnalyticsHelpers = require(‘*/cartridge/scripts/extendAnalyticsHelpers’)
- In: /cartridges/app_storefront_controllers/cartridge/scripts/views/CartView.js
- Where: “prepareView” function → line 48
Code:
// Extend Analytics
extendAnalyticsHelpers.setUpdateCartPayload(cart)
this.analyticsPayload = extendAnalyticsHelpers.getAnalyticsPayload();
- Include ExtendAnalyticsHelpers.setDeleteProductPayload in Cart.js
- In: /cartridges/app_storefront_controllers/cartridge/controllers/Cart.js
Where: top of the file
Code: -
var extendHelpers = require(*/cartridge/scripts/extendHelpers’); var extendAnalyticsHelpers = require(‘*/cartridge/scripts/extendAnalyticsHelpers’);
- In: /cartridges/app_storefront_controllers/cartridge/controllers/Cart.js
- Where: “submitForm” function → “deleteProduct” function → line 182
Code:
var warrantyLineItem = extendHelpers.checkForWarrantyLI(cart, formgroup.getTriggeredAction().object);
extendAnalyticsHelpers.setDeleteProductPayload(cart, formgroup.getTriggeredAction().object, warrantyLineItem);
- Include “Extend Integration” and “Extend Analytics Integration” in app.js
- In: /cartridges/app_storefront_core/cartridge/static/default/js/app.js
- Where: “addToCart” function. Line 2537 - 2547
Code:
// Extend Integration
if ($(‘#extend-offer’).length || (window.EXT_GLOBAL_SWITCH && window.EXT_PDP_UPSELL_SWITCH)) {
extendAddToCart($form, page, minicart, dialog, addItemToCart);
return;
}
// ExtendAnalytics Integration
if (window.EXT_A_EXT_GLOBAL_SWITCH) {
var payload = createAddToCartAnalytics($form)
trackAddToCart(payload)
}
Updated about 1 year ago