Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix: Order page showing every seller's commission lines
Łukasz Adamczykfd1594f08e97
diff --git a/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsx b/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsxindex 409d60022d..5f5b2205fb 100644--- a/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsx+++ b/packages/dashboard/src/components/spree/orders/order-discounts-sidebar-card.tsx@@ -161,7 +161,7 @@ function CouponCodeDialog({const promotionsQuery = useQuery({queryKey: useResourceKey('promotions', 'coupon-options'),- queryFn: () => adminClient.promotions.list({ q: { kind_eq: 'coupon_code' }, per_page: 100 }),+ queryFn: () => adminClient.promotions.list({ kind_eq: 'coupon_code', limit: 100 }),enabled: open,})const couponPromotions = (promotionsQuery.data?.data ?? []).filter((promotion) => promotion.code)diff --git a/packages/dashboard/src/hooks/use-order.test.ts b/packages/dashboard/src/hooks/use-order.test.tsnew file mode 100644index 0000000000..71752982c6--- /dev/null+++ b/packages/dashboard/src/hooks/use-order.test.ts@@ -0,0 +1,19 @@+import { describe, expect, it } from 'vitest'+import { commissionLinesParams } from './use-order'++describe('commission line params', () => {+ it('names the ransack predicate at the top level', () => {+ expect(commissionLinesParams('or_123')).toMatchObject({ order_id_eq: 'or_123' })+ })++ // Nesting them under `q` serialises to `q[q]=[object Object]`: Ransack drops+ // the predicate, and the order page shows every commission line in the+ // store — other sellers' orders included.+ it('nests nothing the SDK would stringify into a predicate', () => {+ const nested = Object.entries(commissionLinesParams('or_123')).filter(+ ([, value]) => typeof value === 'object' && !Array.isArray(value),+ )++ expect(nested).toEqual([])+ })+})diff --git a/packages/dashboard/src/hooks/use-order.ts b/packages/dashboard/src/hooks/use-order.tsindex 71f7a82016..35622e3fed 100644--- a/packages/dashboard/src/hooks/use-order.ts+++ b/packages/dashboard/src/hooks/use-order.ts@@ -82,12 +82,22 @@ export function useOrderFees(orderId: string) {})}-async function listAllCommissionLines(orderId: string) {- const params = {- q: { order_id_eq: orderId },+/**+ * Ransack predicates go in flat: the SDK wraps them into `q[...]` itself, so a+ * nested `q` becomes `q[q]=[object Object]`, which Ransack ignores — and an+ * unfiltered list is every commission line in the store, rendered against+ * whichever order happens to be open.+ */+export function commissionLinesParams(orderId: string) {+ return {+ order_id_eq: orderId,limit: 100,expand: ['commission_rate'],}+}++async function listAllCommissionLines(orderId: string) {+ const params = commissionLinesParams(orderId)const first = await adminClient.commissionLines.list({ ...params, page: 1 })const rest = await Promise.all(Array.from({ length: (first.meta?.pages ?? 1) - 1 }, (_, index) =>