From f6f24ca983b9c04c45c358674db536a3c7cc59e1 Mon Sep 17 00:00:00 2001 From: Nick Van Doorn Date: Fri, 19 Jan 2024 11:29:42 -0800 Subject: [PATCH 1/2] Add failing feature spec for stock location bug Before we fix this bug, we should reproduce it in a feature spec. Co-authored-by: An Stewart Co-authored-by: Adam Mueller (cherry picked from commit 24090382f0d754c8721b78ed66511054f0e44b1e) --- backend/spec/features/admin/stock_items_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/spec/features/admin/stock_items_spec.rb b/backend/spec/features/admin/stock_items_spec.rb index f88dbb47bf5..19718993e48 100644 --- a/backend/spec/features/admin/stock_items_spec.rb +++ b/backend/spec/features/admin/stock_items_spec.rb @@ -6,8 +6,10 @@ stub_authorization! let(:admin_user) { create(:admin_user) } - let!(:variant_1) { create(:variant) } - let!(:variant_2) { create(:variant) } + let!(:variant_1) { create(:variant, product: product1) } + let!(:variant_2) { create(:variant, product: product2) } + let(:product1) { create(:product, name: 'Ruby Shirt') } + let(:product2) { create(:product, name: 'Solidus Shirt') } let!(:stock_location) { create(:stock_location_without_variant_propagation) } scenario 'User can add a new stock locations to any variant' do @@ -19,4 +21,12 @@ end expect(page).to have_content("Created successfully") end + + scenario 'searching by variant' do + visit spree.admin_stock_items_path + fill_in 'SKU or Option Value', with: 'Ruby' + click_on 'Filter Results' + expect(page).to have_content "Ruby Shirt" + expect(page).to_not have_content "Solidus Shirt" + end end From 0bef762cc746aff6c02fd7c5edf28b15265ca968 Mon Sep 17 00:00:00 2001 From: Nick Van Doorn Date: Fri, 26 Jan 2024 14:40:12 -0800 Subject: [PATCH 2/2] Remove order by sku from variant scope This "fixes" the variant scope issue but I'm not sure it's the solution we want. I suppose it depends if ordering by sku is important here. Co-authored-by: An Stewart (cherry picked from commit c4bd75a78a812d45c7784e2bb21e471ecc7574c9) --- backend/app/controllers/spree/admin/stock_items_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/controllers/spree/admin/stock_items_controller.rb b/backend/app/controllers/spree/admin/stock_items_controller.rb index 7669a41f19c..8750bc9ca71 100644 --- a/backend/app/controllers/spree/admin/stock_items_controller.rb +++ b/backend/app/controllers/spree/admin/stock_items_controller.rb @@ -56,7 +56,7 @@ def load_stock_management_data def variant_scope scope = Spree::Variant .accessible_by(current_ability) - .distinct.order(:sku) + .distinct .includes( :images, stock_items: :stock_location,