Skip to content

Commit

Permalink
Fix/api changes (#409)
Browse files Browse the repository at this point in the history
* switch to fulfillmentCreate

* fix for productUpdate input
  • Loading branch information
tekhaus authored Oct 9, 2024
1 parent 327ce9a commit 3f76a44
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 55 deletions.
60 changes: 13 additions & 47 deletions docs/auto-fulfill-items-that-dont-require-shipping/script.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
lineItems(first: 30) {
nodes {
id
inventoryItemId
remainingQuantity
requiresShipping
variant {
product {
tags
}
}
}
}
}
Expand Down Expand Up @@ -56,15 +60,13 @@
"nodes": [
{
"id": "gid://shopify/FulfillmentOrderLineItem/1234567890",
"inventoryItemId": "gid://shopify/InventoryItem/1234567890",
"remainingQuantity": 1,
"requiresShipping": false
},
{
"id": "gid://shopify/FulfillmentOrderLineItem/2345678901",
"inventoryItemId": "gid://shopify/InventoryItem/2345678901",
"remainingQuantity": 2,
"requiresShipping": false
"requiresShipping": false,
"variant": {
"product": {
"tags": {{ inclusion_tags.first | json }}
}
}
}
]
}
Expand Down Expand Up @@ -114,43 +116,7 @@
{% assign has_exclusion_tag = nil %}
{% assign has_inclusion_tag = nil %}

{% comment %}
-- use the inventory item Id to query for product tags; product access from fulfillment order line items has been deprecated
{% endcomment %}

{% capture query %}
query {
inventoryItem(id: {{ fulfillment_order_line_item.inventoryItemId | json }}) {
variant {
product {
tags
}
}
}
}
{% endcapture %}

{% assign result = query | shopify %}

{% if event.preview %}
{% capture result_json %}
{
"data": {
"inventoryItem": {
"variant": {
"product": {
"tags": {{ inclusion_tags.first | json }}
}
}
}
}
}
{% endcapture %}

{% assign result = result_json | parse_json %}
{% endif %}

{% assign product_tags = result.data.inventoryItem.variant.product.tags %}
{% assign product_tags = fulfillment_order_line_item.variant.product.tags %}

