mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Spree changed their way of soft-deleting variants from calling `delete` to calling `destroy`. We don't need our own implementation any more.
18 lines
359 B
Ruby
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
|