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
Move serializers and change model
Michał Brożek50f303c66f6c
diff --git a/api/app/controllers/spree/api/v2/platform/gift_cards_controller.rb b/api/app/controllers/spree/api/v2/platform/gift_cards_controller.rbnew file mode 100644index 0000000000..9d8ada2616--- /dev/null+++ b/api/app/controllers/spree/api/v2/platform/gift_cards_controller.rb@@ -0,0 +1,15 @@+module Spree+ module Api+ module V2+ module Platform+ class GiftCardsController < ResourceController+ private++ def model_class+ Spree::GiftCard+ end+ end+ end+ end+ end+enddiff --git a/api/app/serializers/spree/api/v2/gift_card_serializer.rb b/api/app/serializers/spree/api/v2/gift_card_serializer.rbnew file mode 100644index 0000000000..7332b687da--- /dev/null+++ b/api/app/serializers/spree/api/v2/gift_card_serializer.rb@@ -0,0 +1,17 @@+module Spree+ module Api+ module V2+ module Platform+ class GiftCardSerializer < BaseSerializer+ set_type :gift_card++ attributes :state, :code, :expires_at,+ :amount, :amount_remaining, :minimum_order_amount,+ :display_amount, :display_amount_remaining, :display_minimum_order_amount++ belongs_to :user+ end+ end+ end+ end+enddiff --git a/api/app/serializers/spree/v2/storefront/cart_serializer.rb b/api/app/serializers/spree/v2/storefront/cart_serializer.rbindex 9a6e639400..1af19133bc 100644--- a/api/app/serializers/spree/v2/storefront/cart_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/cart_serializer.rb@@ -58,6 +58,7 @@ module Spreeid_method_name: :ship_address_id,serializer: :address,record_type: :address+ belongs_to :gift_cardendendenddiff --git a/api/app/serializers/spree/v2/storefront/gift_card_serializer.rb b/api/app/serializers/spree/v2/storefront/gift_card_serializer.rbnew file mode 100644index 0000000000..0f98f851ab--- /dev/null+++ b/api/app/serializers/spree/v2/storefront/gift_card_serializer.rb@@ -0,0 +1,11 @@+module Spree+ module V2+ module Storefront+ class GiftCardSerializer < BaseSerializer+ set_type :gift_card++ attributes :code, :amount, :amount_remaining, :display_amount, :display_amount_remaining+ end+ end+ end+enddiff --git a/core/app/models/spree/gift_card.rb b/core/app/models/spree/gift_card.rbindex e55e2b76af..e524221658 100644--- a/core/app/models/spree/gift_card.rb+++ b/core/app/models/spree/gift_card.rb@@ -17,7 +17,12 @@ module Spreebelongs_to :batch, class_name: 'Spree::GiftCardBatch', optional: true, foreign_key: :gift_card_batch_idhas_many :store_credits, class_name: 'Spree::StoreCredit'- has_many :orders, -> { without_vendor }, through: :store_credits, source: :orders+ if defined?(Spree::Vendor)+ has_many :orders, -> { without_vendor }, through: :store_credits, source: :orders+ else+ has_many :orders, through: :store_credits, source: :orders+ end+has_many :users, through: :ordersscope :active, -> { where(state: [:active, :partialy_redeemed]).where(expires_at: [nil, Time.current..]) }diff --git a/core/app/services/spree/cart/recalculate.rb b/core/app/services/spree/cart/recalculate.rbindex 56ccd24e5c..2c6df9c311 100644--- a/core/app/services/spree/cart/recalculate.rb+++ b/core/app/services/spree/cart/recalculate.rb@@ -4,6 +4,7 @@ module Spreeprepend Spree::ServiceModule::Basedef call(order:, line_item:, line_item_created: false, options: {})+ order.remove_gift_card if order.gift_card.present?order_updater = ::Spree::OrderUpdater.new(order)order.payments.store_credits.checkout.destroy_all