mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract to class ExchangeVariantDeleter
This commit is contained in:
@@ -50,7 +50,7 @@ Spree::Admin::ProductsController.class_eval do
|
||||
|
||||
delete_stock_params_and_set_after do
|
||||
super
|
||||
remove_product_from_order_cycles if original_supplier != @product.supplier_id
|
||||
ExchangeVariantDeleter.new.delete(@product) if original_supplier != @product.supplier_id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -193,13 +193,6 @@ Spree::Admin::ProductsController.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def remove_product_from_order_cycles
|
||||
variant_ids = @product.variants.map(&:id)
|
||||
ExchangeVariant.
|
||||
where(variant_id: variant_ids).
|
||||
delete_all
|
||||
end
|
||||
|
||||
def set_product_master_variant_price_to_zero
|
||||
@product.price = 0 if @product.price.nil?
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ class Spree::ProductSet < ModelSet
|
||||
end
|
||||
product.save if errors.empty?
|
||||
|
||||
remove_product_from_order_cycles(product) if original_supplier != product.supplier_id
|
||||
ExchangeVariantDeleter.new.delete(product) if original_supplier != product.supplier_id
|
||||
end
|
||||
|
||||
def validate_presence_of_unit_value(product, variant)
|
||||
@@ -64,13 +64,6 @@ class Spree::ProductSet < ModelSet
|
||||
product.errors.add(:unit_value, "can't be blank")
|
||||
end
|
||||
|
||||
def remove_product_from_order_cycles(product)
|
||||
variant_ids = product.variants.map(&:id)
|
||||
ExchangeVariant.
|
||||
where(variant_id: variant_ids).
|
||||
delete_all
|
||||
end
|
||||
|
||||
def update_product_variants(product, attributes)
|
||||
return true unless attributes[:variants_attributes]
|
||||
update_variants_attributes(product, attributes[:variants_attributes])
|
||||
|
||||
8
app/services/exchange_variant_deleter.rb
Normal file
8
app/services/exchange_variant_deleter.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class ExchangeVariantDeleter
|
||||
def delete(product)
|
||||
variant_ids = product.variants.map(&:id)
|
||||
ExchangeVariant.
|
||||
where(variant_id: variant_ids).
|
||||
delete_all
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user