Skip to content

Conversation

@ede-somogyi-algolia
Copy link
Collaborator

@ede-somogyi-algolia ede-somogyi-algolia commented Dec 17, 2025

Issue description

Setting the value of the Algolia_InStockThreshold site preference to 0 (the current default) breaks in_stock calculation.

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 === true if 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 return in_stock === true. To solve this, the logic was changed so that an ATS of 0 will never return true, no matter what value the Algolia_InStockThreshold preference is set to. This also guards against user error as the user can set 0 as the InStockThreshold, even if that’s not the default.

Changes in this PR

  • changed the default value of Algolia_InStockThreshold to 1 so new installations will now set this value
  • isInStock() in productFilter.js now returns true only if ATS > 0
  • when none of the variants are in stock, the isInStock() method didn't previously return anything, fixed
  • isInStoreStock() in productFilter.js now returns true only if ATS > 0
  • isCustomVariationGroupInStock() in productFilter.js now returns true only if ATS > 0
  • storeAvailability() in algoliaLocalizedProduct.js now returns true only if ATS > 0
  • productFilterConfig.example.js now shows the correct default of 1
  • made the description of the Algolia_InStockThreshold site preference more explicit

@ede-somogyi-algolia ede-somogyi-algolia self-assigned this Dec 17, 2025
@ede-somogyi-algolia ede-somogyi-algolia force-pushed the fix/SFCC-471_fix_default_Algolia_InStockThreshold_value branch from 9e880c4 to 9474268 Compare December 17, 2025 16:14
@ede-somogyi-algolia ede-somogyi-algolia changed the base branch from develop to feat/vargroup-model/sfcc-468-2-expose-variation-attribute-as-site-preference December 17, 2025 16:15
Copy link
Collaborator

@sbellone sbellone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍
There is a lint issue to fix, and please target develop as this is an independent fix.

Comment on lines 391 to 386
let inStock = productFilter.isInStock(product, ALGOLIA_IN_STOCK_THRESHOLD);

if (!inStock && !INDEX_OUT_OF_STOCK) {
return undefined;
}

return inStock;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let inStock = productFilter.isInStock(product, ALGOLIA_IN_STOCK_THRESHOLD);
if (!inStock && !INDEX_OUT_OF_STOCK) {
return undefined;
}
return inStock;
return productFilter.isInStock(product, ALGOLIA_IN_STOCK_THRESHOLD);

@ede-somogyi-algolia ede-somogyi-algolia changed the base branch from feat/vargroup-model/sfcc-468-2-expose-variation-attribute-as-site-preference to develop December 23, 2025 16:25
@ede-somogyi-algolia ede-somogyi-algolia changed the base branch from develop to feat/vargroup-model/sfcc-468-2-expose-variation-attribute-as-site-preference December 23, 2025 16:31
@ede-somogyi-algolia ede-somogyi-algolia force-pushed the feat/vargroup-model/sfcc-468-2-expose-variation-attribute-as-site-preference branch from 73ffb11 to 3a8c8d0 Compare December 23, 2025 16:34
@ede-somogyi-algolia ede-somogyi-algolia force-pushed the fix/SFCC-471_fix_default_Algolia_InStockThreshold_value branch from e18c67c to 84c1121 Compare December 23, 2025 17:42
@ede-somogyi-algolia
Copy link
Collaborator Author

Closing pull request, re-opened in #248, pointing to develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants