From af07358914d6cf2a08aa008e56eeb6e457c81205 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 2 Oct 2024 15:05:20 +1000 Subject: [PATCH] Assume on-demand is false by default We have only one stock location and that has the default set to false. Now we can simplify code. The mentioned Bugsnag notification has not been found. The stock item is always present in this case but it doesn't hurt to guard against it with `&.`. --- app/models/concerns/variant_stock.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/app/models/concerns/variant_stock.rb b/app/models/concerns/variant_stock.rb index 2e5023d46c..710095502f 100644 --- a/app/models/concerns/variant_stock.rb +++ b/app/models/concerns/variant_stock.rb @@ -43,19 +43,9 @@ module VariantStock def on_demand # A variant that has not been saved yet or has been soft-deleted doesn't have a stock item # This provides a default value for variant.on_demand - # using Spree::StockLocation.backorderable_default - return Spree::StockLocation.first.backorderable_default if new_record? || deleted? + return false if new_record? || deleted? - # This can be removed unless we have seen this error in Bugsnag recently - if stock_item.nil? - Bugsnag.notify( - RuntimeError.new("Variant #stock_item called, but the stock_item does not exist!"), - object: as_json - ) - return Spree::StockLocation.first.backorderable_default - end - - stock_item.backorderable? + stock_item&.backorderable? end # Sets whether the variant can be ordered on demand or not. Note that