Class: Caboose::ShippingAddressesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/shipping_addresses_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_index, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_jsonObject

GET /admin/orders/:order_id/shipping-address/json



5
6
7
8
9
# File 'app/controllers/caboose/shipping_addresses_controller.rb', line 5

def admin_json
  return if !user_is_allowed('orders', 'edit')    
  order = Order.find(params[:order_id])      
  render :json => order.shipping_address      
end

#admin_updateObject

PUT /admin/orders/:order_id/shipping-address



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/caboose/shipping_addresses_controller.rb', line 12

def admin_update
  return if !user_is_allowed('orders', 'edit')
  
  resp = Caboose::StdClass.new({'attributes' => {}})
  order = Order.find(params[:order_id])    
  sa = order.shipping_address
  Caboose.log(sa.first_name)
  save = true    
  params.each do |name, value|
    case name          
      when 'name'           then sa.name          = value          
      when 'first_name'     then sa.first_name    = value
      when 'last_name'      then sa.last_name     = value
      when 'street'         then sa.street        = value
      when 'address1'       then sa.address1      = value
      when 'address2'       then sa.address2      = value
      when 'company'        then sa.company       = value
      when 'city'           then sa.city          = value
      when 'state'          then sa.state         = value
      when 'province'       then sa.province      = value
      when 'province_code'  then sa.province_code = value
      when 'zip'            then sa.zip           = value
      when 'country'        then sa.country       = value
      when 'country_code'   then sa.country_code  = value
      when 'phone'          then sa.phone         = value
    end
  end          
  Caboose.log(sa.first_name)
  resp.success = save && sa.save
  Caboose.log(sa.first_name)
  render :json => resp
end