- tags
- #shop
shop-carts¶
Two flows about carts. A new cart tells the shop who's shopping. Abandoned carts runs once a day (a cron, declared in Init): any cart still open after 48 hours is marked abandoned, and its customer gets a friendly nudge.
A new cart¶
The trigger in Init hands this rule the new cart's key; it looks up the cart and its customer and sends one message.
$when shop.cartCreated (id: String) {
cart = dom.find(cls = "Cart", key = id)
who = dom.find(cls = "Customer", key = cart.customer)
payload = shop.notify(to = "admins", text = "New cart from ${who.name}")
}
Abandoned carts¶
hours is how long a cart may sit open; the cron sends 48. Each old cart goes through shop.abandon, one at a time, so the payload is the list of carts it abandoned.
$when shop.abandonedCarts (hours: Int) {
cut = toMillis(now()) - hours * 3600000
old = dom.list(cls = "Cart").data filter (c => c.status is "open" and toMillis(c.updated as Date) < cut)
payload = old map (c => shop.abandon(id = c.id))
}
$when shop.abandon (id: String) {
c = dom.find(cls = "Cart", key = id)
dom.upsert(cls = "Cart", entity = c + {status: "abandoned"})
who = dom.find(cls = "Customer", key = c.customer)
shop.notify(to = who.email, text = "Still thinking about it, ${who.name}? Your cart is waiting.")
payload = id
}