From e06df7d658232d284a7a2e73be97837a8a8bed20 Mon Sep 17 00:00:00 2001 From: zanetagebka Date: Thu, 6 Jun 2024 10:06:45 +0200 Subject: [PATCH] - Refactor method to fix StringConcatenation cop --- app/services/products_renderer.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/services/products_renderer.rb b/app/services/products_renderer.rb index d7296e9fa1..57608f849a 100644 --- a/app/services/products_renderer.rb +++ b/app/services/products_renderer.rb @@ -68,23 +68,26 @@ class ProductsRenderer end def products_order - if (distributor.preferred_shopfront_product_sorting_method == "by_producer") && - distributor.preferred_shopfront_producer_order.present? - distributor - .preferred_shopfront_producer_order - .split(",").map { |id| "spree_products.supplier_id=#{id} DESC" } - .join(", ") + ", spree_products.name ASC, spree_products.id ASC" + if distributor.preferred_shopfront_product_sorting_method == "by_producer" && + distributor.preferred_shopfront_producer_order.present? + order_by_producer = distributor + .preferred_shopfront_producer_order + .split(",").map { |id| "spree_products.supplier_id=#{id} DESC" } + .join(", ") + "#{order_by_producer}, spree_products.name ASC, spree_products.id ASC" elsif distributor.preferred_shopfront_product_sorting_method == "by_category" && - distributor.preferred_shopfront_taxon_order.present? - distributor - .preferred_shopfront_taxon_order - .split(",").map { |id| "first_variant.primary_taxon_id=#{id} DESC" } - .join(", ") + ", spree_products.name ASC, spree_products.id ASC" + distributor.preferred_shopfront_taxon_order.present? + order_by_category = distributor + .preferred_shopfront_taxon_order + .split(",").map { |id| "first_variant.primary_taxon_id=#{id} DESC" } + .join(", ") + "#{order_by_category}, spree_products.name ASC, spree_products.id ASC" else "spree_products.name ASC, spree_products.id" end end + def variants_for_shop @variants_for_shop ||= begin scoper = OpenFoodNetwork::ScopeVariantToHub.new(distributor)