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
Expand the originating cart on admin orders
Damian Legawiecc934c5ff70cf
diff --git a/packages/admin-sdk/src/types/generated/Cart.ts b/packages/admin-sdk/src/types/generated/Cart.tsnew file mode 100644index 0000000000..c86e3ddad1--- /dev/null+++ b/packages/admin-sdk/src/types/generated/Cart.ts@@ -0,0 +1,56 @@+// Typelizer digest 35d79f55dcbb58be6c0197e2e083a8bd+//+// DO NOT MODIFY: This file was automatically generated by Typelizer.+import type {AppliedPromotion, LineItem, Address, Market} from '@/types'++interface Cart {+ id: string;+ market_id: string | null;+ channel_id: string | null;+ number: string;+ token: string;+ email: string | null;+ customer_note: string | null;+ currency: string;+ locale: string | null;+ total_quantity: number;+ warnings: Array<{code: string, message: string, line_item_id?: string, variant_id?: string}>;+ coupon_code: string | null;+ item_total: string | null;+ display_item_total: string | null;+ adjustment_total: string | null;+ display_adjustment_total: string | null;+ discount_total: string | null;+ display_discount_total: string | null;+ tax_total: string | null;+ display_tax_total: string | null;+ included_tax_total: string | null;+ display_included_tax_total: string | null;+ additional_tax_total: string | null;+ display_additional_tax_total: string | null;+ total: string | null;+ display_total: string | null;+ gift_card_total: string | null;+ display_gift_card_total: string | null;+ amount_due: string | null;+ display_amount_due: string | null;+ delivery_total: string | null;+ display_delivery_total: string | null;+ store_credit_total: string | null;+ display_store_credit_total: string | null;+ covered_by_store_credit: boolean;+ current_step: string;+ completed_steps: Array<string>;+ requirements: Array<{step: string, field: string, message: string}>;+ shipping_eq_billing_address: boolean;+ discounts: Array<AppliedPromotion>;+ items: Array<LineItem>;+ billing_address: Address | null;+ shipping_address: Address | null;+ market: Market | null;+ completed_at: string | null;+ created_at: string;+ updated_at: string;+}++export default Cart;diff --git a/packages/admin-sdk/src/types/generated/Order.ts b/packages/admin-sdk/src/types/generated/Order.tsindex 608004701b..ea3a63d606 100644--- a/packages/admin-sdk/src/types/generated/Order.ts+++ b/packages/admin-sdk/src/types/generated/Order.ts@@ -1,7 +1,7 @@-// Typelizer digest 84f69b556d7fd0474620bd95f64989a4+// Typelizer digest 218952b0f2d1b3e9188f853f8c0e55b9//// DO NOT MODIFY: This file was automatically generated by Typelizer.-import type {AppliedPromotion, LineItem, Fulfillment, Payment, Address, GiftCard, Market, Channel, StockLocation, PaymentMethod, Customer, ReturnAuthorization, Reimbursement} from '@/types'+import type {AppliedPromotion, LineItem, Fulfillment, Payment, Address, GiftCard, Market, Cart, Channel, StockLocation, PaymentMethod, Customer, ReturnAuthorization, Reimbursement} from '@/types'interface Order {id: string;@@ -68,6 +68,7 @@ interface Order {canceler_id: string | null;created_by_id: string | null;customer_id: string | null;+ cart?: Cart;channel?: Channel;preferred_stock_location?: StockLocation;payment_methods?: Array<PaymentMethod>;diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.tsindex 2efca060bc..e38fc30e14 100644--- a/packages/admin-sdk/src/types/generated/index.ts+++ b/packages/admin-sdk/src/types/generated/index.ts@@ -1,4 +1,4 @@-// Typelizer digest 6b82abfcfb9f93754fe40dbb09fffd80+// Typelizer digest e57fbfabe59fc981107a0bdfba77862e//// DO NOT MODIFY: This file was automatically generated by Typelizer.export type { default as Address } from './Address'@@ -6,6 +6,7 @@ export type { default as AdminUser } from './AdminUser'export type { default as AllowedOrigin } from './AllowedOrigin'export type { default as ApiKey } from './ApiKey'export type { default as AppliedPromotion } from './AppliedPromotion'+export type { default as Cart } from './Cart'export type { default as Category } from './Category'export type { default as Channel } from './Channel'export type { default as CollectionRule } from './CollectionRule'diff --git a/spree/api/app/serializers/spree/api/v3/admin/cart_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/cart_serializer.rbnew file mode 100644index 0000000000..4d49413fea--- /dev/null+++ b/spree/api/app/serializers/spree/api/v3/admin/cart_serializer.rb@@ -0,0 +1,30 @@+# frozen_string_literal: true++module Spree+ module Api+ module V3+ module Admin+ # Admin Cart serializer — the store shape plus operational timestamps,+ # slimmed to what inspecting an originating cart needs. The cart's+ # fulfillment/payment sub-graphs are pre-conversion duplicates of the+ # order's own and are dropped (they also ballooned the generated type+ # graph past the TypeScript instantiation limit). Kept associations+ # are redeclared with admin counterparts — admin serializers never+ # reference store serializers.+ class CartSerializer < V3::CartSerializer+ %i[fulfillments payments payment_methods gift_card].each { |key| _attributes.delete(key) }++ typelize completed_at: [:string, nullable: true]++ attributes completed_at: :iso8601, created_at: :iso8601, updated_at: :iso8601++ many :order_promotions, key: :discounts, resource: proc { Spree.api.admin_applied_promotion_serializer }+ many :line_items, key: :items, resource: proc { Spree.api.admin_line_item_serializer }+ one :billing_address, resource: proc { Spree.api.admin_address_serializer }+ one :shipping_address, resource: proc { Spree.api.admin_address_serializer }+ one :market, resource: proc { Spree.api.admin_market_serializer }+ end+ end+ end+ end+enddiff --git a/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rbindex 5ec9965f0e..4a1591da52 100644--- a/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb@@ -77,6 +77,7 @@ module Spreeone :billing_address, resource: proc { Spree.api.admin_address_serializer }, if: proc { expand?('billing_address') }one :shipping_address, resource: proc { Spree.api.admin_address_serializer }, if: proc { expand?('shipping_address') }one :gift_card, resource: proc { Spree.api.admin_gift_card_serializer }+ one :cart, resource: proc { Spree.api.admin_cart_serializer }, if: proc { expand?('cart') }one :market, resource: proc { Spree.api.admin_market_serializer }one :channel, resource: proc { Spree.api.admin_channel_serializer }, if: proc { expand?('channel') }one :preferred_stock_location,diff --git a/spree/api/lib/spree/api/dependencies.rb b/spree/api/lib/spree/api/dependencies.rbindex aec6107333..7bb7d5e01d 100644--- a/spree/api/lib/spree/api/dependencies.rb+++ b/spree/api/lib/spree/api/dependencies.rb@@ -93,6 +93,7 @@ module Spreeadmin_applied_promotion_serializer: 'Spree::Api::V3::Admin::AppliedPromotionSerializer',admin_discount_serializer: 'Spree::Api::V3::Admin::DiscountSerializer',admin_tax_line_serializer: 'Spree::Api::V3::Admin::TaxLineSerializer',+ admin_cart_serializer: 'Spree::Api::V3::Admin::CartSerializer',admin_delivery_zone_serializer: 'Spree::Api::V3::Admin::DeliveryZoneSerializer',admin_delivery_method_rule_serializer: 'Spree::Api::V3::Admin::DeliveryMethodRuleSerializer',admin_delivery_zone_member_serializer: 'Spree::Api::V3::Admin::DeliveryZoneMemberSerializer',diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rbindex 841bcc3c2d..2c9c2800c2 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb@@ -117,6 +117,19 @@ RSpec.describe Spree::Api::V3::Admin::OrdersController, type: :controller doenddescribe 'GET #show' do+ it 'expands the originating cart on a placed order' do+ cart = create(:cart_with_line_items, store: store)+ cart.update_columns(completed_at: Time.current)+ placed = create(:completed_order_with_totals, store: store, cart_id: cart.id)++ get :show, params: { id: placed.prefixed_id, expand: 'cart' }, as: :json++ expect(response).to have_http_status(:ok)+ expect(json_response['cart_id']).to eq(cart.prefixed_id)+ expect(json_response['cart']['id']).to eq(cart.prefixed_id)+ expect(json_response['cart']['completed_at']).to be_present+ end+subject { get :show, params: { id: order.prefixed_id }, as: :json }before { request.headers.merge!(headers) }