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.

Rename the admin embedded discounts key to applied_promotions

Damian Legawiecb85081ca2dd7
diff --git a/packages/admin-sdk/src/types/generated/Cart.ts b/packages/admin-sdk/src/types/generated/Cart.ts
index c86e3ddad1..850553ba8f 100644
--- a/packages/admin-sdk/src/types/generated/Cart.ts
+++ b/packages/admin-sdk/src/types/generated/Cart.ts
@@ -1,7 +1,7 @@
-// Typelizer digest 35d79f55dcbb58be6c0197e2e083a8bd
+// Typelizer digest f4a041b4f1727c26dec5d12359219518
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {AppliedPromotion, LineItem, Address, Market} from '@/types'
+import type {LineItem, Address, Market, AppliedPromotion} from '@/types'
interface Cart {
id: string;
@@ -43,7 +43,6 @@ interface Cart {
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;
@@ -51,6 +50,7 @@ interface Cart {
completed_at: string | null;
created_at: string;
updated_at: string;
+ applied_promotions: Array<AppliedPromotion>;
}
export default Cart;
diff --git a/packages/admin-sdk/src/types/generated/Order.ts b/packages/admin-sdk/src/types/generated/Order.ts
index ea3a63d606..22cfeb99e7 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 218952b0f2d1b3e9188f853f8c0e55b9
+// Typelizer digest d9432cdb6e4d1af419ef6cdb32c8b0c9
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {AppliedPromotion, LineItem, Fulfillment, Payment, Address, GiftCard, Market, Cart, Channel, StockLocation, PaymentMethod, Customer, ReturnAuthorization, Reimbursement} from '@/types'
+import type {LineItem, Fulfillment, Payment, Address, GiftCard, Market, AppliedPromotion, Cart, Channel, StockLocation, PaymentMethod, Customer, ReturnAuthorization, Reimbursement} from '@/types'
interface Order {
id: string;
@@ -41,7 +41,6 @@ interface Order {
store_credit_total: string;
display_store_credit_total: string;
covered_by_store_credit: boolean;
- discounts?: Array<AppliedPromotion>;
items?: Array<LineItem>;
fulfillments?: Array<Fulfillment>;
payments?: Array<Payment>;
@@ -68,6 +67,7 @@ interface Order {
canceler_id: string | null;
created_by_id: string | null;
customer_id: string | null;
+ applied_promotions?: Array<AppliedPromotion>;
cart?: Cart;
channel?: Channel;
preferred_stock_location?: StockLocation;
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.rb
index 4d49413fea..0f6c2a9497 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/cart_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/cart_serializer.rb
@@ -12,13 +12,13 @@ module Spree
# 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) }
+ %i[fulfillments payments payment_methods gift_card discounts].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 :order_promotions, key: :applied_promotions, 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 }
diff --git a/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb
index 4a1591da52..754e79f15b 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
@@ -69,7 +69,12 @@ module Spree
end
# Override inherited associations to use admin serializers
- many :order_promotions, key: :discounts, resource: proc { Spree.api.admin_applied_promotion_serializer }, if: proc { expand?('discounts') }
+ # Renamed from the store's `discounts` key: on the admin surface that
+ # word means the typed money rows (/orders/:id/discounts), so the
+ # promotion summaries carry their real name here. The inherited
+ # store-keyed declaration is dropped, not shadowed.
+ _attributes.delete(:discounts)
+ many :order_promotions, key: :applied_promotions, resource: proc { Spree.api.admin_applied_promotion_serializer }, if: proc { expand?('applied_promotions') }
many :line_items, key: :items, resource: proc { Spree.api.admin_line_item_serializer }, if: proc { expand?('items') }
many :fulfillments, resource: proc { Spree.api.admin_fulfillment_serializer }, if: proc { expand?('fulfillments') }
many :payments, resource: proc { Spree.api.admin_payment_serializer }, if: proc { expand?('payments') }