Skip to content

Latest commit

 

History

History

demonstration-trigger-a-custom-event-for-specific-product-or-variant-changes

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Demonstration: Trigger a custom event for specific product or variant changes

Tags: Demonstration, Products, Variants, Watch

This demonstration task responds to product updates, by firing a custom event whenever it finds that any of the configured product and variant attributes have changed from a cached snapshot. This is useful for creating custom tasks without having to continually build the scaffolding of a specific attribute monitor in each of them.

Default options

{
  "custom_event_topic__required": "user/product/update_monitor",
  "product_attributes_to_monitor__array": [
    "title"
  ],
  "variant_attributes_to_monitor__array": [
    "price",
    "sku"
  ]
}

Learn about task options in Mechanic

Subscriptions

shopify/products/update
mechanic/user/trigger
shopify/products/create

Learn about event subscriptions in Mechanic

Documentation

This demonstration task responds to product updates, by firing a custom event whenever it finds that any of the configured product and variant attributes have changed from a cached snapshot. This is useful for creating custom tasks without having to continually build the scaffolding of a specific attribute monitor in each of them.

Configure it with your custom event topic and a combination of product and/or variant attributes as desired. This task uses the GraphQL representation of the Product and Variant resources, and will only be able to interpet fields that return a single value at those two resource levels. This means you will not be able to enter connections to other resources (e.g. metafields) or fields that have subfields (e.g. featuredImage).

This demonstration task has been preconfigured with a custom event topic of user/product/update_monitor, title as the product attribute to monitor, and price and sku as the variant attributes to monitor.

To build custom tasks to respond to the custom events generated by this task, make sure to subscribe to the custom event topic that has been configured in this task. When firing the custom event, the current product resource will be sent along as the event data. This will include all of the configured attributes to monitor, but no other fields besides the IDs.

Important Notes:

  • This task will not send along the previous product resource values, as the cached snapshot is hashed for comparison, without explicitly storing the field values themselves.
  • The GraphQL resource field names entered in as attributes to monitor must match the Shopify documentation exactly (case-sensitive).
  • After changing any of the attributes to monitor in the config of this task, run the task manually to have it cache the snapshot value for all products in the shop.
  • The task has an arbitraty limit of 25k products that it will paginate through. If your shop has more than that, or a very large amount of variants (and you are tracking changes to them), then consider converting this task to use bulk operations for the manual runs instead.

Installing this task

Find this task in the library at tasks.mechanic.dev, and use the "Try this task" button. Or, import this task's JSON export – see Importing and exporting tasks to learn how imports work.

Contributions

Found a bug? Got an improvement to add? Start here: ../../CONTRIBUTING.md.

Task requests

Submit your task requests for consideration by the Mechanic community, and they may be chosen for development and inclusion in the task library!