Skip to content

feat(ecommerce): add orders, web shop, discount codes, sales analytics and store automation - #1549

Merged
sung17 merged 3 commits into
mainfrom
feat/ecommerce
Oct 24, 2026
Merged

sung17 merged 3 commits into
mainfrom
feat/ecommerce

Conversation

@sung17

@sung17 sung17 commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a native store to ChatbotX: orders, vendors, store settings, a customer web shop with cash-on-delivery checkout, discount codes, sales analytics, and selling inside chat (Messenger product collections, WhatsApp cart → order, product search by message).
  • Store activity drives automation: new trigger and webhook events, an abandoned-cart reminder, and purchase-based contact filters.
  • Agent-first: every operation has a public API procedure (CLI/MCP pick them up from the public spec). Full design in docs/ecommerce.md.

Changes

  • Database: one migration, packages/database/drizzle/20261023162208_ecommerce. It holds every ecommerce table and enum: EcommerceSettings, EcommerceOpenHours, EcommerceOrderCounter, Vendor, Order, OrderItem, OrderStatusHistory, Cart, DiscountCode, DiscountCodeRedemption.
    • It is last in the chain and joins both current leaves of main's snapshot chain.
    • It moves Product.vendor (free text) into Vendor rows with a hand-written backfill, run before the column is dropped.
    • db:check-drift is clean.
  • Business (packages/business): order, discount-code, webshop, ecommerce-settings, vendor, open-hours and ecommerce-analytics services.
    • All money is numeric(19,4), through packages/utils/src/money.ts.
    • Stock is taken under row locks and returned exactly, via OrderItem.stockTaken.
    • Status moves are guarded by ORDER_STATUS_TRANSITIONS.
    • Coupon limits are enforced under a lock.
  • Builder:
    • Ecommerce pages: Orders, Coupons, Products, Categories, Vendors, Analytics, Settings. A pinned shop-link bar gives the {{shop_token}} URL for flow buttons.
    • Public web shop at /shop/<workspaceId>.
    • New public routers: orders, discountCodes, productVendors, ecommerceSettings, openHours, ecommerceAnalytics, webshop, carts.
  • Flows / channels:
    • New sendCollection step, rendered as a carousel on Messenger.
    • A WhatsApp cartSent message creates the cart and replies with a CHECK OUT link.
  • Events / worker:
    • Trigger and webhook events: newOrder, orderAccepted/Shipped/Concluded/Cancelled, productOrdered, productAddedToCart/RemovedFromCart, categoryAddedToCart, cartAbandoned.
    • scanAbandonedCarts cron, guarded per cart with withBlockedOwnerGuard.
    • Order notifications to customers and members.
  • Contact filters: total spent, number of orders, last purchase, bought items, cart contents/value/empty.
  • i18n: all 21 locales.
  • Docs: docs/ecommerce.md, docs/product-messages.md, docs/flows.md, CLI README.

Invariant 23 exemption

The end-customer web shop (/shop/* pages and their server actions for cart, checkout, discount code and rating) is a customer-facing public page. It is authorised by the signed shop token, not a workspace token, so it has no public API procedure. Everything a merchant or agent does has one, including webshop.getLink, which returns the same shop link the UI copies.

Security notes

  • Shop tokens are encrypted and bound to their workspace (7 days; preview links 1 day and never order).
  • Merchant links (checkoutLink, productUrl) accept http(s) only, and are re-checked at render.
  • A frozen workspace (trial expired, scheduled for deletion) shows its shop but takes no orders.

Test plan

  • pnpm lint (includes db:check-drift)
  • check-types: database, business, worker, builder
  • pnpm test: database 1438, business 7571, worker 3922, builder 8457 — all passing
  • Full code review across orders/stock/coupons, web shop/security, events/cron, analytics/filters, and builder/API; confirmed findings fixed, with regression tests
  • db:migrate on a fresh database
  • Manual: place a web shop order (each checkout mode), apply a coupon, accept → conclude (COD becomes paid), cancel (stock returned)
  • Manual: Messenger collection step, WhatsApp cart → CHECK OUT, abandoned-cart reminder flow

…s and store automation

- Orders, vendors, open hours and store settings (COD, per-workspace order
  numbers, stock locking, status transitions) with public API.
- Customer web shop at /shop (signed shop token, cart, checkout, ratings)
  and order notifications for customers and members.
- Discount codes (percentage, fixed amount, free shipping; limits,
  once per customer, contact-filter eligibility, auto-apply).
- Sales analytics, Messenger product collection flow step, product search
  by message, store trigger/webhook events, abandoned-cart reminder cron
  and purchase contact filters.
- One migration (20261021152239_ecommerce) for all ecommerce tables.
@github-actions github-actions Bot added the feature New feature or request label Oct 23, 2026
…er-line stock taken

- Shop link (Public URL + preview) pinned to the bottom of every Ecommerce
  page; product edit page pins its own product link beside Save.
- webshop.getLink accepts productId; Select inputs show option labels.
- Order confirmation mode (default / flow / none) in store settings.
- OrderItem.stockTaken so a cancel or delete returns exactly what was taken.
- Web shop polish: loading skeletons, image carousel, related products,
  coupon ticket, checkout and bottom bars, shop locale.

- All ecommerce tables in one migration, 20261023162208_ecommerce, last in
  the chain after main's latest migrations.
… cards

Meta refuses a whole carousel over one bad URL, so a product link or image
that is not an http(s) URL is left off the card: Buy falls back to the
product's shop page and the card goes without its image. toSafeWebUrl moves
to @chatbotx.io/utils so the web shop and the cards share one check.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@sung17
sung17 merged commit 270eb50 into main Oct 24, 2026
4 checks passed
@sung17 sung17 mentioned this pull request Oct 26, 2026
1 task done
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
…s and store automation (#1549)

* feat(ecommerce): add orders, web shop, discount codes, sales analytics and store automation

- Orders, vendors, open hours and store settings (COD, per-workspace order
  numbers, stock locking, status transitions) with public API.
- Customer web shop at /shop (signed shop token, cart, checkout, ratings)
  and order notifications for customers and members.
- Discount codes (percentage, fixed amount, free shipping; limits,
  once per customer, contact-filter eligibility, auto-apply).
- Sales analytics, Messenger product collection flow step, product search
  by message, store trigger/webhook events, abandoned-cart reminder cron
  and purchase contact filters.
- One migration (20261021152239_ecommerce) for all ecommerce tables.

* feat(ecommerce): pin shop link bar, add order confirmation mode and per-line stock taken

- Shop link (Public URL + preview) pinned to the bottom of every Ecommerce
  page; product edit page pins its own product link beside Save.
- webshop.getLink accepts productId; Select inputs show option labels.
- Order confirmation mode (default / flow / none) in store settings.
- OrderItem.stockTaken so a cancel or delete returns exactly what was taken.
- Web shop polish: loading skeletons, image carousel, related products,
  coupon ticket, checkout and bottom bars, shop locale.

- All ecommerce tables in one migration, 20261023162208_ecommerce, last in
  the chain after main's latest migrations.

* fix(ecommerce): drop non-web product links and images from collection cards

Meta refuses a whole carousel over one bad URL, so a product link or image
that is not an http(s) URL is left off the card: Buy falls back to the
product's shop page and the card goes without its image. toSafeWebUrl moves
to @chatbotx.io/utils so the web shop and the cards share one check.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Deathgiver <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant