Sha256: 39ab41439ba3b6f7555d531c02d8f1e80aedb7da3cf0cba9f1f81da8901ae2f2

Contents?: true

Size: 1.86 KB

Versions: 4

Compression:

Stored size: 1.86 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, :default_image, :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
      params[:product].permit(:name, :sku, :permalink, :description, :short_description, :weight, :price, :cost_price, :tax_rate_id, :stock_control, :default_image_file, :data_sheet_file, :active, :featured, :in_the_box, :product_attributes_array => [:key, :value, :searchable, :public], :product_category_ids => [])
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kkt_shoppe-1.2.1 app/controllers/kkt_shoppe/products_controller.rb
kkt_shoppe-1.2.0 app/controllers/kkt_shoppe/products_controller.rb
kkt_shoppe-1.1.1 app/controllers/kkt_shoppe/products_controller.rb
kkt_shoppe-1.1.0 app/controllers/kkt_shoppe/products_controller.rb