From 69b57544f15790b5d1dd4fb68bdd41f15936da32 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 4 Mar 2020 15:18:04 +0000 Subject: [PATCH] Bring Spree::Variant#active so that we can make it return just variants without includes This makes the variants returned not readonly in rails 4 and thus fixes a spec in Spree::VariantsController#destroy --- app/models/spree/variant_decorator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 566394d946..bd4b2bcb14 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -85,6 +85,10 @@ Spree::Variant.class_eval do ] end + def self.active(currency = nil) + where(id: joins(:prices).where(deleted_at: nil).where('spree_prices.currency' => currency || Spree::Config[:currency]).where('spree_prices.amount IS NOT NULL').select("spree_variants.id")) + end + # We override in_stock? to avoid depending on the non-overridable method Spree::Stock::Quantifier.can_supply? # VariantStock implements can_supply? itself which depends on overridable methods def in_stock?(quantity = 1)