-
Notifications
You must be signed in to change notification settings - Fork 7
fix: [SFCC-526] Miscellaneous fixes #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
4b51f6a
65246dd
3011be8
07e3f8a
ae649e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ function getPromotionalPrice(product) { | |
| // find the lowest price | ||
| if (promoPrices.length > 0) { | ||
| lowestPromoPrice = promoPrices.reduce(function (a, b) { | ||
| return Math.min(a.value, b.value); | ||
| return a.getValue() <= b.getValue() ? a : b; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code typecast the Money object into a number, which can lead to issues downstream (e.g. when trying to call
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch 👍 |
||
| }); | ||
| } | ||
| return lowestPromoPrice; | ||
|
|
@@ -109,7 +109,7 @@ function getPromotionalPrices(product, campaigns) { | |
| if (price === dw.value.Money.NOT_AVAILABLE) { | ||
| return null; | ||
| } | ||
| let promoId = promotion.ID; | ||
| let promoId = promotion.getID(); | ||
| return { | ||
| price: price.getValue(), | ||
| promoId: promoId | ||
|
|
@@ -244,7 +244,7 @@ var aggregatedValueHandlers = { | |
| }, | ||
| defaultVariantID: function(product) { | ||
| const defaultVariant = product.getVariationModel().getDefaultVariant(); | ||
| return defaultVariant ? defaultVariant.ID : null; | ||
| return defaultVariant ? defaultVariant.getID() : null; | ||
| }, | ||
| categories: function (product) { | ||
| var productCategories = product.getOnlineCategories(); | ||
|
|
@@ -279,19 +279,19 @@ var aggregatedValueHandlers = { | |
| }, | ||
| primary_category_id: function (product) { | ||
| var result = null; | ||
| if (empty(product.primaryCategory)) { | ||
| if (empty(product.getPrimaryCategory())) { | ||
| var primaryCategory = product.isVariant() ? product.getMasterProduct().getPrimaryCategory() : null; | ||
| result = empty(primaryCategory) ? null : primaryCategory.ID; | ||
| result = empty(primaryCategory) ? null : primaryCategory.getID(); | ||
| } else { | ||
| result = product.getPrimaryCategory().getID(); | ||
| } | ||
| return result; | ||
| }, | ||
| __primary_category: function (product) { | ||
| var res = {}; | ||
| var primaryCategory = product.primaryCategory; | ||
| var primaryCategory = product.getPrimaryCategory(); | ||
| if (empty(primaryCategory)) { | ||
| primaryCategory = product.isVariant() ? product.masterProduct.primaryCategory : null; | ||
| primaryCategory = product.isVariant() ? product.getMasterProduct().getPrimaryCategory() : null; | ||
| if (empty(primaryCategory)) { | ||
| return null; | ||
| } | ||
|
|
@@ -306,7 +306,7 @@ var aggregatedValueHandlers = { | |
| var variationModel = parameters.variationModel || product.getVariationModel(); | ||
| var colorAttribute = variationModel.getProductVariationAttribute('color'); | ||
| return (colorAttribute && variationModel.getSelectedValue(colorAttribute)) | ||
| ? variationModel.getSelectedValue(colorAttribute).displayValue | ||
| ? variationModel.getSelectedValue(colorAttribute).getDisplayValue() | ||
| : product.custom.color; // this is a workaround to retrieve color values which are otherwise not returned properly by the API via the variation model, likely due to an SFCC bug. It either returns the color value that `getSelectedValue()` couldn't or `null` as before. | ||
|
|
||
| }, | ||
|
|
@@ -319,7 +319,7 @@ var aggregatedValueHandlers = { | |
| if (product.isMaster() || product.isVariationGroup()) { | ||
| return modelHelper.getColorVariations(product); | ||
| } | ||
| const masterProduct = product.getVariationModel().master; | ||
| const masterProduct = product.getVariationModel().getMaster(); | ||
| if (!masterProduct) { | ||
| return null; | ||
| } | ||
|
|
@@ -329,7 +329,7 @@ var aggregatedValueHandlers = { | |
| var variationModel = parameters.variationModel || product.getVariationModel(); | ||
| var sizeAttribute = variationModel.getProductVariationAttribute('size'); | ||
| return (sizeAttribute && variationModel.getSelectedValue(sizeAttribute)) | ||
| ? variationModel.getSelectedValue(sizeAttribute).displayValue | ||
| ? variationModel.getSelectedValue(sizeAttribute).getDisplayValue() | ||
| : product.custom.size; // this is a workaround to retrieve size values which are otherwise not returned properly by the API via the variation model, likely due to an SFCC bug. It either returns the size value that `getSelectedValue()` couldn't or `null` as before. | ||
| }, | ||
| refinementSize: function (product) { | ||
|
|
@@ -346,12 +346,12 @@ var aggregatedValueHandlers = { | |
| var currentCurrency = currentSession.getCurrency(); | ||
|
|
||
| for (var k = 0; k < siteCurrenciesSize; k += 1) { | ||
| var currency = Currency.getCurrency(siteCurrencies[k]); | ||
| var currency = Currency.getCurrency(siteCurrencies.get(k)); | ||
| currentSession.setCurrency(currency); | ||
| var price = product.productSet ? product.priceModel.minPrice : product.priceModel.price; | ||
| if (price.available) { | ||
| var price = product.isProductSet() ? product.getPriceModel().getMinPrice() : product.getPriceModel().getPrice(); | ||
| if (price.isAvailable()) { | ||
| if (!productPrice) { productPrice = {}; } | ||
| productPrice[price.currencyCode] = price.value; | ||
| productPrice[price.getCurrencyCode()] = price.getValue(); | ||
| } | ||
| } | ||
| currentSession.setCurrency(currentCurrency); | ||
|
|
@@ -364,19 +364,22 @@ var aggregatedValueHandlers = { | |
|
|
||
| while (sitePriceBooks.hasNext()) { | ||
| var pricebook = sitePriceBooks.next(); | ||
| if (siteCurrencies.indexOf(pricebook.currencyCode) < 0) { | ||
| var pricebookCurrencyCode = pricebook.getCurrencyCode(); | ||
| if (siteCurrencies.indexOf(pricebookCurrencyCode) < 0) { | ||
| continue; | ||
| } | ||
| var priceInfo = product.priceModel.getPriceBookPriceInfo(pricebook.ID); | ||
| var priceInfo = product.getPriceModel().getPriceBookPriceInfo(pricebook.getID()); | ||
| if (priceInfo) { | ||
| if (!pricebooks[pricebook.currencyCode]) { | ||
| pricebooks[pricebook.currencyCode] = []; | ||
| if (!pricebooks[pricebookCurrencyCode]) { | ||
| pricebooks[pricebookCurrencyCode] = []; | ||
| } | ||
| pricebooks[pricebook.currencyCode].push({ | ||
| price: priceInfo.price.value, | ||
| onlineFrom: priceInfo.onlineFrom ? priceInfo.onlineFrom.getTime() : undefined, | ||
| onlineTo: priceInfo.onlineTo ? priceInfo.onlineTo.getTime() : undefined, | ||
| pricebookID: pricebook.ID, | ||
| var onlineFrom = priceInfo.getOnlineFrom(); | ||
| var onlineTo = priceInfo.getOnlineTo(); | ||
| pricebooks[pricebookCurrencyCode].push({ | ||
| price: priceInfo.getPrice().getValue(), | ||
| onlineFrom: onlineFrom ? onlineFrom.getTime() : undefined, | ||
| onlineTo: onlineTo ? onlineTo.getTime() : undefined, | ||
| pricebookID: pricebook.getID(), | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -416,7 +419,7 @@ var aggregatedValueHandlers = { | |
| }, | ||
| url: function (product) { | ||
| // Get product page url for the current locale | ||
| var productPageUrl = URLUtils.url('Product-Show', 'pid', product.ID); | ||
| var productPageUrl = URLUtils.url('Product-Show', 'pid', product.getID()); | ||
| return productPageUrl ? productPageUrl.toString() : null; | ||
| }, | ||
| promotionalPrice: function (product) { | ||
|
|
@@ -428,7 +431,7 @@ var aggregatedValueHandlers = { | |
| var currentCurrency = currentSession.getCurrency(); | ||
|
|
||
| for (var k = 0; k < siteCurrenciesSize; k += 1) { | ||
| var currency = Currency.getCurrency(siteCurrencies[k]); | ||
| var currency = Currency.getCurrency(siteCurrencies.get(k)); | ||
| currentSession.setCurrency(currency); | ||
| var price = getPromotionalPrice(product); | ||
| if (price) { | ||
|
|
@@ -448,13 +451,13 @@ var aggregatedValueHandlers = { | |
| var currentCurrency = currentSession.getCurrency(); | ||
| var campaigns = PromotionMgr.getCampaigns().toArray(); | ||
| for (var k = 0; k < siteCurrenciesSize; k += 1) { | ||
| var currency = Currency.getCurrency(siteCurrencies[k]); | ||
| var currency = Currency.getCurrency(siteCurrencies.get(k)); | ||
| currentSession.setCurrency(currency); | ||
| var promotionObjects = getPromotionalPrices(product, campaigns); | ||
|
|
||
| if (promotionObjects.length > 0) { | ||
| if (!promotionalPrices) { promotionalPrices = {}; } | ||
| promotionalPrices[siteCurrencies[k]] = promotionObjects; | ||
| promotionalPrices[siteCurrencies.get(k)] = promotionObjects; | ||
| } | ||
| } | ||
| currentSession.setCurrency(currentCurrency); | ||
|
|
@@ -469,7 +472,7 @@ var aggregatedValueHandlers = { | |
| if (parameters.variationModel) { | ||
| variantsIt = parameters.variationModel.getSelectedVariants().iterator(); | ||
| } else { | ||
| variantsIt = product.variants.iterator(); | ||
| variantsIt = product.getVariants().iterator(); | ||
| } | ||
|
|
||
| while (variantsIt.hasNext()) { | ||
|
|
@@ -512,7 +515,7 @@ var aggregatedValueHandlers = { | |
| } | ||
| }, | ||
| _tags: function(product) { | ||
| return ['id:' + product.ID]; | ||
| return ['id:' + product.getID()]; | ||
| }, | ||
| storeAvailability: function(product) { | ||
| var storeArray = []; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the 15-minute timeout from #277. If the job doesn't finish in 15 minutes, chances are high that it will not be successful. With the timeout the job can be retried at least.