Skip to content
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

fix(medusa): calculate sales channel availability correctly for variants #10448

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

srindom
Copy link
Collaborator

@srindom srindom commented Dec 5, 2024

What

  • Fixes inventory calculations on store endpoints which didn't take the sales channel into account.
  • Adds a new utility to framework/utils function to calculate inventory availability based on variant and sales channel ids
  • Adds a new step to core-flows that can be used to calculate inventory availability as part of a workflow.
  • Adds a test for more involved inventory calculations. The existing suite didn't test directly for the channel->location->item->variant relationships.

Why

  • Medusa's availability calculation is powerful, but takes some steps to compute. We don't want to put the burden of computing this value on developers who might need it in their customizations. Therefore we are now providing an easy mechanism for getting the inventory quantity.

Usage

import { getVariantAvailability } from "@medusajs/framework/utils"

const query = container.resolve("query")
const availability = await getVariantAvailability(query, {
  variant_ids: ["variant_1234"],
  sales_channel_id: "sc_1234",
})

// availability -> { variant_1234: { availability: 23, sales_channel_id: "sc_1234" } }

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 5:57pm
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 5:57pm
5 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 5, 2024 5:57pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Dec 5, 2024 5:57pm
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 5, 2024 5:57pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Dec 5, 2024 5:57pm
resources-docs ⬜️ Ignored (Inspect) Visit Preview Dec 5, 2024 5:57pm

Copy link

changeset-bot bot commented Dec 5, 2024

⚠️ No Changeset found

Latest commit: 06f7825

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@srindom srindom force-pushed the wip/variant-avail-step branch from 46433e1 to e7e741b Compare December 5, 2024 15:24
@srindom srindom marked this pull request as ready for review December 5, 2024 15:31
@srindom srindom requested a review from a team as a code owner December 5, 2024 15:31
@srindom srindom changed the title Wip/variant avail step fix(medusa): calculate sales channel availability correctly for variants Dec 5, 2024
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues left a comment

Choose a reason for hiding this comment

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

LGTM

srindom and others added 3 commits December 5, 2024 18:46
@olivermrbl olivermrbl merged commit 7ff3f15 into develop Dec 5, 2024
23 checks passed
@olivermrbl olivermrbl deleted the wip/variant-avail-step branch December 5, 2024 18:29
hirotaka pushed a commit to hirotaka/medusa that referenced this pull request Dec 7, 2024
…nts (medusajs#10448)

* fix: calculate inventory quantities based on sales channel and locations

* Update packages/medusa/src/api/utils/middlewares/products/variant-inventory-quantity.ts

Co-authored-by: Carlos R. L. Rodrigues <[email protected]>

* Update packages/medusa/src/api/utils/middlewares/products/variant-inventory-quantity.ts

Co-authored-by: Carlos R. L. Rodrigues <[email protected]>

* Update packages/core/core-flows/src/product/steps/get-variant-availability.ts

Co-authored-by: Carlos R. L. Rodrigues <[email protected]>

* fix: crk

---------

Co-authored-by: Carlos R. L. Rodrigues <[email protected]>
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.

3 participants