From 4054bdd7225943ad2803a3d4f3d8a1f42b9b2a70 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 29 Apr 2020 17:33:49 +0200 Subject: [PATCH] Add Bugsnag call for "variant with no stock item" case --- app/models/concerns/variant_stock.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/concerns/variant_stock.rb b/app/models/concerns/variant_stock.rb index 5a6094adf4..dedf667c1b 100644 --- a/app/models/concerns/variant_stock.rb +++ b/app/models/concerns/variant_stock.rb @@ -44,6 +44,15 @@ module VariantStock # This provides a default value for variant.on_demand using Spree::StockLocation.backorderable_default return Spree::StockLocation.first.backorderable_default 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? end