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.

Display only Products and Payment Methods from the current store

Damian Legawiecd8abc51441fb
diff --git a/backend/app/controllers/spree/admin/payment_methods_controller.rb b/backend/app/controllers/spree/admin/payment_methods_controller.rb
index 46f1a1c42e..d8f6a4c707 100644
--- a/backend/app/controllers/spree/admin/payment_methods_controller.rb
+++ b/backend/app/controllers/spree/admin/payment_methods_controller.rb
@@ -60,11 +60,7 @@ module Spree
params[:q] ||= {}
@collection = super.order(position: :asc)
- @collection = if params[:q][:all_stores] == '1'
- super.order(position: :asc)
- else
- scope.order(position: :asc)
- end
+ @collection = scope.order(position: :asc)
@search = @collection.ransack(params[:q])
@collection = @search.result.page(params[:page]).per(params[:per_page])
diff --git a/backend/app/controllers/spree/admin/products_controller.rb b/backend/app/controllers/spree/admin/products_controller.rb
index 453d2a6461..cd77f9f7a7 100644
--- a/backend/app/controllers/spree/admin/products_controller.rb
+++ b/backend/app/controllers/spree/admin/products_controller.rb
@@ -96,7 +96,7 @@ module Spree
end
def find_resource
- Product.with_deleted.friendly.find(params[:id])
+ current_store.products.with_deleted.friendly.find(params[:id])
end
def location_after_save
@@ -119,13 +119,7 @@ module Spree
params[:q][:s] ||= 'name asc'
- # Do not scope by store if the params filter is set to :all_stores,
- # or we are looking to show deleted products. Deleted products do not have any stores attahced.
- @collection = if params[:q][:all_stores] == '1' || params[:q][:deleted_at_null] == '0'
- super
- else
- scope
- end
+ @collection = scope
# Don't delete params[:q][:deleted_at_null] here because it is used in view to check the
# checkbox for 'q[deleted_at_null]'. This also messed with pagination when deleted_at_null is checked.
diff --git a/backend/app/views/spree/admin/payment_methods/index.html.erb b/backend/app/views/spree/admin/payment_methods/index.html.erb
index fef9ea6afd..310f87cdf4 100644
--- a/backend/app/views/spree/admin/payment_methods/index.html.erb
+++ b/backend/app/views/spree/admin/payment_methods/index.html.erb
@@ -11,19 +11,9 @@
<%= 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 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 data-hook="admin_products_index_search_buttons" class="form-actions">
diff --git a/backend/app/views/spree/admin/products/index.html.erb b/backend/app/views/spree/admin/products/index.html.erb
index d33ec86e59..1d657150ee 100644
--- a/backend/app/views/spree/admin/products/index.html.erb
+++ b/backend/app/views/spree/admin/products/index.html.erb
@@ -25,13 +25,6 @@
</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_products_for_all_stores'), class: 'custom-control-label' %>
- </div>
- <% end %>
-
<%= f.field_container :deleted_at_null do %>
<div class="custom-control custom-checkbox">
<%= f.check_box :deleted_at_null, {checked: params[:q][:deleted_at_null] == '0', class: 'custom-control-input'}, '0', '1' %>
diff --git a/backend/spec/features/admin/configuration/payment_methods_spec.rb b/backend/spec/features/admin/configuration/payment_methods_spec.rb
index 52c0b73984..14c410847d 100644
--- a/backend/spec/features/admin/configuration/payment_methods_spec.rb
+++ b/backend/spec/features/admin/configuration/payment_methods_spec.rb
@@ -6,10 +6,10 @@ describe 'Payment Methods', type: :feature do
let(:store) { Spree::Store.default }
let!(:store_1) { create(:store) }
let!(:store_2) { create(:store) }
- let!(:store_3) { create(:store) }
+ let!(:store_3) { create(:store, url: 'another-store.lvh.me') }
- let!(:payment_method_one) { create(:payment_method) }
- let!(:payment_method_two) { create(:payment_method, name: 'Should Be MIA' ,stores: [store_3]) }
+ let!(:payment_method_one) { create(:payment_method, stores: [store]) }
+ let!(:payment_method_two) { create(:payment_method, name: 'Should Be MIA', stores: [store_3]) }
before do
visit spree.admin_payment_methods_path
@@ -20,16 +20,16 @@ describe 'Payment Methods', type: :feature do
within('table#listing_payment_methods') do
expect(page).to have_content(payment_method_one.name)
expect(page).not_to have_content(payment_method_two.name)
- end
- end
- it 'is able to show payment methods for all stores using filter' do
- check 'q_all_stores'
- click_on 'Search'
+ Capybara.app_host = 'http://another-store.lvh.me'
+
+ visit spree.admin_payment_methods_path
- expect(page).to have_checked_field(id: 'q_all_stores')
- expect(page).to have_content(payment_method_one.name)
- expect(page).to have_content(payment_method_two.name)
+ expect(page).not_to have_content(payment_method_one.name)
+ expect(page).to have_content(payment_method_two.name)
+
+ Capybara.app_host = nil
+ end
end
end
diff --git a/backend/spec/features/admin/products/products_spec.rb b/backend/spec/features/admin/products/products_spec.rb
index 2e7ba2c5bb..99226e342a 100644
--- a/backend/spec/features/admin/products/products_spec.rb
+++ b/backend/spec/features/admin/products/products_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe 'Products', type: :feature do
let(:store) { Spree::Store.default }
- let(:other_store) { create(:store)}
+ let(:other_store) { create(:store, name: 'Other Store', url: 'another-store.lvh.me') }
context 'as admin user' do
stub_authorization!
@@ -53,6 +53,18 @@ describe 'Products', type: :feature do
expect(page).not_to have_content('Long T-Shirt')
end
+
+ it 'lists product from the current store' do
+ Capybara.app_host = 'http://another-store.lvh.me'
+
+ visit spree.admin_products_path
+
+ expect(page).not_to have_content('apache baseball cap')
+ expect(page).not_to have_content('zomg shirt')
+ expect(page).to have_content('Long T-Shirt')
+
+ Capybara.app_host = nil
+ end
end
context 'currency displaying' do
@@ -96,24 +108,6 @@ describe 'Products', type: :feature do
expect(page).not_to have_content('apache baseball cap')
end
- it 'filter is able to show products for all stores' do
- create(:product, name: 'apache baseball cap')
- create(:product, name: 'zomg shirt')
- create(:product, name: 'Long T-Shirt', price: 15, stores: [other_store])
-
- visit spree.admin_products_path
- expect(page).to have_content('zomg shirt')
- expect(page).to have_content('apache baseball cap')
- expect(page).not_to have_content('Long T-Shirt')
-
- find('label', text: 'Show Products for all stores').click
- click_on 'Search'
-
- expect(page).to have_content('zomg shirt')
- expect(page).to have_content('apache baseball cap')
- expect(page).to have_content('Long T-Shirt')
- end
-
it 'is able to search products by their properties' do
create(:product, name: 'apache baseball cap', sku: 'A100')
create(:product, name: 'apache baseball cap2', sku: 'B100')