Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Carry the seller order work onto the consignment model

Damian Legawiece36fde777e2e
diff --git a/packages/seller-dashboard/src/components/orders/fulfillment-tracking-dialog.tsx b/packages/seller-dashboard/src/components/orders/fulfillment-tracking-dialog.tsx
index 23b1c5a9d5..429b5f2dce 100644
--- a/packages/seller-dashboard/src/components/orders/fulfillment-tracking-dialog.tsx
+++ b/packages/seller-dashboard/src/components/orders/fulfillment-tracking-dialog.tsx
@@ -59,7 +59,9 @@ export function FulfillmentTrackingDialog({
resolver: zodResolver(trackingFormSchema),
defaultValues: {
tracking: fulfillment.tracking ?? '',
- tracking_carrier: fulfillment.tracking_carrier ?? '',
+ // The carrier lives on the parcel's consignment since 6.0; `tracking`
+ // on the fulfillment summarizes the first of them.
+ tracking_carrier: fulfillment.deliveries?.[0]?.carrier ?? '',
},
})
diff --git a/packages/seller-sdk/src/seller-client.ts b/packages/seller-sdk/src/seller-client.ts
index fe6012f43f..7cb0baf207 100644
--- a/packages/seller-sdk/src/seller-client.ts
+++ b/packages/seller-sdk/src/seller-client.ts
@@ -434,6 +434,43 @@ export class SellerClient {
* The tracked consignments of one of the seller's parcels. A seller
* ships on manual methods, so tracking numbers are entered here by hand.
*/
+ /**
+ * The tracking number and its carrier. Where a parcel ships from and
+ * which service carries it are the marketplace's arrangements, so they
+ * are not editable here.
+ */
+ update: (
+ orderId: string,
+ id: string,
+ params: { tracking?: string; tracking_carrier?: string },
+ options?: RequestOptions,
+ ): Promise<Fulfillment> =>
+ this.request<Fulfillment>('PATCH', `/orders/${orderId}/fulfillments/${id}`, {
+ ...options,
+ body: params,
+ }),
+
+ /** A parcel this seller is not going to send after all. */
+ cancel: (orderId: string, id: string, options?: RequestOptions): Promise<Fulfillment> =>
+ this.request<Fulfillment>('PATCH', `/orders/${orderId}/fulfillments/${id}/cancel`, options),
+
+ /**
+ * Moves part of what this parcel holds onto one of its own, for goods
+ * leaving separately. Answers with every fulfillment on the order, since
+ * splitting rewrites more than one.
+ */
+ split: (
+ orderId: string,
+ id: string,
+ params: { variant_id: string; quantity: number; stock_location_id?: string },
+ options?: RequestOptions,
+ ): Promise<{ data: Fulfillment[] }> =>
+ this.request<{ data: Fulfillment[] }>(
+ 'PATCH',
+ `/orders/${orderId}/fulfillments/${id}/split`,
+ { ...options, body: params },
+ ),
+
deliveries: {
list: (
orderId: string,
diff --git a/spree/api/config/routes.rb b/spree/api/config/routes.rb
index 28acb5a31d..55690f5631 100644
--- a/spree/api/config/routes.rb
+++ b/spree/api/config/routes.rb
@@ -872,6 +872,15 @@ Spree::Core::Engine.add_routes do
patch :cancel
patch :split
end
+
+ # A parcel's consignments and its postage. Both hang off the
+ # fulfillment because that is what actually travels.
+ resources :deliveries, controller: 'orders/deliveries', only: [:index, :show, :create, :update, :destroy]
+ resources :labels, controller: 'orders/labels', only: [:index, :show, :create, :destroy] do
+ member do
+ get :download
+ end
+ end
end
# Putting a sale right. The seller is merchant of record for their
@@ -905,13 +914,6 @@ Spree::Core::Engine.add_routes do
patch :deny
patch :cancel
end
-
- resources :deliveries, controller: 'orders/deliveries', only: [:index, :show, :create, :update, :destroy]
- resources :labels, controller: 'orders/labels', only: [:index, :show, :create, :destroy] do
- member do
- get :download
- end
- end
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/seller/orders/fulfillments_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/seller/orders/fulfillments_controller_spec.rb
index fe01a9df87..535df769d6 100644
--- a/spree/api/spec/controllers/spree/api/v3/seller/orders/fulfillments_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/seller/orders/fulfillments_controller_spec.rb
@@ -104,8 +104,11 @@ RSpec.describe Spree::Api::V3::Seller::Orders::FulfillmentsController, type: :co
}, as: :json
expect(response).to have_http_status(:ok)
+ # Tracking lives on the parcel's consignment since 6.0; `tracking` and
+ # `tracking_url` on the fulfillment summarize the primary one.
expect(fulfillment.reload.tracking).to eq('TRACK123')
- expect(fulfillment.tracking_carrier).to eq('ups')
+ expect(fulfillment.deliveries.first.carrier).to eq('ups')
+ expect(fulfillment.tracking_url).to include('TRACK123')
end
# Where a parcel ships from and which service carries it are the