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

"Move out-of-stock products to the end of a collection" - inner loop clobbers result from outer loop #401

Closed
isaacbowen opened this issue Sep 17, 2024 · 1 comment
Assignees

Comments

@isaacbowen
Copy link
Member

isaacbowen commented Sep 17, 2024

There's a bit in this task where we're traversing two graphql pagination loops at once. Both loops are currently using the variable result to store the graphql query results, which breaks pagination for the outer loop.

{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"product": {
"variants": {
"nodes": [
{
"id": "gid://shopify/ProductVariant/1234567890",
"inventoryPolicy": "DENY",
"inventoryQuantity": 0
}
]
}
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% for variant in result.data.product.variants.nodes %}
{% if variant.inventoryPolicy == "CONTINUE" or variant.inventoryQuantity > 0 %}
{% assign has_in_stock_variant = true %}
{% break %}
{% endif %}
{% endfor %}
{% if result.data.products.variants.pageInfo.hasNextPage and has_in_stock_variant != true %}
{% assign variants_cursor = result.data.products.variants.pageInfo.endCursor %}

@tekhaus
Copy link
Collaborator

tekhaus commented Sep 17, 2024

Good catch, and a good reminder that there will likely be more loops in loops constructs in tasks as the 2K variants support approaches.

@tekhaus tekhaus closed this as completed Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants