Class: ChannelAdvisor::Order
Instance Attribute Summary collapse
-
#billing_address ⇒ Object
Returns the value of attribute billing_address.
-
#buyer_email ⇒ Object
Returns the value of attribute buyer_email.
-
#buyer_ip_address ⇒ Object
Returns the value of attribute buyer_ip_address.
-
#cancelled_on ⇒ Object
Returns the value of attribute cancelled_on.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#custom_values ⇒ Object
Returns the value of attribute custom_values.
-
#delivery_date ⇒ Object
Returns the value of attribute delivery_date.
-
#email_opt_in ⇒ Object
Returns the value of attribute email_opt_in.
-
#estimated_ship_date ⇒ Object
Returns the value of attribute estimated_ship_date.
-
#flag_description ⇒ Object
Returns the value of attribute flag_description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#payment ⇒ Object
Returns the value of attribute payment.
-
#reseller_id ⇒ Object
Returns the value of attribute reseller_id.
-
#seller_id ⇒ Object
Returns the value of attribute seller_id.
-
#shipments ⇒ Object
Returns the value of attribute shipments.
-
#shipping_address ⇒ Object
Returns the value of attribute shipping_address.
-
#shipping_instructions ⇒ Object
Returns the value of attribute shipping_instructions.
-
#shopping_cart ⇒ Object
Returns the value of attribute shopping_cart.
-
#state ⇒ Object
Returns the value of attribute state.
-
#status ⇒ Object
Returns the value of attribute status.
-
#total ⇒ Object
Returns the value of attribute total.
-
#transaction_notes ⇒ Object
Returns the value of attribute transaction_notes.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
-
.list(criteria = {}) ⇒ Array<Order>
Retrieve a list of orders, restricted by the provided criteria.
-
.ping ⇒ Boolean
Check authorization for and availability of the order service.
-
.set_export_status(client_order_ids, mark_as_exported) ⇒ boolean, Hash
Set the export status for the provided client order identifiers.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Order
constructor
A new instance of Order.
- #invoice_ship_cost ⇒ Object
- #items_ship_cost ⇒ Object
-
#set_export_status(mark_as_exported) ⇒ Boolean
Set the export status for a given order instance.
-
#total_ship_cost ⇒ Object
set_export_status.
Constructor Details
#initialize(attrs = {}) ⇒ Order
Returns a new instance of Order.
7 8 9 10 11 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 |
# File 'lib/channeladvisor/order.rb', line 7 def initialize(attrs={}) @id = attrs[:order_id].to_i @client_id = attrs[:client_order_identifier] @seller_id = attrs[:seller_order_id] @state = attrs[:order_state] @created_at = attrs[:order_time_gmt] @updated_at = attrs[:last_update_date] @cancelled_on = attrs[:date_cancelled_gmt] @total = attrs[:total_order_amount].to_f @reseller_id = attrs[:reseller_id] @flag_description = attrs[:flag_description] @buyer_email = attrs[:buyer_email_address] @email_opt_in = attrs[:email_opt_in] @buyer_ip_address = attrs[:buyer_ip_address] @transaction_notes = attrs[:transaction_notes] @custom_values = attrs[:custom_value_list] @status = OrderStatus.new(attrs[:order_status]) if attrs[:order_status] @payment = Payment.new(attrs[:payment_info]) if attrs[:payment_info] @billing_address = Address.new(attrs[:billing_info]) if attrs[:billing_info] @shipping_address = Address.new(attrs[:shipping_info]) if attrs[:shipping_info] @shopping_cart = ShoppingCart.new(attrs[:shopping_cart]) if attrs[:shopping_cart] if shipping_info = attrs[:shipping_info] @shipping_instructions = shipping_info[:shipping_instructions] @estimated_ship_date = shipping_info[:estimated_ship_date] @delivery_date = shipping_info[:delivery_date] if shipment_list = shipping_info[:shipment_list] @shipments = arrayify(shipment_list[:shipment]).map { |s| Shipment.new(s) } end end end |
Instance Attribute Details
#billing_address ⇒ Object
Returns the value of attribute billing_address.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def billing_address @billing_address end |
#buyer_email ⇒ Object
Returns the value of attribute buyer_email.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def buyer_email @buyer_email end |
#buyer_ip_address ⇒ Object
Returns the value of attribute buyer_ip_address.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def buyer_ip_address @buyer_ip_address end |
#cancelled_on ⇒ Object
Returns the value of attribute cancelled_on.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def cancelled_on @cancelled_on end |
#client_id ⇒ Object
Returns the value of attribute client_id.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def client_id @client_id end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def created_at @created_at end |
#custom_values ⇒ Object
Returns the value of attribute custom_values.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def custom_values @custom_values end |
#delivery_date ⇒ Object
Returns the value of attribute delivery_date.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def delivery_date @delivery_date end |
#email_opt_in ⇒ Object
Returns the value of attribute email_opt_in.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def email_opt_in @email_opt_in end |
#estimated_ship_date ⇒ Object
Returns the value of attribute estimated_ship_date.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def estimated_ship_date @estimated_ship_date end |
#flag_description ⇒ Object
Returns the value of attribute flag_description.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def flag_description @flag_description end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def id @id end |
#payment ⇒ Object
Returns the value of attribute payment.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def payment @payment end |
#reseller_id ⇒ Object
Returns the value of attribute reseller_id.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def reseller_id @reseller_id end |
#seller_id ⇒ Object
Returns the value of attribute seller_id.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def seller_id @seller_id end |
#shipments ⇒ Object
Returns the value of attribute shipments.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def shipments @shipments end |
#shipping_address ⇒ Object
Returns the value of attribute shipping_address.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def shipping_address @shipping_address end |
#shipping_instructions ⇒ Object
Returns the value of attribute shipping_instructions.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def shipping_instructions @shipping_instructions end |
#shopping_cart ⇒ Object
Returns the value of attribute shopping_cart.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def shopping_cart @shopping_cart end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def state @state end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def status @status end |
#total ⇒ Object
Returns the value of attribute total.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def total @total end |
#transaction_notes ⇒ Object
Returns the value of attribute transaction_notes.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def transaction_notes @transaction_notes end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
3 4 5 |
# File 'lib/channeladvisor/order.rb', line 3 def updated_at @updated_at end |
Class Method Details
.list(criteria = {}) ⇒ Array<Order>
Retrieve a list of orders, restricted by the provided criteria
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/channeladvisor/order.rb', line 118 def list(criteria = {}) handle_errors do if created_between = criteria.delete(:created_between) criteria[:created_from] = created_between.first criteria[:created_to] = created_between.last end if updated_between = criteria.delete(:updated_between) criteria[:updated_from] = updated_between.first criteria[:updated_to] = updated_between.last end response = Services::OrderService.get_order_list(criteria) result = response[:get_order_list_response][:get_order_list_result] check_status_of result orders = [] if data = result[:result_data] arrayify(data[:order_response_item]).each { |o| orders << new(o) } end return orders end end |
.ping ⇒ Boolean
Check authorization for and availability of the order service
78 79 80 81 82 83 84 |
# File 'lib/channeladvisor/order.rb', line 78 def ping handle_errors do response = Services::OrderService.ping result = response[:ping_response][:ping_result] check_status_of result end end |
.set_export_status(client_order_ids, mark_as_exported) ⇒ boolean, Hash
Set the export status for the provided client order identifiers
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/channeladvisor/order.rb', line 153 def set_export_status(client_order_ids, mark_as_exported) handle_errors do client_order_id_list = arrayify client_order_ids response = Services::OrderService.set_orders_export_status(client_order_id_list, mark_as_exported) result = response[:set_orders_export_status_response][:set_orders_export_status_result] check_status_of result bools = arrayify result[:result_data][:boolean] if bools.count == 1 return bools.first else result_hash = {} bools.each do |bool| client_order_ids.each do |client_order_id| result_hash[client_order_id] = bool end end return result_hash end end end |
Instance Method Details
#invoice_ship_cost ⇒ Object
62 63 64 |
# File 'lib/channeladvisor/order.rb', line 62 def invoice_ship_cost shopping_cart.invoices.select { |i| i.type == "Shipping" }.first.unit_price.nonzero? end |
#items_ship_cost ⇒ Object
66 67 68 |
# File 'lib/channeladvisor/order.rb', line 66 def items_ship_cost shopping_cart.items.collect { |i| i.shipping_cost }.inject(:+) end |
#set_export_status(mark_as_exported) ⇒ Boolean
Set the export status for a given order instance
49 50 51 52 53 54 55 56 |
# File 'lib/channeladvisor/order.rb', line 49 def set_export_status(mark_as_exported) handle_errors do response = Services::OrderService.set_orders_export_status([@client_id], mark_as_exported) result = response[:set_orders_export_status_response][:set_orders_export_status_result] check_status_of result return result[:result_data][:boolean] end end |
#total_ship_cost ⇒ Object
set_export_status
58 59 60 |
# File 'lib/channeladvisor/order.rb', line 58 def total_ship_cost invoice_ship_cost || items_ship_cost end |