-
Notifications
You must be signed in to change notification settings - Fork 7
fix: [SFCC-471] Changed the default value of Algolia_InStockThreshold to 1, additional related fixes #248
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
base: develop
Are you sure you want to change the base?
fix: [SFCC-471] Changed the default value of Algolia_InStockThreshold to 1, additional related fixes #248
Changes from all commits
d756f87
2f67426
150ca74
681766c
6ebc0ff
865ba60
37f390d
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 |
|---|---|---|
|
|
@@ -66,13 +66,13 @@ | |
| // if (product.optionProduct) return false; | ||
| // Do not include bundled product | ||
| if (product.bundled && !(product.priceModel && product.priceModel.price && product.priceModel.price.available)) return false; | ||
|
|
||
| // Check online status | ||
| if (!isOnline(product)) return false; | ||
|
|
||
| // Check searchable status | ||
| if (!isSearchable(product)) return false; | ||
|
|
||
| // Check if product has at least one online category | ||
| // Note: In SFCC, variant products don't have their own categories - getOnlineCategories() returns empty for variants | ||
| // We must check categories on the master product instead | ||
|
|
@@ -82,7 +82,7 @@ | |
| } else { | ||
| if (!hasOnlineCategory(product)) return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -101,24 +101,50 @@ | |
| // even if one variant is in stock, we consider the product as in stock | ||
| if (product.master || product.variationGroup) { | ||
| const variantsIt = product.variants.iterator(); | ||
|
|
||
| while (variantsIt.hasNext()) { | ||
| let variant = variantsIt.next(); | ||
| let variantAvailabilityModel = variant.getAvailabilityModel(); | ||
|
|
||
| if (variantAvailabilityModel) { | ||
| let variantInvRecord = variantAvailabilityModel.getInventoryRecord(); | ||
|
|
||
| if (variantInvRecord) { | ||
| let variantAtsValue = variantInvRecord.getATS().getValue(); | ||
| if (variantAtsValue >= threshold) { | ||
| let variantATSValue = variantInvRecord.getATS().getValue(); | ||
|
|
||
| if (variantATSValue > 0 && variantATSValue >= threshold) { // comparing to zero explicitly so that a threshold of 0 wouldn't return true | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| var invRecord = availabilityModel.getInventoryRecord(); | ||
| var atsValue = invRecord ? invRecord.getATS().getValue() : 0; | ||
| return atsValue >= threshold; | ||
|
|
||
| return (atsValue > 0 && atsValue >= threshold); | ||
|
||
| } | ||
|
|
||
| /** | ||
| * Checks if at least one variant in a variation model is in stock. | ||
| * @param {dw.catalog.ProductVariationModel} variationModel | ||
| * @param {Number} threshold | ||
| * @returns {Boolean} whether at least one of the variants is in stock | ||
| */ | ||
| function isCustomVariationGroupInStock(variationModel, threshold) { | ||
|
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. Let's keep the introduction of this helper in the dedicated feature branch
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. Can't, as the changes to the would-be helper are here as well which would be lost if I removed this from here. This will nicely fall into place once the other pull requests are merged into develop and this branch is rebased. The linter error will also be gone.
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.
Do "the changes" refer to the |
||
| const variantsIt = variationModel.getSelectedVariants().iterator(); | ||
| while (variantsIt.hasNext()) { | ||
| let variant = variantsIt.next(); | ||
| let variantATSValue = variant.getAvailabilityModel().getInventoryRecord().getATS().getValue(); | ||
| if (variantATSValue > 0 && variantATSValue >= threshold) { | ||
ede-somogyi-algolia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -133,14 +159,18 @@ | |
| function isInStoreStock(product, storeId, threshold) { | ||
| const StoreMgr = require('dw/catalog/StoreMgr'); | ||
| let store = StoreMgr.getStore(storeId); | ||
|
|
||
| if (!store || !store.inventoryList) { | ||
| return false; | ||
| } | ||
|
|
||
| let storeInventory = store.inventoryList; | ||
| let inventoryRecord = storeInventory.getRecord(product.ID); | ||
| if (inventoryRecord && inventoryRecord.ATS.value && inventoryRecord.ATS.value >= threshold) { | ||
|
|
||
| if (inventoryRecord && inventoryRecord.ATS.value && inventoryRecord.ATS.value >= threshold && inventoryRecord.ATS.value > 0) { // comparing to zero explicitly so that a threshold of 0 wouldn't return true | ||
ede-somogyi-algolia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.