Files
openfoodnetwork/app/services/variant_deleter.rb
Maikel Linke b4d1e48693 Update soft-delete of variants
Spree changed their way of soft-deleting variants from calling `delete`
to calling `destroy`. We don't need our own implementation any more.
2019-02-19 14:25:18 +11:00

18 lines
359 B
Ruby

# Checks the validity of a soft-delete call.
class VariantDeleter
def delete(variant)
if only_variant_on_product?(variant)
variant.errors.add :product, I18n.t(:spree_variant_product_error)
return false
end
variant.destroy
end
private
def only_variant_on_product?(variant)
variant.product.variants == [variant]
end
end