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, 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