feat: ship_postcode wire-through for FedEx ODA#116
Open
ecommeanblvd wants to merge 3 commits into
Open
Conversation
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
shopify_orders.ship_postcodeshippingAddress.zipshipPostcodeinput, forward vàoquote()ship_postcodetrong join + quote callorder.shipPostcodeOperational
ship_postcode— em sẽ chạy backfill sau khi PR merge (raw_payload chưa fetch zip lúc import lần đầu)Còn lại sau PR này
Test plan
pnpm tsccleanpnpm test --run→ 546/546 pass