From 3e9d1bfe1f91c48bcaad56ad2716ff4fc32f1ffc Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 22 Mar 2021 14:52:42 +0000 Subject: [PATCH] Add defensive more code in not_hidden_for scope --- app/models/spree/variant.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 71c10a16e3..ed94fba1e6 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -109,12 +109,13 @@ module Spree } scope :not_hidden_for, lambda { |enterprise| - return where("1=0") if enterprise.blank? + enterprise_id = enterprise&.id.to_i + return none if enterprise_id < 1 joins(" LEFT OUTER JOIN (SELECT * FROM inventory_items - WHERE enterprise_id = #{enterprise.andand.id}) + WHERE enterprise_id = #{enterprise_id}) AS o_inventory_items ON o_inventory_items.variant_id = spree_variants.id") .where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true)