Class: Caboose::ShippingAddressesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::ShippingAddressesController
- Defined in:
- app/controllers/caboose/shipping_addresses_controller.rb
Instance Method Summary collapse
-
#admin_json ⇒ Object
GET /admin/orders/:order_id/shipping-address/json.
-
#admin_update ⇒ Object
PUT /admin/orders/:order_id/shipping-address.
-
#my_account_json ⇒ Object
GET /my-account/orders/:order_id/shipping-address/json.
-
#my_account_update ⇒ Object
PUT /my-account/orders/:order_id/shipping-address.
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, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_json ⇒ Object
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_update ⇒ Object
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 |
# 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 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_json ⇒ Object
GET /my-account/orders/:order_id/shipping-address/json
46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/caboose/shipping_addresses_controller.rb', line 46 def my_account_json return if !logged_in? order = Order.find(params[:order_id]) if order.customer_id != logged_in_user.id render :json => { :error => "The given order does not belong to you." } return end render :json => order.shipping_address end |
#my_account_update ⇒ Object
PUT /my-account/orders/:order_id/shipping-address
57 58 59 60 61 62 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 |
# File 'app/controllers/caboose/shipping_addresses_controller.rb', line 57 def my_account_update return if !logged_in? resp = Caboose::StdClass.new order = Order.find(params[:order_id]) if order.customer_id != logged_in_user.id render :json => { :error => "The given order does not belong to you." } return end sa = order.shipping_address 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 |