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

Product query doesn't refer only to current channel stock location #2356

Closed
lzzfnc opened this issue Aug 24, 2023 · 2 comments
Closed

Product query doesn't refer only to current channel stock location #2356

lzzfnc opened this issue Aug 24, 2023 · 2 comments

Comments

@lzzfnc
Copy link
Contributor

lzzfnc commented Aug 24, 2023

We have a multi channel - multi sellers setup, where every seller relies on a different stock location.
When querying a product there is an unexpected behaviour regarding the stockLevel, that seems to take into account not only the current channel stock location, but also all the others. If there are no saleable units in the current stock location, but they are still available in other locations, the product query will return IN_STOCK.

To Reproduce

  1. Set up two channels channel-A and channel-B
  2. Create two stock locations stock-A and stock-B
  3. Edit a Product Variant in order to set its available stock
  4. out-of-stock-threshold is set to 0 as default
  5. channel-A refers only to stock-A, same for the other
  6. Set stock-A to 0
  7. Set stock-B to 10
  8. Query the product with the shop-api a in the channel-A and check for stockLevel
  9. The query returns stockLevel: IN_STOCK
  10. Eventually, the product can be added to an order and purchased
  11. This allocate 1 item in the channel-A, and even to fullfill the order, leading to a negative stock amount.

Expected behavior

The query should return stockLevel: OUT_OF_STOCK, since stock-A has been set to zero.

Environment (please complete the following information):

  • @vendure/core version: 2.0.0
  • Nodejs version: 16
  • Database: postgres
@lzzfnc lzzfnc added the type: bug 🐛 Something isn't working label Aug 24, 2023
@michaelbromley michaelbromley moved this to 📋 Backlog in Vendure OS Roadmap Aug 24, 2023
@michaelbromley michaelbromley moved this from 📋 Backlog to 🏗 In progress in Vendure OS Roadmap Aug 30, 2023
@michaelbromley
Copy link
Member

michaelbromley commented Aug 30, 2023

Thanks for the report. This behaviour is the responsibility of the StockLocationStrategy.

The StockLocationStrategy is responsible for determining which {StockLocation}s
should be used to fulfill an {OrderLine} and how much stock should be allocated
from each location. It is also used to determine the available stock for a given
{ProductVariant}.

By default, Vendure uses the DefaultStockLocationStrategy which is documented thus:

The DefaultStockLocationStrategy is the default implementation of the {StockLocationStrategy}.
It assumes only a single StockLocation and that all stock is allocated from that location.

You can see the source here: https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/src/config/catalog/default-stock-location-strategy.ts#L28

So technically what you report is "working as intended" but yeah, we should probably look at what we can do better here.

I see the following options:

  1. Better documentation. I've made a start on this, the new beta docs include a section on stock control which covers this: https://beta-docs.vendure.io/guides/core-concepts/stock-control/#selecting-a-stock-location
  2. It should also be covered in the multi-vendor marketplace guide, which it currently isn't.
  3. We could make the DefaultStockLocationStrategy just handle this automatically.
  4. We could leave the default strategy, but also export a MultiChannelStockLocationStrategy

Doing 3 would be a breaking change so I'm going to look into 4.

@michaelbromley michaelbromley moved this from 🏗 In progress to 📋 Backlog in Vendure OS Roadmap Aug 30, 2023
@lzzfnc
Copy link
Contributor Author

lzzfnc commented Sep 25, 2023

Thanks for the detailed explanation!
Did you had perhaps the chance to look into the MultiChannelStockLocationStrategy?

@dlhck dlhck added type: feature ✨ and removed type: bug 🐛 Something isn't working labels Sep 27, 2024
@dlhck dlhck added this to the v3.1.0 milestone Sep 27, 2024
@halykon halykon self-assigned this Oct 22, 2024
@michaelbromley michaelbromley removed their assignment Oct 31, 2024
@michaelbromley michaelbromley moved this from 📅 Planned to ♻️ In progress in Vendure OS Roadmap Nov 27, 2024
michaelbromley added a commit that referenced this issue Nov 28, 2024
Fixes #2356. This commit introduces a much more sophisticated stock location strategy
that takes into account the active channel, as well as available stock levels
in each available StockLocation.

With v3.1.0 it will become the default strategy.
michaelbromley added a commit that referenced this issue Nov 29, 2024
Fixes #2356. This commit introduces a much more sophisticated stock location strategy
that takes into account the active channel, as well as available stock levels
in each available StockLocation.

With v3.1.0 it will become the default strategy.
@michaelbromley michaelbromley moved this from ♻️ In progress to 💯 Ready in Vendure OS Roadmap Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 💯 Ready
Development

No branches or pull requests

4 participants