Skip to content

Commit

Permalink
Merge pull request #3934 from nirnaeth/promotion_rule_product_limit
Browse files Browse the repository at this point in the history
Promotion rule product limit improvements
  • Loading branch information
kennyadsl authored Apr 30, 2021
2 parents 7f57b4c + 6aa7c0c commit bcd714d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ $.fn.productAutocomplete = function (options) {
initSelection: function (element, callback) {
$.get(Spree.pathFor('admin/search/products'), {
ids: element.val().split(','),
token: Spree.api_key
token: Spree.api_key,
show_all: true
}, function (data) {
callback(multiple ? data.products : data.products[0]);
});
Expand Down
12 changes: 11 additions & 1 deletion backend/app/controllers/spree/admin/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ def products
@products = Spree::Product.ransack(params[:q]).result
end

@products = @products.distinct.page(params[:page]).per(params[:per_page])
@products = list_products
expires_in 15.minutes, public: true
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
end

private

def list_products
if params[:show_all]
@products.distinct.page(params[:page])
else
@products.distinct.page(params[:page]).per(params[:per_page])
end
end
end
end
end
20 changes: 19 additions & 1 deletion backend/spec/controllers/spree/admin/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,30 @@ def starting_letters(string)
end
end

context 'when idds param is not present' do
context 'when ids param is not present' do
let(:params) { { q: { name_cont: 'jersey' } } }

it_should_behave_like 'product search' do
let(:expected_products) { [product_one, product_two] }
end
end

context 'when all products are requested to be shown' do
context 'when a per page limit is set' do
let(:params) { { show_all: true, per_page: 1 } }

it_should_behave_like 'product search' do
let(:expected_products) { [product_one, product_two] }
end
end

context 'when a per page limit is not set' do
let(:params) { { show_all: true } }

it_should_behave_like 'product search' do
let(:expected_products) { [product_one, product_two] }
end
end
end
end
end

0 comments on commit bcd714d

Please sign in to comment.