Merge pull request #6268 from yihyang/master-yy-added-product-sorting

Sort products alphabetically in OC edit/create page
This commit is contained in:
Maikel
2020-11-13 13:29:54 +11:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -31,7 +31,7 @@ class ExchangeProductsRenderer
end
def supplied_products(enterprises_query_matcher)
products_relation = Spree::Product.where(supplier_id: enterprises_query_matcher)
products_relation = Spree::Product.where(supplier_id: enterprises_query_matcher).order(:name)
filter_visible(products_relation)
end

View File

@@ -14,6 +14,13 @@ describe ExchangeProductsRenderer do
expect(products.first.supplier.name).to eq exchange.variants.first.product.supplier.name
end
it "loads products in order" do
products = renderer.exchange_products(true, exchange.sender)
sorted_products_names = products.map(&:name).sort
expect(products.map(&:name)).to eq(sorted_products_names)
end
end
describe "for an outgoing exchange" do
@@ -27,6 +34,13 @@ describe ExchangeProductsRenderer do
expect(suppliers).to include products.second.supplier.name
end
it "loads products in order" do
products = renderer.exchange_products(false, exchange.receiver)
sorted_products_names = products.map(&:name).sort
expect(products.map(&:name)).to eq(sorted_products_names)
end
context "showing products from coordinator inventory only" do
before { order_cycle.update prefers_product_selection_from_coordinator_inventory_only: true }