mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
11068: update product/varaint delete actions
This commit is contained in:
@@ -46,21 +46,31 @@ class ProductsReflex < ApplicationReflex
|
||||
render_products_form_with_flash
|
||||
end
|
||||
|
||||
def delete_product(product_id)
|
||||
if ProductDeleter.delete(product_id)
|
||||
def delete_product(id)
|
||||
authorize! :delete, Spree::Product
|
||||
product = product_finder(id).find_product
|
||||
authorize! :delete, product
|
||||
|
||||
if product.destroy
|
||||
puts "Deleted Successfully"
|
||||
else
|
||||
puts "Failure"
|
||||
end
|
||||
|
||||
fetch_and_render_products
|
||||
end
|
||||
|
||||
def delete_variant(variant_id)
|
||||
if VariantDeleter.new.delete(variant_id)
|
||||
def delete_variant(id)
|
||||
authorize! :delete, Spree::Variant
|
||||
variant = variant_scope.find(id)
|
||||
authorize! :delete, variant
|
||||
|
||||
if VariantDeleter.new.delete(variant)
|
||||
puts "Deleted Successfully"
|
||||
else
|
||||
puts "Failure"
|
||||
end
|
||||
|
||||
fetch_and_render_products
|
||||
end
|
||||
|
||||
@@ -238,4 +248,12 @@ class ProductsReflex < ApplicationReflex
|
||||
params.permit(products: ::PermittedAttributes::Product.attributes)
|
||||
.to_h.with_indifferent_access
|
||||
end
|
||||
|
||||
def product_finder(id)
|
||||
ProductScopeQuery.new(current_user, {id:})
|
||||
end
|
||||
|
||||
def variant_scope
|
||||
Spree::Variant.active
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# This soft deletes the product
|
||||
class ProductDeleter
|
||||
# @param id [int] ID of the product to be deleted
|
||||
def self.delete(id)
|
||||
product = Spree::Product.find_by(id:)
|
||||
product&.destroy
|
||||
end
|
||||
end
|
||||
@@ -16,6 +16,7 @@ export default class extends ApplicationController {
|
||||
}
|
||||
|
||||
deleteVariant() {
|
||||
window.dispatchEvent(new Event('modal:close'));
|
||||
this.stimulate('Products#delete_variant', this.currentIdValue)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user