medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.93k stars 2.6k forks source link

When ordering products by variants.prices.amount not all products are retrieved. #5539

Closed chemicalkosek closed 4 months ago

chemicalkosek commented 1 year ago

Bug report

Describe the bug

When using /store/products route and ordering by variants.prices.amount not all products are retrieved even though the count in response is correct. The number of returned products also differs when changing from ASC to DESC.

System information

Medusa version (including plugins): Node.js version: 1.7.3

Steps to reproduce the behavior

/store/products?fields=id&expand=variants.prices&order=variants.prices.amount

In test case the count in response is correct: 94. Actual records returned: 55

When we reverse the order to DESC: /store/products?fields=id&expand=variants.prices&order=-variants.prices.amount

In test case count in response is correct: 94. Actual records returned: 27

The actual records returned is always the same. If we start to increase the limit to a number higher than the number of products in database it starts to return more products. It needed a limit of almost 300 to return all 94 records.

Products have different length of variants, some 1, some ~ 50.

Expected behavior

Return all relevant products

Xxsource98 commented 11 months ago

Hi, I have problem with pricing ordering too.

adrien2p commented 10 months ago

I ll have a look guys

adrien2p commented 10 months ago

once the snapshot is generated you can try this version https://github.com/medusajs/medusa/pull/5990

adrien2p commented 10 months ago

@chemicalkosek would you be able to test the snapshot version?

chemicalkosek commented 10 months ago

I've made this issue for some Discord users who had such problems, I wasn't actually using this. But sure, I'll test it today and get back to you.

PS. I thought that this will be the "new" way of ordering and filtering products: https://github.com/medusajs/medusa/pull/5447

adrien2p commented 10 months ago

yes you are right, but it has been put on pause for now .. So we still need to fix the existing :D

chemicalkosek commented 10 months ago

I have tested and can confirm that the original issue is fixed.

Altough there are some errors when starting the backend, I assume they come from some incoming breaking changes that are already merged in this snapshot.

Error: Cannot find module 'node_modules/@medusajs/admin/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:438:19)
    [discovery] ORM entity discovery started, using ReflectMetadataProvider
Could not resolve module: cartCartSalesChannelSalesChannelLink. Error: Loaders for module cartCartSalesChannelSalesChannelLink failed: Cannot read properties of undefined (reading 'className')

Error initializing link modules. TypeError: Cannot set properties of undefined (setting '__definition')
    at MedusaModule.bootstrapLink (/node_modules/@medusajs/medusa/node_modules/@medusajs/modules-sdk/dist/medusa-module.js:214:44)
adrien2p commented 10 months ago

Yes exactly, those errors are due to unreleased things yet. Thank you very much 👌

@olivermrbl should we proceed?

olivermrbl commented 10 months ago

Yessir 🚢

sradevski commented 4 months ago

Hey, thanks for the report! Since v2 brought a lot of architectural and API changes on the backend, we will be closing this ticket since it no longer applies to our new setup, or the issue has already been fixed. If you are still facing issues with v1, please open a new ticket and we will address it as soon as possible. Thanks! 🙏