[ { "label": "Custom action: auto create and add items to collections from the product vendor", "trigger_type": [ "product_updated", "product_created" ], "object_type": "product", "app_id": "triggers", "settings": { "priority": 0, "condition_groups": { "1": { "conditions": { "1": { "field": "product.vendor", "settings": { "operator": "not_empty", "value": "", "long_value": "", "token_object_type": "product", "condition_type": "AND" }, "weight": 999 } }, "actions": { "1": { "type": "custom", "settings": { "token_object_type": "product", "label": "", "twig": "{% set vendor_collection = \"vendor=\"~product.vendor %}\r\n{% set fetched_collection = RUN_ACTION(\"shopify_api_request\", {\r\n method: \"GET\",\r\n path: \"custom_collections\",\r\n data: {title: vendor_collection},\r\n }) %}\r\n \r\n {% if fetched_collection.response.custom_collections[0].id is defined %}\r\n {% do QUEUE_ACTION(\"product_add_to_collections\", {\r\n resource: product,\r\n collection_ids: [fetched_collection.response.custom_collections[0].id]\r\n }) %} \r\n {% else %}\r\n {% set created_collection = RUN_ACTION(\"shopify_api_request\", {\r\n method: \"POST\",\r\n path: \"custom_collections\",\r\n data: {\r\n \"custom_collection\": {\r\n \"title\": vendor_collection, \r\n \"published\": false,\r\n \"metafields\": [\r\n {\r\n \"key\": \"collection_type\",\r\n \"value\": \"vendor\",\r\n \"type\": \"string\",\r\n \"namespace\": \"global\"\r\n }\r\n ]\r\n }\r\n }\r\n }) %}\r\n {% do QUEUE_ACTION(\"product_add_to_collections\", {\r\n resource: product,\r\n collection_ids: [created_collection.response.custom_collection.id]\r\n }) %} \r\n {% endif %}\r\n\r\n\r\n\r\n", "wait": "0", "cw_timezone": "Europe\/London", "custom_wait": "" }, "weight": 30, "target_key": "product" } } } }, "shared_workflow_id": 37333 }, "description": "This automation will create a collection named after the product's vendor and add the product to the collection." } ]