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
Ensure we're always associating Payment Method with the current store
Damian Legawiec65b4c13a6cbf
diff --git a/backend/app/controllers/spree/admin/payment_methods_controller.rb b/backend/app/controllers/spree/admin/payment_methods_controller.rbindex d8f6a4c707..bb679ddcb1 100644--- a/backend/app/controllers/spree/admin/payment_methods_controller.rb+++ b/backend/app/controllers/spree/admin/payment_methods_controller.rb@@ -10,7 +10,7 @@ module Spreedef create@payment_method = params[:payment_method].delete(:type).constantize.new(payment_method_params)@object = @payment_method- set_store+ ensure_current_storeinvoke_callbacks(:create, :before)if @payment_method.saveinvoke_callbacks(:create, :after)@@ -30,7 +30,7 @@ module Spreetype: payment_method_type,updated_at: Time.current)- @payment_method = PaymentMethod.find(params[:id])+ @payment_method = scope.find(params[:id])endattributes = payment_method_params.merge(preferences_params)@@ -39,6 +39,7 @@ module Spreeendif @payment_method.update(attributes)+ ensure_current_storeinvoke_callbacks(:update, :after)flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:payment_method))redirect_to spree.edit_admin_payment_method_path(@payment_method)diff --git a/backend/app/views/spree/admin/payment_methods/_form.html.erb b/backend/app/views/spree/admin/payment_methods/_form.html.erbindex b60b4c9306..bef9dc34ec 100644--- a/backend/app/views/spree/admin/payment_methods/_form.html.erb+++ b/backend/app/views/spree/admin/payment_methods/_form.html.erb@@ -24,10 +24,12 @@<%= text_area :payment_method, :description, { cols: 60, rows: 6, class: 'form-control' } %><% end %>- <div data-hook="store" class="form-group">- <%= label_tag :payment_method_stores, Spree.t(:stores) %>- <%= collection_select(:payment_method, :store_ids, @stores, :id, :unique_name, {}, { multiple: true, class: 'select2' }) %>- </div>+ <% if @payment_method.persisted? %>+ <div data-hook="store" class="form-group">+ <%= label_tag :payment_method_stores, Spree.t(:stores) %>+ <%= collection_select(:payment_method, :store_ids, @stores, :id, :unique_name, {}, { multiple: true, class: 'select2' }) %>+ </div>+ <% end %><div data-hook="display" class="form-group"><%= label_tag :payment_method_display_on, Spree.t(:display) %>diff --git a/backend/spec/features/admin/configuration/payment_methods_spec.rb b/backend/spec/features/admin/configuration/payment_methods_spec.rbindex 14c410847d..c292914c0b 100644--- a/backend/spec/features/admin/configuration/payment_methods_spec.rb+++ b/backend/spec/features/admin/configuration/payment_methods_spec.rb@@ -66,43 +66,39 @@ describe 'Payment Methods', type: :feature doexpect(page).to have_select('payment_method_store_ids', selected: store.unique_name)end-- it 'is able to create a new payment method with 2 stores' do- within find('#contentHeader') do- click_link 'admin_new_payment_methods_link'- end-- expect(page).to have_content('New Payment Method')- fill_in 'payment_method_name', with: 'check90'- fill_in 'payment_method_description', with: 'check90 desc'- select 'PaymentMethod::Check', from: 'gtwy-type'-- select2 store_1.unique_name, from: 'Stores'- select2 store_3.unique_name, from: 'Stores'-- click_button 'Create'- expect(page).to have_content('successfully created!')- expect(page).to have_selector('li.select2-selection__choice', text: store_1.unique_name)- expect(page).not_to have_selector('li.select2-selection__choice', text: store_2.unique_name)- expect(page).to have_selector('li.select2-selection__choice', text: store_3.unique_name)- endendcontext 'admin editing a payment method', js: true dobefore do- create(:check_payment_method)- refresh-- within('table#listing_payment_methods') do- click_icon(:edit)- end+ visit spree.edit_admin_payment_method_path(check_payment_method)end+ let!(:check_payment_method) { create(:check_payment_method, name: 'Check') }+it 'is able to edit an existing payment method' dofill_in 'payment_method_name', with: 'Payment 99'click_button 'Update'expect(page).to have_content('successfully updated!')expect(page).to have_field('payment_method_name', with: 'Payment 99')++ expect(check_payment_method.reload.stores).to contain_exactly(store)+ end++ it 'is able to associate payment method with 2 stores' do+ expect(page).to have_content('Check')++ select2_open label: 'Stores'+ select2_search store_1.unique_name, from: 'Stores'+ select2_select store_1.unique_name, from: 'Stores', match: :first++ select2_open label: 'Stores'+ select2_search store_3.unique_name, from: 'Stores'+ select2_select store_3.unique_name, from: 'Stores', match: :first++ click_button 'Update'+ expect(page).to have_content('successfully updated!')++ expect(check_payment_method.reload.stores).to contain_exactly(store, store_1, store_3)endit 'displays validation errors' do