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
This commit is contained in:
Luis Ramos
2020-03-04 15:18:04 +00:00
parent 940423acfc
commit 69b57544f1

View File

@@ -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)