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 `currency` to gift cards
Damian Legawiecd3041898b466
diff --git a/admin/app/views/spree/admin/gift_cards/_gift_card.html.erb b/admin/app/views/spree/admin/gift_cards/_gift_card.html.erbindex 64ce6b1332..4316820e8f 100644--- a/admin/app/views/spree/admin/gift_cards/_gift_card.html.erb+++ b/admin/app/views/spree/admin/gift_cards/_gift_card.html.erb@@ -6,6 +6,7 @@</td><td class="w-10 cursor-pointer" data-action="click->row-link#openLink"><%= gift_card.display_amount %></td><td class="w-10 cursor-pointer" data-action="click->row-link#openLink"><%= gift_card.display_used_amount %></td>+ <td class="w-10 cursor-pointer" data-action="click->row-link#openLink"><%= gift_card.currency.upcase %></td><td class="w-10 cursor-pointer" data-action="click->row-link#openLink"><%= active_badge(gift_card.active?, label: gift_card.display_state) %></td><td class="w-10 cursor-pointer" data-action="click->row-link#openLink"><% if gift_card.expires_at.present? %>diff --git a/admin/app/views/spree/admin/gift_cards/_list.html.erb b/admin/app/views/spree/admin/gift_cards/_list.html.erbindex 73655b4ae2..9e1a2ccf45 100644--- a/admin/app/views/spree/admin/gift_cards/_list.html.erb+++ b/admin/app/views/spree/admin/gift_cards/_list.html.erb@@ -6,6 +6,7 @@<th><%= Spree.t(:code) %></th><th><%= Spree.t(:amount) %></th><th><%= Spree.t(:used) %></th>+ <th><%= Spree.t(:currency) %></th><th><%= Spree.t(:status) %></th><th><%= Spree.t(:expires_at) %></th><th><%= Spree.t('admin.gift_cards.issued_to') %></th>diff --git a/core/app/models/spree/gift_card.rb b/core/app/models/spree/gift_card.rbindex d25aea3248..dd7efee9e8 100644--- a/core/app/models/spree/gift_card.rb+++ b/core/app/models/spree/gift_card.rb@@ -26,6 +26,7 @@ module Spree# Validations#validates :code, presence: true, uniqueness: { scope: :store_id }+ validates :store, :currency, presence: truevalidates :amount, presence: true, numericality: { greater_than: 0 }validates :amount_remaining, presence: true, numericality: { greater_than_or_equal_to: 0 }validates :expires_at, comparison: { greater_than: Date.current + 1.day }, allow_nil: true, unless: :skip_expires_at_validation@@ -62,6 +63,7 @@ module Spreebefore_validation :generate_codebefore_validation :normalize_codebefore_validation :set_amount_remaining+ before_validation :set_currencybefore_destroy :ensure_can_be_deleted#@@ -182,5 +184,9 @@ module Spreeerrors.add(:base, :cannot_destroy_used_gift_card)throw(:abort)end++ def set_currency+ self.currency ||= store.default_currency+ endendenddiff --git a/core/app/models/spree/gift_card_batch.rb b/core/app/models/spree/gift_card_batch.rbindex 488324e09e..8515e1d6dc 100644--- a/core/app/models/spree/gift_card_batch.rb+++ b/core/app/models/spree/gift_card_batch.rb@@ -8,6 +8,7 @@ module Spree#validates :codes_count, :amount, :prefix, presence: truevalidates :codes_count, numericality: { greater_than: 0, less_than_or_equal_to: Spree::Config[:gift_card_batch_limit].to_i }+ validates :store, :currency, presence: truevalidates :amount, numericality: { greater_than: 0 }#@@ -18,6 +19,7 @@ module Spree## Callbacks#+ before_validation :set_currencyafter_create :generate_gift_cardsauto_strip_attributes :prefix@@ -60,10 +62,15 @@ module Spreegift_card_batch_id: id,amount: amount,amount_remaining: amount,+ currency: currency,code: generate_code,store_id: store_id,expires_at: expires_at}end++ def set_currency+ self.currency ||= store.default_currency+ endendenddiff --git a/core/db/migrate/20250506073057_create_spree_gift_cards_and_spree_gift_card_batches.rb b/core/db/migrate/20250506073057_create_spree_gift_cards_and_spree_gift_card_batches.rbindex e533be71e8..7947f86a61 100644--- a/core/db/migrate/20250506073057_create_spree_gift_cards_and_spree_gift_card_batches.rb+++ b/core/db/migrate/20250506073057_create_spree_gift_cards_and_spree_gift_card_batches.rb@@ -3,7 +3,8 @@ class CreateSpreeGiftCardsAndSpreeGiftCardBatches < ActiveRecord::Migration[7.2]create_table :spree_gift_card_batches, if_not_exists: true do |t|t.references :store, null: false, index: truet.integer :codes_count, default: 1, null: false- t.decimal :amount, precision: 10, scale: 2, default: '10.0', null: false+ t.decimal :amount, precision: 10, scale: 2, null: false+ t.string :currency, null: falset.string :prefixt.date :expires_at@@ -20,6 +21,7 @@ class CreateSpreeGiftCardsAndSpreeGiftCardBatches < ActiveRecord::Migration[7.2]t.string :state, null: false, index: truet.decimal :amount, precision: 10, scale: 2, null: falset.decimal :amount_remaining, precision: 10, scale: 2, null: false+ t.string :currency, null: falset.timestampsend