From d4512904eac85597ba7df63d9b79207c8dfd9d02 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 5 Dec 2019 15:37:10 +1100 Subject: [PATCH] Make product order deterministic When products are sorted by name and two products have the same name, their order is undefined. With pagination, two pages can have a different order of products with the same name which then means that two pages can return the same product. Sorting by product id makes sure that the result is always in the same order, for every page. --- app/services/products_renderer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/products_renderer.rb b/app/services/products_renderer.rb index ca9c728267..bfa7f4eaa5 100644 --- a/app/services/products_renderer.rb +++ b/app/services/products_renderer.rb @@ -66,7 +66,7 @@ class ProductsRenderer .split(",").map { |id| "spree_products.primary_taxon_id=#{id} DESC" } .join(", ") + ", spree_products.name ASC, spree_products.id ASC" else - "spree_products.name ASC" + "spree_products.name ASC, spree_products.id" end end