Extract to class ExchangeVariantDeleter

This commit is contained in:
luisramos0
2019-10-17 18:21:49 +01:00
parent 8857404ddf
commit b625ea0c61
3 changed files with 10 additions and 16 deletions

View File

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

View File

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

View 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