[ { "label": "Tag products in stock by location", "trigger_type": [ "product_created", "product_updated" ], "object_type": "product", "app_id": "triggers", "settings": { "condition_groups": { "1": { "conditions": [], "actions": [ { "type": "product_add_tags", "settings": { "wait": "0", "custom_wait": "", "check_date": [], "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(', ') }}" }, "weight": 999, "target_key": "product" }, { "type": "product_remove_tags", "settings": { "wait": "0", "custom_wait": "", "check_date": [], "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 } } ]