{% for exclusion_tag in exclusion_tags %}
{% if product_tags contains exclusion_tag %}
Expand Down Expand Up @@ -226,7 +192,7 @@
{% for keyval in fulfillment_orders_by_location %}
{% action "shopify" %}
mutation {
fulfillmentCreateV2(
fulfillmentCreate(
fulfillment: {
lineItemsByFulfillmentOrder: [
{% for fulfillment_order_data in keyval[1] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
{% for keyval in fulfillment_order_ids_by_location_and_type %}
{% action "shopify" %}
mutation {
fulfillmentCreateV2(
fulfillmentCreate(
fulfillment: {
lineItemsByFulfillmentOrder: [
{% for fulfillment_order_id in keyval[1] %}
Expand Down
2 changes: 1 addition & 1 deletion docs/set-product-types-by-title-keywords/script.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
{% action "shopify" %}
mutation {
productUpdate(
input: {
product: {
id: {{ product.id | json }}
productType: {{ product_type_to_set | json }}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
{% action "shopify" %}
mutation {
productUpdate(
input: {
product: {
id: {{ product.id | json }}
descriptionHtml: {{ cached_description_html | json }}
}
Expand All @@ -170,7 +170,7 @@
{% action "shopify" %}
mutation {
productUpdate(
input: {
product: {
id: {{ product.id | json }}
descriptionHtml: {{ updated_description_html | json }}
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/auto-fulfill-items-that-dont-require-shipping.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign inclusion_tags = options.include_products_with_any_of_these_tags__array %}\n{% assign exclusion_tags = options.exclude_products_with_any_of_these_tags__array %}\n{% assign wait_until_any_other_shippable_items_are_fulfilled = options.wait_until_any_other_shippable_items_are_fulfilled__boolean %}\n\n{% comment %}\n -- get all open or in progress fulfillment orders\n{% endcomment %}\n\n{% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n fulfillmentOrders(\n first: 10\n query: \"status:open OR status:in_progress\"\n ) {\n nodes {\n id\n assignedLocation {\n location {\n id\n }\n }\n lineItems(first: 30) {\n nodes {\n id\n inventoryItemId\n remainingQuantity\n requiresShipping\n }\n }\n }\n }\n }\n }\n{% endcapture %}\n\n{% assign result = query | shopify %}\n\n{% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"order\": {\n \"id\": \"gid://shopify/Order/1234567890\",\n \"fulfillmentOrders\": {\n \"nodes\": [\n {\n \"id\": \"gid://shopify/FulfillmentOrder/1234567890\",\n \"assignedLocation\": {\n \"location\": {\n \"id\": \"gid://shopify/Location/1234567890\"\n }\n },\n \"lineItems\": {\n \"nodes\": [\n {\n \"id\": \"gid://shopify/FulfillmentOrderLineItem/1234567890\",\n \"inventoryItemId\": \"gid://shopify/InventoryItem/1234567890\",\n \"remainingQuantity\": 1,\n \"requiresShipping\": false\n },\n {\n \"id\": \"gid://shopify/FulfillmentOrderLineItem/2345678901\",\n \"inventoryItemId\": \"gid://shopify/InventoryItem/2345678901\",\n \"remainingQuantity\": 2,\n \"requiresShipping\": false\n }\n ]\n }\n }\n ]\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n{% endif %}\n\n{% assign fulfillment_orders = result.data.order.fulfillmentOrders.nodes %}\n\n{% if fulfillment_orders == blank %}\n {% log \"There are no open fulfillment orders to fulfill on this order.\" %}\n {% break %}\n{% endif %}\n\n{% comment %}\n NOTE: fulfillments can only be created for one location at a time, so need to group fulfillment orders by location\n{% endcomment %}\n\n{% assign fulfillment_orders_by_location = hash %}\n{% assign has_unfulfilled_shippable_items = nil %}\n\n{% for fulfillment_order in fulfillment_orders %}\n {% assign fulfillment_order_data = hash %}\n {% assign fulfillment_order_data[\"fulfillment_order_id\"] = fulfillment_order.id %}\n\n {% for fulfillment_order_line_item in fulfillment_order.lineItems.nodes %}\n {% comment %}\n -- skip items that do not require shipping, but set flag if any are unfulfilled\n {% endcomment %}\n\n {% if fulfillment_order_line_item.requiresShipping %}\n {% if fulfillment_order_line_item.remainingQuantity > 0 %}\n {% assign has_unfulfilled_shippable_items = true %}\n {% endif %}\n\n {% continue %}\n {% endif %}\n\n {% if inclusion_tags != blank or exclusion_tags != blank %}\n {% assign has_exclusion_tag = nil %}\n {% assign has_inclusion_tag = nil %}\n\n {% comment %}\n -- use the inventory item Id to query for product tags; product access from fulfillment order line items has been deprecated\n {% endcomment %}\n\n {% capture query %}\n query {\n inventoryItem(id: {{ fulfillment_order_line_item.inventoryItemId | json }}) {\n variant {\n product {\n tags\n }\n }\n }\n }\n {% endcapture %}\n \n {% assign result = query | shopify %}\n \n {% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"inventoryItem\": {\n \"variant\": {\n \"product\": {\n \"tags\": {{ inclusion_tags.first | json }}\n }\n }\n }\n }\n }\n {% endcapture %}\n \n {% assign result = result_json | parse_json %}\n {% endif %}\n \n {% assign product_tags = result.data.inventoryItem.variant.product.tags %}\n\n {% for exclusion_tag in exclusion_tags %}\n {% if product_tags contains exclusion_tag %}\n {% assign has_exclusion_tag = true %}\n {% break %}\n {% endif %}\n {% endfor %}\n\n {% for inclusion_tag in inclusion_tags %}\n {% if product_tags contains inclusion_tag %}\n {% assign has_inclusion_tag = true %}\n {% break %}\n {% endif %} \n {% endfor %}\n\n {% comment %}\n -- exclusion tags have priority over inclusion tags\n {% endcomment %}\n\n {% if has_exclusion_tag %}\n {% log\n message: \"This line item's product has at least one of the configured exclusion tags; skipping\",\n fulfillment_order_line_item: fulfillment_order_line_item,\n product_tags: product_tags,\n exclusion_tags: exclusion_tags\n %}\n {% continue %}\n\n {% elsif inclusion_tags != blank %}\n {% unless has_inclusion_tag %}\n {% log\n message: \"This line item's product does not contain any of the configured inclusion tags; skipping\",\n fulfillment_order_line_item: fulfillment_order_line_item,\n product_tags: product_tags,\n inclusion_tags: inclusion_tags\n %}\n {% continue %}\n {% endunless %}\n {% endif %}\n {% endif %}\n\n {% comment %}\n -- save unfulfilled line items that do not require shipping\n {% endcomment %}\n\n {% if fulfillment_order_line_item.remainingQuantity > 0 %}\n {% assign fulfillment_order_data[\"unfulfilled_line_items\"]\n = fulfillment_order_data[\"unfulfilled_line_items\"]\n | default: array\n | push: fulfillment_order_line_item\n %}\n {% endif %}\n {% endfor %}\n\n {% comment %}\n -- group unfulfilled line items by location for fulfillment\n {% endcomment %}\n\n {% if fulfillment_order_data.unfulfilled_line_items != blank %}\n {% assign fulfillment_orders_by_location[fulfillment_order.assignedLocation.location.id]\n = fulfillment_orders_by_location[fulfillment_order.assignedLocation.location.id]\n | default: array\n | push: fulfillment_order_data\n %}\n {% endif %}\n{% endfor %}\n\n{% if wait_until_any_other_shippable_items_are_fulfilled and has_unfulfilled_shippable_items %}\n {% log \"Unfulfilled shippable items exist on this order and the 'Wait until any other shippable items are fulfilled' option is checked; no auto fulfillments will be made in this task run.\" %}\n {% break %}\n{% endif %}\n\n{% for keyval in fulfillment_orders_by_location %}\n {% action \"shopify\" %}\n mutation {\n fulfillmentCreateV2(\n fulfillment: {\n lineItemsByFulfillmentOrder: [\n {% for fulfillment_order_data in keyval[1] %}\n {\n fulfillmentOrderId: {{ fulfillment_order_data.fulfillment_order_id | json }}\n fulfillmentOrderLineItems: [\n {% for unfulfilled_line_item in fulfillment_order_data.unfulfilled_line_items %}\n {\n id: {{ unfulfilled_line_item.id | json }}\n quantity: {{ unfulfilled_line_item.remainingQuantity }}\n }\n {% endfor %}\n ]\n }\n {% endfor %}\n ]\n notifyCustomer: false\n }\n ) {\n fulfillment {\n id\n status\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n{% endfor %}",
"script": "{% assign inclusion_tags = options.include_products_with_any_of_these_tags__array %}\n{% assign exclusion_tags = options.exclude_products_with_any_of_these_tags__array %}\n{% assign wait_until_any_other_shippable_items_are_fulfilled = options.wait_until_any_other_shippable_items_are_fulfilled__boolean %}\n\n{% comment %}\n -- get all open or in progress fulfillment orders\n{% endcomment %}\n\n{% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n fulfillmentOrders(\n first: 10\n query: \"status:open OR status:in_progress\"\n ) {\n nodes {\n id\n assignedLocation {\n location {\n id\n }\n }\n lineItems(first: 30) {\n nodes {\n id\n remainingQuantity\n requiresShipping\n variant {\n product {\n tags\n }\n }\n }\n }\n }\n }\n }\n }\n{% endcapture %}\n\n{% assign result = query | shopify %}\n\n{% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"order\": {\n \"id\": \"gid://shopify/Order/1234567890\",\n \"fulfillmentOrders\": {\n \"nodes\": [\n {\n \"id\": \"gid://shopify/FulfillmentOrder/1234567890\",\n \"assignedLocation\": {\n \"location\": {\n \"id\": \"gid://shopify/Location/1234567890\"\n }\n },\n \"lineItems\": {\n \"nodes\": [\n {\n \"id\": \"gid://shopify/FulfillmentOrderLineItem/1234567890\",\n \"remainingQuantity\": 1,\n \"requiresShipping\": false,\n \"variant\": {\n \"product\": {\n \"tags\": {{ inclusion_tags.first | json }}\n }\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n{% endif %}\n\n{% assign fulfillment_orders = result.data.order.fulfillmentOrders.nodes %}\n\n{% if fulfillment_orders == blank %}\n {% log \"There are no open fulfillment orders to fulfill on this order.\" %}\n {% break %}\n{% endif %}\n\n{% comment %}\n NOTE: fulfillments can only be created for one location at a time, so need to group fulfillment orders by location\n{% endcomment %}\n\n{% assign fulfillment_orders_by_location = hash %}\n{% assign has_unfulfilled_shippable_items = nil %}\n\n{% for fulfillment_order in fulfillment_orders %}\n {% assign fulfillment_order_data = hash %}\n {% assign fulfillment_order_data[\"fulfillment_order_id\"] = fulfillment_order.id %}\n\n {% for fulfillment_order_line_item in fulfillment_order.lineItems.nodes %}\n {% comment %}\n -- skip items that do not require shipping, but set flag if any are unfulfilled\n {% endcomment %}\n\n {% if fulfillment_order_line_item.requiresShipping %}\n {% if fulfillment_order_line_item.remainingQuantity > 0 %}\n {% assign has_unfulfilled_shippable_items = true %}\n {% endif %}\n\n {% continue %}\n {% endif %}\n\n {% if inclusion_tags != blank or exclusion_tags != blank %}\n {% assign has_exclusion_tag = nil %}\n {% assign has_inclusion_tag = nil %}\n\n {% assign product_tags = fulfillment_order_line_item.variant.product.tags %}\n\n {% for exclusion_tag in exclusion_tags %}\n {% if product_tags contains exclusion_tag %}\n {% assign has_exclusion_tag = true %}\n {% break %}\n {% endif %}\n {% endfor %}\n\n {% for inclusion_tag in inclusion_tags %}\n {% if product_tags contains inclusion_tag %}\n {% assign has_inclusion_tag = true %}\n {% break %}\n {% endif %} \n {% endfor %}\n\n {% comment %}\n -- exclusion tags have priority over inclusion tags\n {% endcomment %}\n\n {% if has_exclusion_tag %}\n {% log\n message: \"This line item's product has at least one of the configured exclusion tags; skipping\",\n fulfillment_order_line_item: fulfillment_order_line_item,\n product_tags: product_tags,\n exclusion_tags: exclusion_tags\n %}\n {% continue %}\n\n {% elsif inclusion_tags != blank %}\n {% unless has_inclusion_tag %}\n {% log\n message: \"This line item's product does not contain any of the configured inclusion tags; skipping\",\n fulfillment_order_line_item: fulfillment_order_line_item,\n product_tags: product_tags,\n inclusion_tags: inclusion_tags\n %}\n {% continue %}\n {% endunless %}\n {% endif %}\n {% endif %}\n\n {% comment %}\n -- save unfulfilled line items that do not require shipping\n {% endcomment %}\n\n {% if fulfillment_order_line_item.remainingQuantity > 0 %}\n {% assign fulfillment_order_data[\"unfulfilled_line_items\"]\n = fulfillment_order_data[\"unfulfilled_line_items\"]\n | default: array\n | push: fulfillment_order_line_item\n %}\n {% endif %}\n {% endfor %}\n\n {% comment %}\n -- group unfulfilled line items by location for fulfillment\n {% endcomment %}\n\n {% if fulfillment_order_data.unfulfilled_line_items != blank %}\n {% assign fulfillment_orders_by_location[fulfillment_order.assignedLocation.location.id]\n = fulfillment_orders_by_location[fulfillment_order.assignedLocation.location.id]\n | default: array\n | push: fulfillment_order_data\n %}\n {% endif %}\n{% endfor %}\n\n{% if wait_until_any_other_shippable_items_are_fulfilled and has_unfulfilled_shippable_items %}\n {% log \"Unfulfilled shippable items exist on this order and the 'Wait until any other shippable items are fulfilled' option is checked; no auto fulfillments will be made in this task run.\" %}\n {% break %}\n{% endif %}\n\n{% for keyval in fulfillment_orders_by_location %}\n {% action \"shopify\" %}\n mutation {\n fulfillmentCreate(\n fulfillment: {\n lineItemsByFulfillmentOrder: [\n {% for fulfillment_order_data in keyval[1] %}\n {\n fulfillmentOrderId: {{ fulfillment_order_data.fulfillment_order_id | json }}\n fulfillmentOrderLineItems: [\n {% for unfulfilled_line_item in fulfillment_order_data.unfulfilled_line_items %}\n {\n id: {{ unfulfilled_line_item.id | json }}\n quantity: {{ unfulfilled_line_item.remainingQuantity }}\n }\n {% endfor %}\n ]\n }\n {% endfor %}\n ]\n notifyCustomer: false\n }\n ) {\n fulfillment {\n id\n status\n }\n userErrors {\n field\n message\n }\n }\n }\n {% endaction %}\n{% endfor %}\n",
"subscriptions": [
"shopify/orders/paid",
"mechanic/user/order"
Expand Down
Loading

0 comments on commit 3f76a44

Please sign in to comment.