craftcms / shopify

Synchronize and extend product data from your Shopify storefront.
MIT License
45 stars 25 forks source link

Unable to define fixed order on product query #79

Closed russback closed 11 months ago

russback commented 1 year ago

Description

When passing an array of shopifyIds, the returned order does not match the order of the array of IDs passed. When adding fixedOrder(true), no results are returned.

This does not return products in the order the of the productIds array passed:

{% set products = craft.shopifyProducts.shopifyId(productIds).collect %}

This returns no results:

{% set products = craft.shopifyProducts.shopifyId(productIds).fixedOrder(true).collect %}

Steps to reproduce

  1. Pass productIds in an order that is different to the default order products are stored in Craft.

Additional info

lukeholder commented 11 months ago

You should be able to do:

{% set products = craft.shopifyProducts
  .shopifyProductId(productIds)
  .orderBy(create(
    'craft\\db\\FixedOrderExpression',
    ['shopify_products.shopifyId', productIds, craft.app.db]
  )).collect()
%}

If we get other people asking for this, I will look into it. Thanks!

mdominguez commented 9 months ago

Would also like this! Would be cool if we could drag the order with the 4 dots like entries in a structure?

russback commented 7 months ago

@lukeholder just coming back to this as the project has been on hold.

With that query I'm getting this error:

Twig Runtime Error – [Twig\Error\RuntimeError](http://twig.sensiolabs.org/api/2.x/Twig/Error/RuntimeError.html)
Calling unknown method: craft\shopify\elements\db\ProductQuery::shopifyProductId()