-
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?
Conversation
…nal in_stock checks, made comments and descriptions more precise
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.
Pull request overview
This PR fixes incorrect stock availability calculations caused by the Algolia_InStockThreshold site preference defaulting to 0. The core issue is that a threshold of 0 causes all products to be marked as in-stock (since ATS >= 0 is always true for any product). The fix updates the default to 1 and adds explicit ATS > 0 checks throughout the codebase to prevent threshold=0 from incorrectly marking products as in-stock.
Key Changes:
- Changed default value of
Algolia_InStockThresholdfrom 0.0 to 1.0 in system metadata - Added explicit
ATS > 0checks in all stock validation methods to guard against threshold=0 edge cases - Added fallback value
|| 1when reading the preference to ensure correct behavior for existing installations
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
metadata/algolia/meta/system-objecttype-extensions.xml |
Updated default value of Algolia_InStockThreshold from 0.0 to 1.0 |
cartridges/int_algolia/cartridge/scripts/algolia/filters/productFilter.js |
Added ATS > 0 checks to isInStock(), isInStoreStock(), and new isCustomVariationGroupInStock() methods; added missing return statement |
cartridges/int_algolia/cartridge/scripts/algolia/model/algoliaLocalizedProduct.js |
Added ATS > 0 check in storeAvailability() handler; simplified in_stock handler |
cartridges/int_algolia/cartridge/scripts/algolia/model/algoliaProduct.js |
Added fallback value ` |
cartridges/int_algolia/cartridge/scripts/algolia/steps/algoliaProductIndex.js |
Added fallback value ` |
cartridges/int_algolia/cartridge/scripts/algolia/steps/algoliaProductDeltaIndex.js |
Added fallback value ` |
cartridges/int_algolia_sfra/cartridge/scripts/hooks/order/algoliaHooks.js |
Added fallback value ` |
cartridges/int_algolia/cartridge/configuration/productFilterConfig.example.js |
Updated documentation to show correct default value of 1 |
cartridges/bm_algolia/cartridge/templates/resources/algolia.properties |
Improved description clarity for InStockThreshold and IndexOutOfStock preferences |
test/unit/int_algolia/scripts/algolia/helper/orderHelper.test.js |
Added variant data with ATS=5 to test fixtures |
test/unit/int_algolia/scripts/algolia/helper/__snapshots__/orderHelper.test.js.snap |
Updated snapshots to reflect variants in test output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cartridges/int_algolia/cartridge/scripts/algolia/filters/productFilter.js
Show resolved
Hide resolved
| var atsValue = invRecord ? invRecord.getATS().getValue() : 0; | ||
| return atsValue >= threshold; | ||
|
|
||
| return (atsValue > 0 && atsValue >= threshold); |
Copilot
AI
Dec 23, 2025
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.
The condition atsValue > 0 && atsValue >= threshold is redundant when threshold >= 1. Since the default is now 1 and there's a fallback of || 1, consider simplifying to atsValue >= threshold.
cartridges/int_algolia/cartridge/scripts/algolia/filters/productFilter.js
Show resolved
Hide resolved
cartridges/int_algolia/cartridge/scripts/algolia/filters/productFilter.js
Show resolved
Hide resolved
cartridges/int_algolia/cartridge/scripts/algolia/model/algoliaLocalizedProduct.js
Show resolved
Hide resolved
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
cartridges/int_algolia/cartridge/scripts/algolia/steps/algoliaProductIndex.js
Show resolved
Hide resolved
| * @param {Number} threshold | ||
| * @returns {Boolean} whether at least one of the variants is in stock | ||
| */ | ||
| function isCustomVariationGroupInStock(variationModel, threshold) { |
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.
Let's keep the introduction of this helper in the dedicated feature branch
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.
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.
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.
as the changes to the would-be helper are here as well which would be lost if I removed this from here
Do "the changes" refer to the variantATSValue > 0 addition? I think it can be easily added on the attribute-slicing feature branch.
Re-opened PR instead of closed PR #246 to point to
developIssue description
Setting the value of the Algolia_InStockThreshold site preference to 0 (the current default) breaks
in_stockcalculation.The default value was changed from no value to 0 in #110 .
When setting up a new cartridge installation, a default value of 0 leads to all products always returning
in_stock == true.Context: SFCC didn’t require a default to be set before – the code treated leaving it empty as if there was no limit set and handled it correctly (i.e. didn’t take the value of this preference into account at all, falling back to the expected behavior of “treat a product as in-stock if it has at least 1 product in stock”).
The documentation shows this value as set to 1, which results in correct behavior.
#110 introduced an explicit 0 as the default value of this preference, which leads to problems due to the code returning
in_stock === trueif the product has at least 0 products in stock, so it always returns true for all products, which is erroneous behavior. Existing cartridge installations where there was no default value set should not encounter problems, but new installations will as all products will always returnin_stock === true. To solve this, the logic was changed so that an ATS of 0 will never returntrue, no matter what value theAlgolia_InStockThresholdpreference is set to. This also guards against user error as the user can set 0 as theInStockThreshold, even if that’s not the default.Changes in this PR
Algolia_InStockThresholdto 1 so new installations will now set this valueisInStock()inproductFilter.jsnow returnstrueonly ifATS > 0isInStock()method didn't previously return anything, fixedisInStoreStock()inproductFilter.jsnow returnstrueonly ifATS > 0isCustomVariationGroupInStock()inproductFilter.jsnow returnstrueonly ifATS > 0storeAvailability()inalgoliaLocalizedProduct.jsnow returnstrueonly ifATS > 0productFilterConfig.example.jsnow shows the correct default of 1Algolia_InStockThresholdsite preference more explicit