Class: Caboose::BillingAddressesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #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, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_jsonObject


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

def admin_json
  return if !user_is_allowed('invoices', 'edit')    
  invoice = Invoice.find(params[:invoice_id])      
  render :json => invoice.billing_address      
end

#admin_updateObject


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
44
45
46
47
# File 'app/controllers/caboose/billing_addresses_controller.rb', line 12

def admin_update
  return if !user_is_allowed('invoices', 'edit')
  
  resp = Caboose::StdClass.new({'attributes' => {}})
  invoice = Invoice.find(params[:invoice_id])    
  sa = invoice.billing_address
  
  if sa.nil?
    sa = Address.create
    invoice.billing_address_id = sa.id
    invoice.save
  end
  
  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
  resp.success = save && sa.save      
  render :json => resp
end

#my_account_jsonObject


52
53
54
55
56
57
58
59
60
# File 'app/controllers/caboose/billing_addresses_controller.rb', line 52

def 
  return if !logged_in?    
  invoice = Invoice.find(params[:invoice_id])      
  if invoice.customer_id != logged_in_user.id        
    render :json => { :error => "The given invoice does not belong to you." } 
    return
  end
  render :json => invoice.billing_address      
end

#my_account_updateObject


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/caboose/billing_addresses_controller.rb', line 63

def 
  return if !logged_in?
  
  resp = Caboose::StdClass.new
  invoice = Invoice.find(params[:invoice_id])
  if invoice.customer_id != logged_in_user.id        
    render :json => { :error => "The given invoice does not belong to you." } 
    return
  end                
  
  sa = invoice.billing_address      
  if sa.nil?
    sa = Address.create
    invoice.billing_address_id = sa.id
    invoice.save
  end
  
  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
  resp.success = save && sa.save      
  render :json => resp
end