Skip to content

fix: filter out cross-app products in cart sync - #729

Open
Hsu-Pei-Chun wants to merge 1 commit into
developfrom
fix/cart-sync-filter-out-cross-app-invalid-products-on-checkout
Open

fix: filter out cross-app products in cart sync#729
Hsu-Pei-Chun wants to merge 1 commit into
developfrom
fix/cart-sync-filter-out-cross-app-invalid-products-on-checkout

Conversation

@Hsu-Pei-Chun

Copy link
Copy Markdown
Contributor

問題描述

購物車在 sync 時,會將 localStorage 和 DB 的商品合併,但沒有驗證商品是否屬於當前 app。當 cart_product 表中存在跨 app 的商品(例如 cw 的方案出現在 demo 的購物車),這些商品:

  1. 前端 UI 不會顯示(被 _removePhaseOutCartProducts 過濾掉)
  2. 但仍然保留在 DB 和 localStorage 中
  3. 結帳時全部送給 checkout-order API
  4. 後端查不到跨 app 的方案 → 回傳 E_CHECKOUT_ORDER「找不到方案」→ 整批失敗
  5. 前端 totalPrice = 0,無法結帳

修改內容

CartOperator.syncCartProducts 中新增 filterByValidProductIds,利用 Hasura row-level permissions 的特性來判斷商品是否屬於當前 app:

  • product GraphQL 查詢中加入 product_owner.member.app_id
  • 跨 app 商品的 product_ownerproduct_owner.member 會是 null(被 Hasura 權限過濾)
  • sync 時自動移除這些無效商品,不寫回 DB 和 localStorage

影響範圍

  • src/services/cart/CartOperator.ts
    • syncCartProducts:使用 filterByValidProductIds 過濾後再寫入
    • _createGetCartProductOperationQueryproduct 查詢新增 product_owner { member { app_id } }
    • 新增 filterByValidProductIds 函數

測試方式

  1. cart_product 表中加入跨 app 的商品
  2. 開啟購物車頁面,確認跨 app 商品不會出現在購物清單
  3. 確認 checkout-order API 只收到有效商品的 productIds
  4. 確認總價正常顯示,可以選擇付款方式並結帳

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.

1 participant