forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraise-the-price-of-a-product-after-every-sale.json
22 lines (22 loc) · 1.95 KB
/
raise-the-price-of-a-product-after-every-sale.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"docs": "This task monitors purchases for a specific product ID, and raises the price every time it's purchased, by the amount that you specify. (To be specific, this task will raise the price on the _individual variant_ that was purchased.)\r\n\r\nConfigure this task with the ID of the product you want to monitor. Find the product ID by opening the product in the Shopify admin, and using the numbers at the very end of the URL in your browser. For example, the product at `https://example.myshopify.com/admin/products/1234567890` would have a product ID of `1234567890`.",
"halt_action_run_sequence_on_error": false,
"name": "Raise the price of a product after every sale",
"online_store_javascript": null,
"options": {
"product_id__required_number": null,
"increase_price_by_this_much__number_required": null,
"maximum_price__number": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% assign purchased_variant = nil %}\n{% for line_item in order.line_items %}\n {% if line_item.product_id == options.product_id__required_number %}\n {% assign purchased_variant = line_item.variant %}\n {% break %}\n {% endif %}\n{% endfor %}\n\n{% if event.preview or purchased_variant %}\n {% assign next_price = purchased_variant.price | plus: options.increase_price_by_this_much__number_required %}\n\n {% unless event.preview != true and options.maximum_price__number != blank and next_price > options.maximum_price__number %}\n {\n \"action\": {\n \"type\": \"shopify\",\n \"options\": [\n \"update\",\n [\n \"variant\",\n {{ purchased_variant.id | json }}\n ],\n {\n \"price\": {{ next_price | json }}\n }\n ]\n }\n }\n {% endunless %}\n{% endif %}",
"subscriptions": [
"shopify/orders/paid"
],
"subscriptions_template": "shopify/orders/paid",
"tags": [
"Price",
"Products"
]
}