Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fixed: support multiple currencies when creating gift cards

Damian Legawiec2f54b9311443
diff --git a/admin/app/views/spree/admin/gift_card_batches/_form.html.erb b/admin/app/views/spree/admin/gift_card_batches/_form.html.erb
index a068a140cb..fcaa3dc0fd 100644
--- a/admin/app/views/spree/admin/gift_card_batches/_form.html.erb
+++ b/admin/app/views/spree/admin/gift_card_batches/_form.html.erb
@@ -8,6 +8,7 @@
<div class="card-body">
<%= f.spree_text_field :prefix, disabled: f.object.persisted?, label: Spree.t('admin.gift_card_batches.prefix') %>
<%= f.spree_number_field :amount, required: true, disabled: f.object.persisted? %>
+ <%= f.spree_select :currency, options_for_select(supported_currency_options, f.object.currency), { label: Spree.t(:currency), autocomplete: true } %>
<%= f.spree_number_field :codes_count, required: true, min: 1, max: Spree::Config[:gift_card_batch_limit], label: Spree.t('admin.gift_card_batches.codes_count') %>
<%= f.spree_date_field :expires_at, disabled: f.object.persisted?, help: 'Gift cards will expire after this date.' %>
</div>
diff --git a/admin/app/views/spree/admin/gift_cards/_form.html.erb b/admin/app/views/spree/admin/gift_cards/_form.html.erb
index edc8e736e3..e396f5ef7f 100644
--- a/admin/app/views/spree/admin/gift_cards/_form.html.erb
+++ b/admin/app/views/spree/admin/gift_cards/_form.html.erb
@@ -5,6 +5,7 @@
<% end %>
<%= f.spree_number_field :amount, required: true %>
+ <%= f.spree_select :currency, options_for_select(supported_currency_options, f.object.currency), { label: Spree.t(:currency), autocomplete: true }, { disabled: f.object.persisted? } %>
<div class="form-group">
<%= f.label :user_id, Spree.t(:customer) %>
diff --git a/admin/spec/controllers/spree/admin/gift_card_batches_controller_spec.rb b/admin/spec/controllers/spree/admin/gift_card_batches_controller_spec.rb
index 94827a3e51..f38f1904b4 100644
--- a/admin/spec/controllers/spree/admin/gift_card_batches_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/gift_card_batches_controller_spec.rb
@@ -27,7 +27,7 @@ describe Spree::Admin::GiftCardBatchesController, type: :controller do
gift_card_batch: {
prefix: 'BATCH001',
amount: 10,
- currency: 'USD',
+ currency: 'EUR',
codes_count: 20,
expires_at: 1.year.from_now.to_date
}
@@ -43,7 +43,7 @@ describe Spree::Admin::GiftCardBatchesController, type: :controller do
gift_card_batch = Spree::GiftCardBatch.last
expect(gift_card_batch.prefix).to eq('BATCH001')
expect(gift_card_batch.amount).to eq(10)
- expect(gift_card_batch.currency).to eq('USD')
+ expect(gift_card_batch.currency).to eq('EUR')
expect(gift_card_batch.codes_count).to eq(20)
expect(gift_card_batch.expires_at).to eq(1.year.from_now.to_date)
expect(gift_card_batch.store).to eq(store)
@@ -67,7 +67,7 @@ describe Spree::Admin::GiftCardBatchesController, type: :controller do
{
gift_card_batch: {
amount: -100,
- currency: 'USD'
+ currency: 'EUR'
}
}
end
diff --git a/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb b/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb
index c7c3bf5d7b..6a72941ebf 100644
--- a/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb
@@ -110,7 +110,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
{
gift_card: {
amount: 100,
- currency: 'USD',
+ currency: 'EUR',
user_id: user.id,
expires_at: 1.year.from_now.to_date,
code: '1234567890'
@@ -150,7 +150,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
{
gift_card: {
amount: -100,
- currency: 'USD'
+ currency: 'EUR'
}
}
end
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 152b00b942..5b2dbae4e5 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -110,9 +110,9 @@ module Spree
@@export_attributes = [:type, :format, :record_selection, :search_params]
- @@gift_card_attributes = [:code, :amount, :expires_at, :user_id]
+ @@gift_card_attributes = [:code, :amount, :expires_at, :user_id, :currency]
- @@gift_card_batch_attributes = [:prefix, :codes_count, :amount, :expires_at]
+ @@gift_card_batch_attributes = [:prefix, :codes_count, :amount, :expires_at, :currency]
@@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]