app/controllers/spree/admin/variants_controller.rb in solidus_backend-2.1.1 vs app/controllers/spree/admin/variants_controller.rb in solidus_backend-2.2.0.beta1
- old
+ new
@@ -1,16 +1,19 @@
module Spree
module Admin
class VariantsController < ResourceController
+ helper 'spree/admin/products'
+
belongs_to 'spree/product', find_by: :slug
new_action.before :new_before
+ before_action :redirect_on_empty_option_values, only: [:new]
before_action :load_data, only: [:new, :create, :edit, :update]
# override the destroy method to set deleted_at value
# instead of actually deleting the product.
def destroy
- @variant = Variant.find(params[:id])
+ @variant = Spree::Variant.find(params[:id])
if @variant.destroy
flash[:success] = Spree.t('notice_messages.variant_deleted')
else
flash[:success] = Spree.t('notice_messages.variant_not_deleted')
end
@@ -40,14 +43,18 @@
search = Spree::Config.variant_search_class.new(params[:variant_search_term], scope: base_variant_scope)
@collection = search.results.includes(variant_includes).page(params[:page]).per(Spree::Config[:admin_variants_per_page])
end
def load_data
- @tax_categories = TaxCategory.order(:name)
+ @tax_categories = Spree::TaxCategory.order(:name)
end
def variant_includes
[{ option_values: :option_type }, :default_price]
+ end
+
+ def redirect_on_empty_option_values
+ redirect_to admin_product_variants_url(params[:product_id]) if @product.empty_option_values?
end
end
end
end