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
Fixed Gift Cards Storefront API
Damian Legawiecf507979ab011
diff --git a/api/app/serializers/spree/api/v2/platform/gift_card_serializer.rb b/api/app/serializers/spree/api/v2/platform/gift_card_serializer.rbindex f1d57e2144..f78be3e4b8 100644--- a/api/app/serializers/spree/api/v2/platform/gift_card_serializer.rb+++ b/api/app/serializers/spree/api/v2/platform/gift_card_serializer.rb@@ -3,13 +3,13 @@ module Spreemodule V2module Platformclass GiftCardSerializer < BaseSerializer- set_type :gift_card+ include ResourceSerializerConcern- attributes :state, :code, :expires_at,- :amount, :amount_remaining,- :display_amount, :display_amount_remaining+ set_type :gift_cardbelongs_to :user++ has_many :ordersendendenddiff --git a/api/app/serializers/spree/v2/storefront/cart_serializer.rb b/api/app/serializers/spree/v2/storefront/cart_serializer.rbindex 1af19133bc..33be38c0e1 100644--- a/api/app/serializers/spree/v2/storefront/cart_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/cart_serializer.rb@@ -58,7 +58,7 @@ module Spreeid_method_name: :ship_address_id,serializer: :address,record_type: :address- belongs_to :gift_card+ belongs_to :gift_card, serializer: :gift_cardendendenddiff --git a/api/app/serializers/spree/v2/storefront/gift_card_serializer.rb b/api/app/serializers/spree/v2/storefront/gift_card_serializer.rbindex 0f98f851ab..ece050200c 100644--- a/api/app/serializers/spree/v2/storefront/gift_card_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/gift_card_serializer.rb@@ -4,7 +4,10 @@ module Spreeclass GiftCardSerializer < BaseSerializerset_type :gift_card- attributes :code, :amount, :amount_remaining, :display_amount, :display_amount_remaining+ attributes :amount, :amount_used, :amount_remaining, :display_amount, :display_amount_used,+ :display_amount_remaining, :expires_at++ attribute :code, &:display_codeendendenddiff --git a/api/spec/requests/spree/api/v2/storefront/cart_spec.rb b/api/spec/requests/spree/api/v2/storefront/cart_spec.rbindex 10c7895076..6984ae48aa 100644--- a/api/spec/requests/spree/api/v2/storefront/cart_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/cart_spec.rb@@ -2,6 +2,7 @@ require 'spec_helper'describe 'API V2 Storefront Cart Spec', type: :request dolet!(:store) { create(:store) }+ let!(:store_credit_payment_method) { create(:store_credit_payment_method, stores: [store]) }let(:currency) { store.default_currency }let(:user) { create(:user) }let(:order) { create(:order, user: user, store: store, currency: currency) }@@ -635,19 +636,19 @@ describe 'API V2 Storefront Cart Spec', type: :request doendcontext 'with gift card' do- let(:gift_card) { create(:gift_card, amount: 10, store: store) }- let(:coupon_code) { gift_card.code }+ let(:gift_card) { create(:gift_card, amount: 10, store: store, amount_used: 10) }+ let(:order) { create(:order_with_line_items, store: store, user: nil, currency: store.default_currency, gift_card: gift_card) }before do- order.update_column(:total, 30)- patch '/api/v2/storefront/cart/apply_coupon_code', params: { coupon_code: coupon_code }, headers: headers_bearer- get '/api/v2/storefront/cart', headers: headers_bearer, params: { include: 'gift_card' }+ get '/api/v2/storefront/cart', headers: headers_order_token, params: { include: 'gift_card' }endit 'should return an order with gift card' do- expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:code).with_value(gift_card.code)))+ expect(response.status).to eq(200)+ expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:code).with_value(gift_card.display_code)))expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:display_amount).with_value('$10.00')))expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:display_amount_remaining).with_value('$0.00')))+ expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:display_amount_used).with_value('$10.00')))endendend@@ -710,7 +711,8 @@ describe 'API V2 Storefront Cart Spec', type: :request doit 'applies the gift card' doapply_gift_card- expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:code).with_value(gift_card.code)))+ expect(response.status).to eq(200)+ expect(json_response['included']).to include(have_type('gift_card').and(have_attribute(:code).with_value(gift_card.display_code)))endendenddiff --git a/storefront/spec/controllers/spree/checkout_controller_spec.rb b/storefront/spec/controllers/spree/checkout_controller_spec.rbindex ebb507e07f..71efb63294 100644--- a/storefront/spec/controllers/spree/checkout_controller_spec.rb+++ b/storefront/spec/controllers/spree/checkout_controller_spec.rb@@ -256,7 +256,7 @@ describe Spree::CheckoutController, type: :controller doendend- xcontext 'removes expired gift card' do+ context 'removes expired gift card' dolet!(:gift_card) { create :gift_card, code: '123', amount: 10, state: 'active' }before do@@ -1166,7 +1166,7 @@ describe Spree::CheckoutController, type: :controller doexpect(order.promotions).not_to include(promotion)end- xcontext 'for a gift card' do+ context 'for a gift card' dolet(:gift_card) { create :gift_card, store: store }let(:coupon_code) { gift_card.code.upcase }