Skip to content

feat: ship_postcode wire-through for FedEx ODA#116

Open
ecommeanblvd wants to merge 3 commits into
mainfrom
feat/ship-postcode
Open

feat: ship_postcode wire-through for FedEx ODA#116
ecommeanblvd wants to merge 3 commits into
mainfrom
feat/ship-postcode

Conversation

@ecommeanblvd

Copy link
Copy Markdown
Owner

Tóm tắt

Engine + DB schema đã có sẵn logic match postcode → ODA tier (Tier A flat, Tier B/C max-of-two). Nhưng các caller chưa truyền postcode vào engine — bug làm engine UNDER-quote 30 % đơn FedEx có ODA (mất ~550-735k VND mỗi đơn).

Changes

  • db/0032: shopify_orders.ship_postcode
  • GraphQL: bulk query thêm shippingAddress.zip
  • types + mapper: pass zip vào DB
  • resolve-shipping-estimate + batch-shipping-estimator: thêm shipPostcode input, forward vào quote()
  • reconcile: include ship_postcode trong join + quote call
  • callers (order-actions, dashboard-actions, verify-order-quote): forward order.shipPostcode

Operational

  1. ✅ Migration 0032 applied trên prod
  2. Existing 4000+ orders cần resync để populate ship_postcode — em sẽ chạy backfill sau khi PR merge (raw_payload chưa fetch zip lúc import lần đầu)
  3. 📦 New orders (webhook + cron sau merge) tự populate

Còn lại sau PR này

  • Anh nạp ODA postcode list cho SA / QA / AE / KW / BH / OM / JO / IL (8 nước ME) → em import → reconcile sẽ thấy Δ giảm mạnh
  • 42 nước hiện đã có postcode patterns (US, JP, MX, AU, CN…) — sau khi resync xong sẽ tự match

Test plan

  • pnpm tsc clean
  • pnpm test --run → 546/546 pass
  • Migration applied prod
  • Operator trigger resync orders trên prod sau merge

lmtiep added 3 commits June 3, 2026 18:12
Engine đã có sẵn logic match postcode → ODA tier (carrier_remote_postcodes
+ remote_fixed surcharge per Tier A/B/C). Nhưng các caller chưa
truyền postcode vào engine.

Code changes
------------
- db/0032: thêm shopify_orders.ship_postcode
- GraphQL bulk query: thêm shippingAddress.zip
- shopify-types + mapper: pass zip vào ship_postcode khi sync
- resolve-shipping-estimate (single-order modal):
  • EngineEstimateInput.shipPostcode
  • forward vào tryCarriers → quote
- batch-shipping-estimator (dashboard):
  • EngineEstimateInput.shipPostcode
  • memo key thêm pKey (postcode)
  • forward vào bestQuoteWithinCarrier → quote
- reconcile: include shipPostcode trong SELECT join + quote() call
- callers: order-actions, dashboard-actions, verify-order-quote
  forward order.shipPostcode

Operational
-----------
- Column ship_postcode applied trên prod ✓
- Existing 4000+ orders cần Shopify resync để populate (raw_payload
  chưa fetch zip ở thời điểm import lần đầu)
- New orders (via webhook + cron sau merge) sẽ tự populate

Test plan
---------
- [x] pnpm tsc clean
- [x] 546/546 tests pass
- [ ] Merge → operator chạy resync orders trên prod để populate
      ship_postcode cho 4000+ legacy orders
- [ ] (Sau khi anh nạp ODA postcode list cho SA/QA/AE/KW/BH/OM/JO/IL)
      → re-reconcile để verify Δ giảm
Backfill bulk operation fail với:
  Field 'title' doesn't exist on type 'ShippingLineConnection'

Shopify API 2025-01 yêu cầu shippingLines là connection — phải fetch
qua edges/node thay vì list trực tiếp:
  shippingLines { edges { node { title code } } }

Stream parser cũng cần update vì shippingLines giờ đến từ child rows
(JSONL bulk operation flatten connections via __parentId). Detect
shipping line bằng id prefix gid://shopify/ShippingLine/...

Verified bằng backfill mirermirer-official → 9 orders ingested clean.
… mới

Khi user nói "đừng sync orders cũ hơn vào DB", em build script này thay
vì backfill nguyên 1 năm. Chỉ:
  - SELECT orders ĐÃ có trong DB nhưng thiếu ship_postcode
  - Batch 50 IDs → GraphQL nodes(ids:) query Shopify
  - UPDATE ship_postcode = shippingAddress.zip

Idempotent + an toàn (không tạo orders mới).

Coverage trên prod sau khi chạy:
  meanblvd:            3460 / 4365 (79 %)
  tinhatelier:          573 /  726 (79 %)
  mirermirer-official:    7 /    9 (78 %)

905 + 153 + 2 orders Shopify trả về zip=null (digital, pickup, hoặc
khách không nhập zip) — không có cách populate ngoài việc thêm
manually.

Usage:
  tsx scripts/patch-postcodes.ts --store=<uuid> [--limit=N]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants