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
Removed `validate_gift_card_data` action as it's not finalized yet
Damian Legawiec23b6a5140bff
diff --git a/api/app/controllers/spree/api/v2/storefront/checkout_controller.rb b/api/app/controllers/spree/api/v2/storefront/checkout_controller.rbindex a3d4200ecc..987cf02bfb 100644--- a/api/app/controllers/spree/api/v2/storefront/checkout_controller.rb+++ b/api/app/controllers/spree/api/v2/storefront/checkout_controller.rb@@ -111,16 +111,6 @@ module Spreeendend- def validate_gift_card_data- if params[:gift_card_code].present? && spree_current_order.gift_card.nil?- render json: { error: Spree.t('api.v2.gift_card.not_found') }, status: 422- elsif params[:gift_card_amount].to_d != spree_current_order.gift_card_total.to_d- render json: { error: Spree.t('api.v2.gift_card.amount_not_valid') }, status: 422- else- render json: { success: true }, status: 200- end- end-privatedef resource_serializerdiff --git a/api/config/routes.rb b/api/config/routes.rbindex 27e46051c9..4309960131 100644--- a/api/config/routes.rb+++ b/api/config/routes.rb@@ -32,7 +32,6 @@ Spree::Core::Engine.add_routes doget :shipping_ratespatch :select_shipping_methodpost :validate_order_for_payment- post :validate_gift_card_dataendresource :account, controller: :account, only: %i[show create update]diff --git a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rbindex 4adefba1a6..af9a5c796d 100644--- a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb@@ -1118,52 +1118,4 @@ describe 'API V2 Storefront Checkout Spec', type: :request doendendend-- describe 'checkout#validate_gift_card_data' do- let(:order) { create(:order) }-- let(:execute) { post '/api/v2/storefront/checkout/validate_gift_card_data', params: params, headers: headers }-- context 'when order is not present' do- let(:params) { { order_token: '' } }-- it 'returns a 404 status' do- execute- expect(response).to have_http_status(:not_found)- end- end-- context 'when order is present' do- context 'and gift card code is not present' do- let(:params) { { order_token: order.token, gift_card_code: '' } }-- it 'returns a 200 status' do- execute- expect(response).to have_http_status(:ok)- end- end-- context 'and gift_card_code param present but order has no gift card' do- let(:params) { { order_token: order.token, gift_card_code: '123456' } }-- it 'returns a 422 status' do- execute- expect(response).to have_http_status(:unprocessable_entity)- expect(json_response['error']).to eq(Spree.t('api.v2.gift_card.not_found'))- end- end-- context 'and gift_card_amount param present but order gift card total is different' do- let(:params) { { order_token: order.token, gift_card_amount: 100 } }- let(:gift_card) { create(:gift_card, amount: 200) }- let(:order) { create(:order, gift_card: gift_card) }-- it 'returns a 422 status' do- execute- expect(response).to have_http_status(:unprocessable_entity)- expect(json_response['error']).to eq(Spree.t('api.v2.gift_card.amount_not_valid'))- end- end- end- endenddiff --git a/core/app/models/spree/order/store_credit.rb b/core/app/models/spree/order/store_credit.rbindex c267ed6832..f8edd74fe9 100644--- a/core/app/models/spree/order/store_credit.rb+++ b/core/app/models/spree/order/store_credit.rb@@ -14,12 +14,19 @@ module Spreeendalias covered_by_store_credit covered_by_store_credit?+ # Returns the total amount of store credits available to the user associated with the order.+ # Returns only store credit for this store and same currency as order+ #+ # @return [BigDecimal] The total amount of store credits available to the user associated with the order.def total_available_store_creditreturn 0.0 unless useruser.total_available_store_credit(currency, store)end+ # Returns the available store credits for the user associated with the order.+ #+ # @return [Array<Spree::StoreCredit>] The available store credits for the user associated with the order.def available_store_creditsreturn Spree::StoreCredit.none if user.nil?@@ -32,10 +39,16 @@ module Spreetotal_available_store_credit > 0end+ # Returns the total amount of the order minus the total amount of store credits applied to the order.+ #+ # @return [BigDecimal] The total amount of the order minus the total amount of store credits applied to the order.def order_total_after_store_credittotal - total_applicable_store_creditend+ # Returns the total amount of the order minus the total amount of store credits applied to the order.+ #+ # @return [BigDecimal] The total amount of the order minus the total amount of store credits applied to the order.def total_minus_store_creditstotal - total_applied_store_creditend@@ -48,10 +61,16 @@ module Spreeendend+ # Returns the total amount of store credits applied to the order.+ #+ # @return [BigDecimal] The total amount of store credits applied to the order.def total_applied_store_creditpayments.store_credits.valid.sum(:amount)end+ # Returns true if the order is using store credit.+ #+ # @return [Boolean] True if the order is using store credit, false otherwise.def using_store_credit?total_applied_store_credit > 0enddiff --git a/core/spec/models/spree/order_merger_spec.rb b/core/spec/models/spree/order_merger_spec.rbindex 11c26bf647..8eacc5f578 100644--- a/core/spec/models/spree/order_merger_spec.rb+++ b/core/spec/models/spree/order_merger_spec.rb@@ -166,7 +166,12 @@ module Spreeit 'merges the gift card' dosubject.merge!(order_2)- expect(order_1.reload.gift_card).to eq(gift_card)++ order_1.reload.tap do |merged|+ expect(merged.gift_card).to eq(gift_card)+ expect(merged.payments.store_credits.count).to eq(1)+ expect(merged.total_applied_store_credit).to eq(20)+ endendendend