From cd8e20cf1989b3bc2d738e3995c0e22137c509cc Mon Sep 17 00:00:00 2001 From: mrbrdo Date: Wed, 27 Apr 2022 23:24:54 +0200 Subject: [PATCH] Correctly calculate last_modified_index when the @products scope is using GROUP BY In this case, maximum(:updated_at) is not a single value but rather a hash. --- app/controllers/spree/products_controller.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/products_controller.rb b/app/controllers/spree/products_controller.rb index 3ed7340914..9fdc999ea3 100644 --- a/app/controllers/spree/products_controller.rb +++ b/app/controllers/spree/products_controller.rb @@ -107,7 +107,15 @@ def etag_show alias product_etag etag_show def last_modified_index - products_last_modified = @products.maximum(:updated_at)&.utc if @products.respond_to?(:maximum) + if @products.respond_to?(:maximum) + if max_updated_at = @products.maximum(:updated_at) + if max_updated_at.kind_of?(Hash) + products_last_modified = max_updated_at.values.max&.utc + else + products_last_modified = max_updated_at.utc + end + end + end current_store_last_modified = current_store.updated_at.utc [products_last_modified, current_store_last_modified].compact.max