medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.67k stars 2.43k forks source link

Sorting or Ordering the products by multiple columns is not possible #5314

Open bkvaiude opened 11 months ago

bkvaiude commented 11 months ago

Bug report

store/products?order=created_at&order=-size Order parameter doesn't have support to order product listing by multiple columns or properties

Describe the bug

In our use cases, on website we are listing the products in table list format where we want to allow user to sort products by multiple products properties

As shown in attached example, it seems medusa STORE APIs are having single column sorting or ordering

When I pass the multiple params in order request parameter, it results in 400 bad request

Expected behavior

order request parameter suppose to be access multiple columns as value with order preference and sort the result accordingly

Exact behaviour of following SELECT statement in RDBMS

Select * from products order by size desc, discount desc, price

Medusa API representation

  1. store/products?order=-size&order=-discount&order=price
  2. store/products?order=-size,-discount,price

Screenshots

image

Code snippets

Sample of CURL request

curl --location --request GET 'localhost:9000/store/products?order=created_at&order=-size' \ --header 'Content-Type: application/json' \ --data '{ "q": "Medusa" }'

bkvaiude commented 10 months ago

@olivermrbl Can you please help me out here?

bkvaiude commented 10 months ago

@shahednasser Can you please help me out here?

shahednasser commented 10 months ago

@bkvaiude it's not possible to order by multiple fields. You'll have to create a custom API route.