#sort products by price?

23 messages · Page 1 of 1 (latest)

scenic dagger
#

Is there a way to sort products by price when listing products?

I think sorting by fields was resolved in this pr https://github.com/medusajs/medusa/pull/2815

but I have not figured out how to sort by price since it is nested within variants property

GitHub

What
Move to transformQuery which adds a default ordering and also allows to order the product list from the store API
How
Among other things, fix the product repo to allow ordering by either a key...

burnt spear
#

?order=variants.prices, you can look the integration test

scenic dagger
#

Aha i saw that, thanks!

zenith crag
#

Somehow it doesnt work for me, it says "Order field variants.prices is not valid":

::1 - - [11/May/2023:16:54:59 +0000] "GET /store/products?limit=20&offset=0&category_id%5B0%5D=pcat_01GZKDC1ESKPE058E4768ATB85&category_id%5B1%5D=&order=variants.prices HTTP/1.1" 400 76 "-" "axios/0.24.0"
error:   Order field variants.prices is not valid
Error: Order field variants.prices is not valid
    at prepareListQuery (C:\projects\fs-store\medusa-server\node_modules\@medusajs\medusa\dist\utils\get-query-config.js:122:19)
    at attachListOrRetrieveConfig (C:\projects\fs-store\medusa-server\node_modules\@medusajs\medusa\dist\api\middlewares\transform-query.js:167:66)
    at C:\projects\fs-store\medusa-server\node_modules\@medusajs\medusa\dist\api\middlewares\transform-query.js:132:21
    at step (C:\projects\fs-store\medusa-server\node_modules\@medusajs\medusa\dist\api\middlewares\transform-query.js:33:23)
    at Object.next (C:\projects\fs-store\medusa-server\node_modules\@medusajs\medusa\dist\api\middlewares\transform-query.js:14:53)
    at fulfilled (C:\projects\fs-store\medusa-server\node_modules\@medusajs\medusa\dist\api\middlewares\transform-query.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'invalid_data',
  code: undefined,
  date: 2023-05-11T16:55:00.020Z
}

Im on the latest versions 👀

burnt spear
#

variansts.prices.amount?

zenith crag
dense linden
#

how do you change the order if asc or desc?

dense linden
#

Also, does anyone of you encountered this where when I'm applying order param, the list is incomplete:

cobalt granite
#

add a minus

dense linden
# cobalt granite

thanks @cobalt granite , yea able to find that documentation last minute. Although I'm having problem when sort order is applied where data list is incomplete.

cobalt granite
#

The count should be 12 by the way

#

Weird

#

Is it the same in postman?

#

You're not doing any filtering before console.logging?

dense linden
#

this is the log from the chrom dev tools (network)

dense linden
cobalt granite
#

What is the exact query you're running?

cobalt granite
#

I have the same issue

cobalt granite
#

If I start increasing limit to a number that is higher than the actual products in database, it's starting to return more