Skip to content

Commit

Permalink
Order Confirmation bug fixes (#6)
Browse files Browse the repository at this point in the history
* removed conditional blocking order confirmations from being sent

* Order Confirmation bug fixes

* Removed status check until strategy is specced

* Rebased & updated changelog

* Rebased & updated changelog

* Added status check back in for safety
  • Loading branch information
cykolln committed Oct 14, 2021
1 parent 01281fb commit 87def64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bumped for multiple releases during one month.
### [Unreleased]
##### Fixed
- Order Confirmation event will now correctly fire for orders with coupons.
- Order Confirmation will now correctly fire if product has no primary category.
##### Updated
- Rename sendEmail function to trackEvent
- Fix grammar/typos in comments and docstrings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ function prepareOrderPayload(order, isFutureOrder, mailType) {
}

items.push(productLineItem.productID);

itemCount += productLineItem.quantity.value;
var allCategories;
if (productDetail.variant) {
itemPrimaryCategories.push(productDetail.masterProduct.getPrimaryCategory().displayName);
if (productDetail.masterProduct.getPrimaryCategory()) {
itemPrimaryCategories.push(productDetail.masterProduct.getPrimaryCategory().displayName);
}
allCategories = productDetail.masterProduct.getAllCategories();
} else {
itemPrimaryCategories.push(productDetail.getPrimaryCategory().displayName);
if (productDetail.getPrimaryCategory()) {
itemPrimaryCategories.push(productDetail.getPrimaryCategory().displayName);
}
allCategories = productDetail.getAllCategories();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Logger = require('dw/system/Logger');
var productMgr = require('dw/catalog/ProductMgr');
var orderMgr = require('dw/order/OrderMgr');
var basketMgr = require('dw/order/BasketMgr');
var Logger = require('dw/system/Logger');

var buildDataLayer = function () {
var logger = Logger.getLogger('Klaviyo', 'SFRA klaviyoDataLayer - buildDataLayer()');
Expand Down Expand Up @@ -49,18 +50,16 @@ var buildDataLayer = function () {
}

// Order Confirmation Event
if (pageContext == 'orderconfirmation' && orderID) {
if (orderID && !empty(orderID.rawValue)) {
logger.info('Building dataLayer for "Order Confirmation" event.');
KlaviyoUtils = require('*/cartridge/scripts/utils/klaviyo/klaviyoUtils');

if (!dw.system.Site.getCurrent().getCustomPreferenceValue('klaviyo_order_transactional_enabled')) {
return;
}
currentOrder = orderMgr.getOrder(orderID);
KlaviyoUtils.prepareOrderConfirmationEventForKlaviyo(currentOrder);
// check to see if the status is new or created
if (currentOrder.status == 3 || currentOrder.status == 4) {
KlaviyoUtils.prepareOrderConfirmationEventForKlaviyo(currentOrder);
}
}


// Viewed Product event
if (!empty(pageProductID.rawValue)) {
logger.info('Building dataLayer for "Viewed Product" event.');
Expand Down

0 comments on commit 87def64

Please sign in to comment.