Sha256: e0b6677e16fb60062e54d7245bf1c89f1ffaede3d9db133e75cbda7bff808af6

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

module KktShoppe
  class ProductsController < KktShoppe::ApplicationController

    before_filter { @active_nav = :products }
    before_filter { params[:id] && @product = KktShoppe::Product.root.find(params[:id]) }

    def index
      @products = KktShoppe::Product.root.includes(:translations, :stock_level_adjustments, :product_categories, :variants).order(:name).group_by(&:product_category).sort_by { |cat,pro| cat.name }
    end

    def new
      @product = KktShoppe::Product.new
    end

    def create
      @product = KktShoppe::Product.new(safe_params)
      if @product.save
        redirect_to :products, :flash => {:notice =>  t('kkt_shoppe.products.create_notice') }
      else
        render :action => "new"
      end
    end

    def edit
    end

    def update
      if @product.update(safe_params)
        redirect_to [:edit, @product], :flash => {:notice => t('kkt_shoppe.products.update_notice') }
      else
        render :action => "edit"
      end
    end

    def destroy
      @product.destroy
      redirect_to :products, :flash => {:notice =>  t('kkt_shoppe.products.destroy_notice')}
    end

    def import
      if request.post?
        if params[:import].nil?
          redirect_to import_products_path, :flash => {:alert => I18n.t('kkt_shoppe.imports.errors.no_file')}
        else
          KktShoppe::Product.import(params[:import][:import_file])
          redirect_to products_path, :flash => {:notice => I18n.t("kkt_shoppe.products.imports.success")}
        end
      end
    end

    private

    def safe_params
      file_params = [:file, :parent_id, :role, :parent_type, :file => []]
      params[:product].permit(:name, :sku, :permalink, :description, :short_description, :weight, :price, :cost_price, :tax_rate_id, :stock_control, :active, :featured, :in_the_box, :attachments => [:default_image => file_params, :data_sheet => file_params, :extra => file_params], :product_attributes_array => [:key, :value, :searchable, :public], :product_category_ids => [])
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kkt_shoppe-2.0.2 app/controllers/kkt_shoppe/products_controller.rb
kkt_shoppe-2.0.1 app/controllers/kkt_shoppe/products_controller.rb
kkt_shoppe-2.0.0 app/controllers/kkt_shoppe/products_controller.rb
kkt_shoppe-1.3.0 app/controllers/kkt_shoppe/products_controller.rb
kkt_shoppe-1.1.2 app/controllers/kkt_shoppe/products_controller.rb