Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to define fixed order on product query #79

Closed
russback opened this issue Sep 15, 2023 · 3 comments
Closed

Unable to define fixed order on product query #79

russback opened this issue Sep 15, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@russback
Copy link

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

  • Craft version: 4.5.4
  • PHP version: 8.2
  • Database driver & version: mysql
  • Plugins & versions: craftcms/shopify 3.2.0
@russback russback added the bug Something isn't working label Sep 15, 2023
@lukeholder lukeholder self-assigned this Nov 1, 2023
@lukeholder
Copy link
Member

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
Copy link

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

@russback
Copy link
Author

russback commented Feb 8, 2024

@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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants