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

Does craft.shopifyProducts.shopifyId() work with fixedOrder? #98

Closed
AmandaLutzTO opened this issue Mar 22, 2024 · 3 comments
Closed

Does craft.shopifyProducts.shopifyId() work with fixedOrder? #98

AmandaLutzTO opened this issue Mar 22, 2024 · 3 comments
Labels
bug Something isn't working Plugins → Shopify For Linear sync Plugins For Linear sync

Comments

@AmandaLutzTO
Copy link

Description

I've successfully used craft.shopify.api.get to get all of the products belonging to a Shopify Collection (https://shopify.dev/docs/api/admin-rest/2023-10/resources/collection#get-collections-collection-id-products). In the Shopify admin, the Collections have the products in order of "Best selling".

I can loop through all the products returned by the api to build an array of ids but I want them displayed in that order, not the current postDate DESC.

I've tried fixedOrder (https://craftcms.com/docs/4.x/entries.html#fixedorder) but returns an empty result set.

Steps to reproduce

  1. craft.shopify.api.get to get all of the products belonging to a Shopify Collection
  2. loop through all the products returned by the api
  3. build an array of ids
  4. are displayed postDate DESC
  5. add fixedOrder to craft.shopifyProducts.shopifyId() query
  6. returns empty result set

Additional info

  • Craft version: 4.8.4
  • PHP version: 8.1.8
  • Database driver & version: MySQL 8.0.32
  • Plugins & versions: Shopify 4.1.0
@AmandaLutzTO AmandaLutzTO added bug Something isn't working Plugins For Linear sync Plugins → Shopify For Linear sync labels Mar 22, 2024
Copy link

linear bot commented Mar 22, 2024

@nfourtythree
Copy link
Contributor

Hi @AmandaLutzTO

This is possible to do, but when using the fixedOrder param you must use the id() criteria to be able to set the order. This id is the element id in Craft.

As you identified you can retrieve the products from the Shopify collection and then query for them using the shopifyId to get the corresponding Craft element ID. Once you have built this array of IDs you can then pass them into the Shopify products query as follows:

{# Where `ids` is a pre-built array of element IDs #}
{% set ids = [123, 456] %}
{% set products = craft.shopifyProducts.id(ids).fixedOrder().all() %}

Hope this helps, thanks!

@AmandaLutzTO
Copy link
Author

Exactly what I was missing. Thanks.

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

No branches or pull requests

2 participants