[SOLVED] Sort products by price in Sylius REST API

please how do I enable sorting by price in Sylius REST API?

I tried to override Product grid in AdminApiBundle by adding new field:

        type: int
        sortable: channelPricing.price

So I basically just copied this field from Product grid definition in ShopBundle.

But now I’m getting this error:

"[Semantical Error] line 0, col 146 near 'channelPricing.price': Error: 'channelPricing' is not defined."

Where & how should I define channelPricing?

Besides adding the field to the grid, you need to have it in the query builder.
See how it’s done for the shop bundle’s product grid

It uses Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository::createShopListQueryBuilder where the following lines allow filtering by price:

// Grid hack, we do not need to join these if we don't sort by price
    if (isset($sorting['price'])) {
            ->innerJoin('o.variants', 'variant')
            ->innerJoin('variant.channelPricings', 'channelPricing')
            ->andWhere('channelPricing.channelCode = :channelCode')
            ->setParameter('channelCode', $channel->getCode())

got it! Thank you :slight_smile: