Skip to content

fix(search): resolve inStock per channel in webhooks - #2427

Merged
lkostrowski merged 1 commit into
mainfrom
lkostrowski/algolia-instock-webhook-sync
Aug 27, 2026
Merged

fix(search): resolve inStock per channel in webhooks#2427
lkostrowski merged 1 commit into
mainfrom
lkostrowski/algolia-instock-webhook-sync

Conversation

@lkostrowski

Copy link
Copy Markdown
Member

Saleor resolves quantityAvailable per channel, but webhook subscriptions have no channel context - productVariant is resolved with channel_slug=None, so the loader finds no warehouses and always returns 0. Every webhook then wrote inStock: false, and since records are saved with saveObjects (full replace), even BACK_IN_STOCK overwrote the correct value. Only a full index import produced correct data, until the next webhook arrived.

Fetch quantityAvailable again per channel the variant is listed in, and pass the channel-scoped value into each index's document. One query per channel covers all variants, and is skipped when inStock is not an enabled field. A failed fetch throws so Saleor retries, instead of indexing a wrong value.

Also honour trackInventory: untracked variants can always be bought, but Saleor returns null for their quantityAvailable unless limitQuantityPerCheckout is set, so they were indexed as out of stock in both webhook and bulk sync.

Scope of the PR

Related issues

Checklist

Saleor resolves quantityAvailable per channel, but webhook subscriptions
have no channel context - productVariant is resolved with channel_slug=None,
so the loader finds no warehouses and always returns 0. Every webhook then
wrote inStock: false, and since records are saved with saveObjects (full
replace), even BACK_IN_STOCK overwrote the correct value. Only a full index
import produced correct data, until the next webhook arrived.

Fetch quantityAvailable again per channel the variant is listed in, and pass
the channel-scoped value into each index's document. One query per channel
covers all variants, and is skipped when inStock is not an enabled field.
A failed fetch throws so Saleor retries, instead of indexing a wrong value.

Also honour trackInventory: untracked variants can always be bought, but
Saleor returns null for their quantityAvailable unless limitQuantityPerCheckout
is set, so they were indexed as out of stock in both webhook and bulk sync.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lkostrowski
lkostrowski requested a review from a team as a code owner August 27, 2026 12:08
@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 644d395

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
saleor-app-search Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dummy-payment-app Ready Ready Preview Aug 27, 2026 12:10pm
dummy-shipping-app Ready Ready Preview Aug 27, 2026 12:10pm
extensions-explorer Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-anonymizer Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-avatax Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-cms Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-klaviyo Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-onboarding Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-payment-np-atobarai Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-payment-stripe Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-products-feed Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-search Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-segment Ready Ready Preview Aug 27, 2026 12:10pm
saleor-app-smtp Ready Ready Preview Aug 27, 2026 12:10pm

Request Review

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.59140% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.54%. Comparing base (4e0ce63) to head (644d395).

Files with missing lines Patch % Lines
...ps/search/src/lib/algolia/algoliaSearchProvider.ts 6.25% 30 Missing ⚠️
apps/search/src/webhooks/webhook-context.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2427      +/-   ##
==========================================
+ Coverage   37.51%   37.54%   +0.03%     
==========================================
  Files        1222     1223       +1     
  Lines       77118    77209      +91     
  Branches     4204     4219      +15     
==========================================
+ Hits        28929    28989      +60     
- Misses      47694    47725      +31     
  Partials      495      495              
Flag Coverage Δ
anonymizer 9.59% <ø> (ø)
app-problems 98.07% <ø> (ø)
avatax 57.18% <ø> (ø)
cms 21.84% <ø> (ø)
domain 100.00% <ø> (ø)
dummy-payment-app 0.26% <ø> (ø)
dynamo-config-repository 79.29% <ø> (ø)
errors 92.00% <ø> (ø)
extensions-explorer 29.49% <ø> (ø)
handlebars 99.37% <ø> (ø)
logger 28.81% <ø> (ø)
np-atobarai 72.66% <ø> (ø)
onboarding 66.49% <ø> (ø)
otel 23.52% <ø> (ø)
products-feed 6.16% <ø> (ø)
search 33.28% <65.59%> (+0.63%) ⬆️
segment 33.65% <ø> (ø)
shared 57.88% <ø> (ø)
smtp 49.75% <ø> (ø)
stripe 63.55% <ø> (ø)
webhook-utils 21.35% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lkostrowski
lkostrowski enabled auto-merge (squash) August 27, 2026 12:41
@lkostrowski
lkostrowski merged commit 69a3253 into main Aug 27, 2026
71 checks passed
@lkostrowski
lkostrowski deleted the lkostrowski/algolia-instock-webhook-sync branch August 27, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants