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
Add `promo_total_cents` to `Spree::V2::Storefront::CartSerializer` (#12295)
Łukasz Adamczyk650e87f9f2a1
diff --git a/api/app/serializers/spree/v2/storefront/cart_serializer.rb b/api/app/serializers/spree/v2/storefront/cart_serializer.rbindex 115a32cb6e..9a6e639400 100644--- a/api/app/serializers/spree/v2/storefront/cart_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/cart_serializer.rb@@ -24,6 +24,10 @@ module Spreecart.display_total_applied_store_credit.abs.amount_in_centsend+ attribute :promo_total_cents do |cart|+ cart.display_promo_total.abs.amount_in_cents+ end+attribute :tax_total_cents do |cart|cart.display_tax_total.amount_in_centsenddiff --git a/api/spec/serializers/spree/v2/storefront/cart_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/cart_serializer_spec.rbnew file mode 100644index 0000000000..0a1983ba2e--- /dev/null+++ b/api/spec/serializers/spree/v2/storefront/cart_serializer_spec.rb@@ -0,0 +1,27 @@+require 'spec_helper'++RSpec.describe Spree::V2::Storefront::CartSerializer do+ subject { described_class.new(order).serializable_hash }++ include_context 'API v2 serializers params'++ let!(:order) { create(:order) }++ describe '#promo_total_cents' do+ context 'without any promo applied' do+ it 'returns 0 promo total' do+ expect(subject[:data][:attributes][:promo_total_cents]).to eq(0)+ end+ end++ context 'with a promo applied' do+ before do+ order.update_column(:promo_total, 10)+ end++ it 'returns the promo total in cents' do+ expect(subject[:data][:attributes][:promo_total_cents]).to eq(1000)+ end+ end+ end+enddiff --git a/docs/api-reference/storefront.yaml b/docs/api-reference/storefront.yamlindex 1d770d438b..f95984805a 100644--- a/docs/api-reference/storefront.yaml+++ b/docs/api-reference/storefront.yaml@@ -1721,7 +1721,7 @@ paths:The Add Items to Wishlist endpoint adds variants to an existing wishlist by creating a new `wished_item` objects. A wished item in a wishlist is comparable to a line item in a cart.Each wished item references a single variant, holds the desired quantity and returns price information determined by the variant price in current currency, and desired quantity.- operationId: add-item-to-wishlist+ operationId: add-items-to-wishlistparameters:- $ref: '#/components/parameters/Token'requestBody:@@ -1837,7 +1837,7 @@ paths:delete:description: Removes wished items from a wishlist.summary: Delete Items from Wishlist- operationId: delete-wished-variant-from-wishlist+ operationId: delete-wished-variants-from-wishlistparameters:- $ref: '#/components/parameters/Token'requestBody:@@ -2126,12 +2126,30 @@ components:item_total:type: stringexample: '19.99'+ subtotal_cents:+ type: integer+ example: 1999+ store_credit_total_cents:+ type: integer+ example: 0total:type: stringexample: '29.99'+ total_cents:+ type: integer+ example: 2999+ total_minus_store_credits:+ type: string+ example: '29.99'+ total_minus_store_credits_cents:+ type: integer+ example: 2999ship_total:type: string- example: '0.0'+ example: '5.0'+ ship_total_cents:+ type: integer+ example: 500adjustment_total:type: stringexample: '10.0'@@ -2155,6 +2173,9 @@ components:tax_total:type: stringexample: '10.0'+ tax_total_cents:+ type: integer+ example: 1000currency:type: stringexample: USD@@ -2192,6 +2213,9 @@ components:promo_total:type: stringexample: '-10.0'+ promo_total_cents:+ type: integer+ example: -1000display_promo_total:type: stringexample: '-$10.00'@@ -2208,6 +2232,9 @@ components:display_total:type: stringexample: $29.99+ display_total_minus_store_credits:+ type: string+ example: $29.99pre_tax_item_amount:type: stringexample: '17.00'@@ -4482,7 +4509,13 @@ components:number: R233871560item_total: '0.0'total: '0.0'+ subtotal_cents: 0+ store_credit_total_cents: 0+ total_cents: 0+ total_minus_store_credits: '0.0'+ total_minus_store_credits_cents: 0ship_total: '0.0'+ ship_total_cents: 0adjustment_total: '0.0'created_at: '2021-09-28T22:15:07.471Z'updated_at: '2021-09-28T22:15:07.471Z'@@ -4492,6 +4525,7 @@ components:display_additional_tax_total: $0.00display_included_tax_total: $0.00tax_total: '0.0'+ tax_total_cents: 0currency: USDstate: carttoken: zTEpsukRq_yEUcXVCSv0uw1632867307450@@ -4502,9 +4536,11 @@ components:display_tax_total: $0.00promo_total: '0.0'display_promo_total: $0.00+ promo_total_cents: 0item_count: 0special_instructions: nulldisplay_total: $0.00+ display_total_minus_store_credits: $0.00pre_tax_item_amount: '0.0'display_pre_tax_item_amount: $0.00pre_tax_total: '0.0'@@ -4536,8 +4572,14 @@ components:attributes:number: R823511564item_total: '287.97'+ subtotal_cents: 28797total: '316.0'+ store_credit_total_cents: 0+ total_cents: 31600+ total_minus_store_credits: '316.0'+ total_minus_store_credits_cents: 31600ship_total: '5.0'+ ship_total_cents: 500adjustment_total: '23.03'created_at: '2021-09-28T12:57:15.148Z'updated_at: '2021-09-28T13:06:02.689Z'@@ -4547,6 +4589,7 @@ components:display_additional_tax_total: $51.83display_included_tax_total: $26.18tax_total: '78.01'+ tax_total_cents: 7801currency: USDstate: paymenttoken: VDK_6q_NNdWFc81VZRpUfQ1632833835148@@ -4557,9 +4600,11 @@ components:display_tax_total: $78.01promo_total: '-28.8'display_promo_total: '-$28.80'+ promo_total_cents: -2880item_count: 3special_instructions: nulldisplay_total: $316.00+ display_total_minus_store_credits: 31600pre_tax_item_amount: '261.7909'display_pre_tax_item_amount: $261.79pre_tax_total: '266.7909'@@ -4605,8 +4650,14 @@ components:attributes:number: R177608027item_total: '474.95'+ subtotal_cents: 47495total: '527.45'+ store_credit_total_cents: 0+ total_cents: 52745+ total_minus_store_credits: '527.45'+ total_minus_store_credits_cents: 52745ship_total: '5.0'+ ship_total_cents: 500adjustment_total: '47.5'created_at: '2021-09-28T22:31:47.401Z'updated_at: '2021-09-28T22:33:20.257Z'@@ -4625,10 +4676,12 @@ components:display_adjustment_total: $47.50display_tax_total: $47.50promo_total: '0.0'+ promo_total_cents: 0display_promo_total: $0.00item_count: 5special_instructions: nulldisplay_total: $527.45+ display_total_minus_store_credits: 52745pre_tax_item_amount: '474.95'display_pre_tax_item_amount: $474.95pre_tax_total: '479.95'@@ -4967,8 +5020,14 @@ components:attributes:number: R177608027item_total: '474.95'+ subtotal_cents: 47495total: '527.45'+ store_credit_total_cents: 0+ total_cents: 52745+ total_minus_store_credits: '527.45'+ total_minus_store_credits_cents: 52745ship_total: '5.0'+ ship_total_cents: 500adjustment_total: '47.5'created_at: '2021-09-28T22:31:47.401Z'updated_at: '2021-09-28T22:33:20.257Z'@@ -4987,10 +5046,12 @@ components:display_adjustment_total: $47.50display_tax_total: $47.50promo_total: '0.0'+ promo_total_cents: 0display_promo_total: $0.00item_count: 5special_instructions: nulldisplay_total: $527.45+ display_total_minus_store_credits: 52745pre_tax_item_amount: '474.95'display_pre_tax_item_amount: $474.95pre_tax_total: '479.95'@@ -5048,8 +5109,14 @@ components:attributes:number: R177608027item_total: '474.95'+ subtotal_cents: 47495total: '527.45'+ store_credit_total_cents: 0+ total_cents: 52745+ total_minus_store_credits: '527.45'+ total_minus_store_credits_cents: 52745ship_total: '5.0'+ ship_total_cents: 500adjustment_total: '47.5'created_at: '2021-09-28T22:31:47.401Z'updated_at: '2021-09-28T22:33:20.257Z'@@ -5068,10 +5135,12 @@ components:display_adjustment_total: $47.50display_tax_total: $47.50promo_total: '0.0'+ promo_total_cents: 0display_promo_total: $0.00item_count: 5special_instructions: nulldisplay_total: $527.45+ display_total_minus_store_credits: 52745pre_tax_item_amount: '474.95'display_pre_tax_item_amount: $474.95pre_tax_total: '479.95'