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.

Update

Matthew Kennedy9cdcf051c6a0
diff --git a/backend/app/assets/javascripts/spree/backend/spree-select2.js b/backend/app/assets/javascripts/spree/backend/spree-select2.js
index b77e1f709c..9670c3a69f 100644
--- a/backend/app/assets/javascripts/spree/backend/spree-select2.js
+++ b/backend/app/assets/javascripts/spree/backend/spree-select2.js
@@ -3,6 +3,10 @@ document.addEventListener('DOMContentLoaded', function() {
// Remember to add a place holder in the HTML as needed.
$('select.select2').select2({})
+ $('select.select2-multiple').select2({
+ multiple: true
+ })
+
// Initiate a Select2 with the option to clear, on any select element with the class .select2-clear
// Set: include_blank: true in the ERB.
// A placeholder is auto-added here as it is required to clear the Select2.
diff --git a/backend/app/views/spree/admin/payment_methods/_form.html.erb b/backend/app/views/spree/admin/payment_methods/_form.html.erb
index 17bb2571f6..f6f7aa2cb1 100644
--- a/backend/app/views/spree/admin/payment_methods/_form.html.erb
+++ b/backend/app/views/spree/admin/payment_methods/_form.html.erb
@@ -26,7 +26,7 @@
<div data-hook="store" class="form-group">
<%= label_tag :payment_method_store, Spree.t(:store) %>
- <%= collection_select(:payment_method, :store_id, @stores, :id, :unique_name, { include_blank: true }, {id: 'store_id', class: 'select2-clear'}) %>
+ <%= collection_select(:payment_method, :store_ids, @stores, :id, :unique_name, {}, { miltiple: true, id: 'store_id', class: 'select2-multiple' }) %>
<small class="form-text text-muted"><%= Spree.t('payment_method_form.stores_help') %></small>
</div>
diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb
index e92237750e..f5d94e4baa 100644
--- a/core/app/models/spree/payment_method.rb
+++ b/core/app/models/spree/payment_method.rb
@@ -12,7 +12,7 @@ module Spree
validates :name, presence: true
- belongs_to :store
+ has_and_belongs_to_many :stores
with_options dependent: :restrict_with_error do
has_many :payments, class_name: 'Spree::Payment', inverse_of: :payment_method
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 3edce8a407..442c531b8a 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -21,6 +21,8 @@ module Spree
has_one_attached :logo
has_one_attached :mailer_logo
+ has_many :payment_methods
+
validates :mailer_logo, content_type: ['image/png', 'image/jpg', 'image/jpeg']
before_save :ensure_default_exists_and_is_unique
diff --git a/core/db/migrate/20210114182625_add_payment_methods_stores_associasion.rb b/core/db/migrate/20210114182625_add_payment_methods_stores_associasion.rb
new file mode 100644
index 0000000000..716019d9b5
--- /dev/null
+++ b/core/db/migrate/20210114182625_add_payment_methods_stores_associasion.rb
@@ -0,0 +1,8 @@
+class AddPaymentMethodsStoresAssociasion < ActiveRecord::Migration[6.0]
+ def change
+ create_table :spree_payment_methods_stores, id: false do |t|
+ t.belongs_to :payment_method
+ t.belongs_to :store
+ end
+ end
+end
diff --git a/core/db/migrate/20210114220232_remove_store_id_from_spree_payment_methods.rb b/core/db/migrate/20210114220232_remove_store_id_from_spree_payment_methods.rb
new file mode 100644
index 0000000000..b62f395926
--- /dev/null
+++ b/core/db/migrate/20210114220232_remove_store_id_from_spree_payment_methods.rb
@@ -0,0 +1,5 @@
+class RemoveStoreIdFromSpreePaymentMethods < ActiveRecord::Migration[6.0]
+ def change
+ remove_column :spree_payment_methods, :store_id
+ end
+end