Class: Spree::Admin::AddOnMallPricesController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/add_on_mall_prices_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/spree/admin/add_on_mall_prices_controller.rb', line 36

def create
  begin
    params[:add_on_mall_prices].each_value { |value|
      @add_on_mall_prices = Spree::AddOnMallPrice.new(value)
      @add_on_mall_prices.save
      }
        respond_to do |format|
        flash[:success] = t('add_on.notice_messages.admin_product_variant_add_on_mall_price_variant_created')
          format.html { redirect_to admin_product_add_on_mall_prices_path }
        format.json { render action: 'index', status: :created, location: @add_on_mall_prices }
        end
  rescue
        respond_to do |format|
        flash[:error] = t('add_on.notice_messages.admin_product_variant_add_on_mall_price_variant_has_error')
        format.html { render action: 'new' }
        format.json { render json: @add_on_mall_prices.errors }
        end
  end

end

#destroyObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/spree/admin/add_on_mall_prices_controller.rb', line 78

def destroy
  @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

  respond_with(@variant) do |format|
    format.html { redirect_to admin_product_maker_variant_path(params[:product_id]) }
    format.js  { render_js_for_destroy }
  end
end

#editObject



28
29
30
31
32
33
34
# File 'app/controllers/spree/admin/add_on_mall_prices_controller.rb', line 28

def edit
  session[:return_to] = request.url
  @add_on_malls = Spree::AddOnMall.order(:name)
#        @add_on_malls = Spree::AddOnMall.includes(:add_on_mall_prices).where(Spree::AddOnMallPrice.arel_table[:variant_id].eq(params[:variant_id])).references(:add_on_mall_prices).order(:name)
  @add_on_mall_prices = Spree::AddOnMallPrice.includes(:add_on_mall).where(:variant_id => params[:variant_id])
  render :edit
end

#indexObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/admin/add_on_mall_prices_controller.rb', line 17

def index
  session[:return_to] = request.url
  @product = Spree::Product.find_by_permalink!(params[:product_id])
  if @product.has_variants?
    @variant = @product.variants.page(params[:page])
  else
    @variant = Spree::Variant.where(:id => @product.master.id).page(params[:page])
  end
  render :index
end

#newObject



6
7
8
9
10
# File 'app/controllers/spree/admin/add_on_mall_prices_controller.rb', line 6

def new
  session[:return_to] ||= request.referer
  @add_on_malls = Spree::AddOnMall.includes(:add_on_mall_prices).all
  @add_on_mall_prices = Spree::AddOnMallPrice.where(:variant_id => params[:variant_id])
end

#showObject



12
13
14
15
# File 'app/controllers/spree/admin/add_on_mall_prices_controller.rb', line 12

def show
  session[:return_to] ||= request.referer
  redirect_to( :action => :edit )
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/spree/admin/add_on_mall_prices_controller.rb', line 57

def update
  begin
    params[:add_on_mall_prices].each_value { |value|
      @add_on_mall_prices = Spree::AddOnMallPrice.where(:variant_id => value["variant_id"], :add_on_mall_id => value["add_on_mall_id"]).first_or_initialize
      @add_on_mall_prices.update(value)
      logger.info @add_on_mall_prices.errors.inspect
      }
    respond_to do |format|
      flash[:success] = t('add_on.notice_messages.admin_product_variant_add_on_mall_price_variant_updated')
      format.html { redirect_to :action => :index }
      format.json { head :no_content }
    end
  rescue
    respond_to do |format|
      flash[:error] = t('add_on.notice_messages.admin_product_variant_add_on_mall_price_variant_has_error')
      format.html { render action: 'edit' }
      format.json { render json: @add_on_mall_price_variant.errors }
    end
  end
end