[ { "label": "Tag products in stock by location", "trigger_type": [ "product_created", "product_updated" ], "object_type": "product", "app_id": "triggers", "settings": { "priority": 0, "condition_groups": { "1": { "conditions": [], "actions": [ { "type": "product_add_tags", "settings": { "token_object_type": "product", "tags": "{# Set your location prefix here, such as \"LOCATION_\" or \"In stock at \"#}\r\n{% set prefix = \"AVAILABLE_AT_\" %}\r\n\r\n{% set tags = [] %}\r\n{% for key, value in product.inventory_quantity_by_location %}\r\n {% if value > 0 %}\r\n {% set tags = tags | merge([ prefix ~ shop.locations[key].name]) %}\r\n {% endif %}\r\n{% endfor %}\r\n{{ tags | join(', ') }}", "wait": "0", "cw_timezone": "America\/New_York", "custom_wait": "" }, "weight": 999, "target_key": "product" }, { "type": "product_remove_tags", "settings": { "wait": "0", "custom_wait": "", "tags": "{# Set your location prefix here, such as \"LOCATION_\" or \"In stock at \"#}\r\n{% set prefix = \"AVAILABLE_AT_\" %}\r\n\r\n{# Make a clean list (array) of all location names #}\r\n{% set location_names = [] %}\r\n{% for lid, value in shop.locations %}\r\n {% set location_names = location_names|merge([shop.locations[lid].name]) %}\r\n{% endfor %}\r\n\r\n{# Make a clean list of locations with stock available #}\r\n{% set stocked_at = [] %}\r\n{% for key, value in product.inventory_quantity_by_location %}\r\n {% if value > 0 %}\r\n {% set stocked_at = stocked_at | merge([shop.locations[key].name]) %}\r\n {% endif %}\r\n{% endfor %}\r\n\r\n{# Loop over the product's tags and make a list of any that deal with stock at a location and are invalid #}\r\n{% set removals = [] %}\r\n{% set clean_tag = \"\" %}\r\n{% for product_tag in product.tags_array %}\r\n {# workaround for Arigato interpreting the tag as an object for \"starts with\" #}\r\n {% set product_tag = product_tag.getValue() %}\r\n {% if product_tag starts with prefix %}\r\n {% set clean_tag = product_tag | replace({(prefix): \"\"}) %}\r\n {% if clean_tag not in stocked_at %}\r\n {% set removals = removals | merge([product_tag]) %} \r\n {% endif %} \r\n {% endif %} \r\n{% endfor %}\r\n\r\n{# Print out a list of removals #}\r\n{{ removals | join(\", \") }}" }, "weight": 999, "target_key": "product" } ] } }, "shared_workflow_id": 8730 }, "description": "This workflow makes it super easy to track the locations that currently have stock for a particular product. It works by checking if the inventory at a particular location has any stock and adds a tag for the respective location. You can customize this tag further by adding a custom prefix to the location name. If the quantity for a particular location falls below 0 then the tag is removed." } ]