From 40b8eb470ce49afd48de438853a83121e32e3a71 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 12 Mar 2020 19:12:06 +0100 Subject: [PATCH 1/4] Fix deprecation warning for use of #all --- app/controllers/spree/admin/reports_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/reports_controller.rb b/app/controllers/spree/admin/reports_controller.rb index ec08bca29c..78381a9d63 100644 --- a/app/controllers/spree/admin/reports_controller.rb +++ b/app/controllers/spree/admin/reports_controller.rb @@ -247,7 +247,7 @@ module Spree end def suppliers_of_products_distributed_by(distributors) - distributors.map { |d| Spree::Product.in_distributor(d).includes(:supplier).all }. + distributors.map { |d| Spree::Product.in_distributor(d).includes(:supplier).to_a }. flatten.map(&:supplier).uniq end From e24d8d71045b76e0aebd0696da2409ac59eb5250 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 12 Mar 2020 19:12:36 +0100 Subject: [PATCH 2/4] Fix deprecation warning for use of #includes without #references --- lib/open_food_network/reports/line_items.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open_food_network/reports/line_items.rb b/lib/open_food_network/reports/line_items.rb index 4e272a7c13..59d9901552 100644 --- a/lib/open_food_network/reports/line_items.rb +++ b/lib/open_food_network/reports/line_items.rb @@ -21,7 +21,7 @@ module OpenFoodNetwork end if line_item_includes.present? - line_items = line_items.includes(*line_item_includes) + line_items = line_items.includes(*line_item_includes).references(:line_items) end editable_line_items = editable_line_items(line_items) From 1cba129432c6d430e6139744d0a5c750e718707d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 12 Mar 2020 19:13:15 +0100 Subject: [PATCH 3/4] Ensure line_item.variant succeeds when variant is soft-deleted --- app/models/spree/line_item_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index b3456d7ba9..7012cec9ec 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -73,7 +73,7 @@ Spree::LineItem.class_eval do def variant # Overridden so that LineItems always have access to soft-deleted Variant attributes - Spree::Variant.unscoped { super } + Spree::Variant.unscoped { super } || Spree::Variant.unscoped.find(self.variant_id) end def cap_quantity_at_stock! From f1b64e90e08f7b48d1f31420946ccf9542e66f03 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 25 Mar 2020 11:49:14 +0000 Subject: [PATCH 4/4] Add comment to explain unusual fix --- app/models/spree/line_item_decorator.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 7012cec9ec..37637f7564 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -71,8 +71,10 @@ Spree::LineItem.class_eval do where('spree_adjustments.id IS NULL') } + # Overridden so that LineItems always have access to soft-deleted Variant attributes + # In some situations, unscoped super will be nil, in these cases we fetch the variant using the variant_id + # See isssue #4946 for more details def variant - # Overridden so that LineItems always have access to soft-deleted Variant attributes Spree::Variant.unscoped { super } || Spree::Variant.unscoped.find(self.variant_id) end