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 payment_methods scoped by store.
Matthew Kennedy461cb6b9a26f
diff --git a/backend/app/controllers/spree/admin/payment_methods_controller.rb b/backend/app/controllers/spree/admin/payment_methods_controller.rbindex d5c92d032a..4b7c5451b0 100644--- a/backend/app/controllers/spree/admin/payment_methods_controller.rb+++ b/backend/app/controllers/spree/admin/payment_methods_controller.rb@@ -49,12 +49,22 @@ module Spreeprivate+ def scope+ current_store.payment_methods+ end+def collectionreturn @collection if @collection.present?params[:q] ||= {}@collection = super.order(position: :asc)+ @collection = if params[:q][:all_stores] == '1'+ super.order(position: :asc)+ else+ scope.order(position: :asc)+ end+@search = @collection.ransack(params[:q])@collection = @search.result.page(params[:page]).per(params[:per_page])enddiff --git a/backend/app/views/spree/admin/payment_methods/index.html.erb b/backend/app/views/spree/admin/payment_methods/index.html.erbindex a24aa585cd..fef9ea6afd 100644--- a/backend/app/views/spree/admin/payment_methods/index.html.erb+++ b/backend/app/views/spree/admin/payment_methods/index.html.erb@@ -6,6 +6,33 @@<%= button_link_to Spree.t(:new_payment_method), new_object_url, class: "btn-success", icon: 'add.svg', id: 'admin_new_payment_methods_link' %><% end if can? :create, Spree::PaymentMethod %>+<% content_for :table_filter do %>+ <div data-hook="admin_payment_methods_filter_table">+ <%= search_form_for [:admin, @search] do |f| %>+ <%- locals = {f: f} %>+ <div data-hook="admin_payment_methods_index_search" class="row">+ <div class="col-12">+ <div class="form-group">+ <%= f.label :name_cont, Spree.t('name') %>+ <%= f.text_field :name_cont, size: 15, class: "form-control js-quick-search-target js-filterable" %>+ </div>+ </div>+ <div class="col-12">+ <%= f.field_container :all_stores do %>+ <div class="custom-control custom-checkbox">+ <%= f.check_box :all_stores, {checked: params[:q][:all_stores] == '1', class: 'custom-control-input'}, '1', '0' %>+ <%= f.label :all_stores, Spree.t('admin.show_payment_methods_for_all_stores'), class: 'custom-control-label' %>+ </div>+ <% end %>+ </div>+ </div>+ <div data-hook="admin_products_index_search_buttons" class="form-actions">+ <%= button Spree.t(:search), 'search.svg' %>+ </div>+ <% end %>+ </div>+<% end %>+<% if @payment_methods.any? %><div class="table-responsive"><table class="table sortable" id='listing_payment_methods' data-hook data-sortable-link="<%= update_positions_admin_payment_methods_url %>">diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex e6319ed648..6cca41919c 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -4,7 +4,9 @@ module SpreeFAVICON_CONTENT_TYPES = ['image/png', 'image/x-icon', 'image/vnd.microsoft.icon'].freezehas_many :orders, class_name: 'Spree::Order'- has_many :payment_methods, class_name: 'Spree::PaymentMethod'++ has_many :store_payment_methods, class_name: 'Spree::StorePaymentMethod', dependent: :destroy+ has_many :payment_methods, through: :store_payment_methods, class_name: 'Spree::PaymentMethod'has_many :menusdiff --git a/core/app/models/spree/store_payment_method.rb b/core/app/models/spree/store_payment_method.rbnew file mode 100644index 0000000000..7d41005569--- /dev/null+++ b/core/app/models/spree/store_payment_method.rb@@ -0,0 +1,11 @@+module Spree+ class StorePaymentMethod < Spree::Base+ self.table_name = 'spree_payment_methods_stores'++ belongs_to :store, class_name: 'Spree::Store', touch: true+ belongs_to :payment_method, class_name: 'Spree::PaymentMethod', touch: true++ validates :store, :payment_method, presence: true+ validates :store_id, uniqueness: { scope: :product_id }+ end+enddiff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 42b377ae1c..dfea308670 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -549,9 +549,9 @@ en:adjustment_total: Adjustment Totaladjustments: Adjustmentsadmin:- show_orders_for_all_stores: Show orders for all stores- show_products_for_all_stores: Show products for all stores- show_menus_for_all_stores: Show menus for all stores+ show_orders_for_all_stores: Show Orders for all stores+ show_products_for_all_stores: Show Products for all stores+ show_payment_methods_for_all_stores: Show Payment Methods for all storestab:configuration: Configurationcontent: Content