vendure-ecommerce/vendure

product Query - finding by slug does not take into account duplicate slugs in different channels

Opened this issue · 0 comments

Describe the bug
In the findOneBySlug() method called from the product() query, the query builder looks for all products matching the given slug and then sorts by the language code before returning the first product in the array. This, however, does not take into account the channel that the query is called from. In the case of two separate channels having products with the same slugs, the getRawOne() call could potentially return the wrong one for the channel, thus returning null for the query when in reality, the product does exist.

To Reproduce
Steps to reproduce the behavior:

  1. Create two channels.
  2. Create a product in each channel with the same slug.
  3. Run the product() query with that slug in both channels.
  4. See that only one of those calls will succeed while the other returns null.

Expected behavior
The findOneBySlug() method should search by channel instead of returning the first product in the sorted array. Calling the query from both channels with the same slug should return the respective products.

Environment (please complete the following information):

  • @vendure/core version: 2.1.7 (seems to be an issue in later versions as well)
  • Nodejs version: 18.16.1
  • Database (mysql/postgres etc): postgres

Additional context
N/A