Sha256: 1ff094c27b47eb5e01cac421fddbd3bf9ad6c89c8b7ada52ee756fc87c25bba4

Contents?: true

Size: 803 Bytes

Versions: 5

Compression:

Stored size: 803 Bytes

Contents

module Workarea
  decorate Admin::CategorizationsController, with: :browse_option do
    def create
      ids = BrowseOptionIds.all_for(@product.model)

      Catalog::Category.in(id: params[:category_ids]).each do |category|
        ids.each { |id| category.product_ids.prepend(id) }
        category.save!
      end

      flash[:success] = t('workarea.admin.categorizations.flash_messages.added')
      redirect_to catalog_product_categorizations_path(@product)
    end

    def destroy
      category = Catalog::Category.find_by(slug: params[:id])
      ids = BrowseOptionIds.all_for(@product.model)
      category.product_ids.reject! { |id| ids.include?(id) }
      category.save!

      flash[:success] = t('workarea.admin.categorizations.flash_messages.removed')
      head :ok
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-browse_option-2.2.0 app/controllers/workarea/admin/categorizations_controller.decorator
workarea-browse_option-2.1.9 app/controllers/workarea/admin/categorizations_controller.decorator
workarea-browse_option-2.1.8 app/controllers/workarea/admin/categorizations_controller.decorator
workarea-browse_option-2.1.7 app/controllers/workarea/admin/categorizations_controller.decorator
workarea-browse_option-2.1.6 app/controllers/workarea/admin/categorizations_controller.decorator