Class: ChannelAdvisor::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/channeladvisor/order.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_addressObject

Returns the value of attribute billing_address.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def billing_address
  @billing_address
end

#buyer_emailObject

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_addressObject

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_onObject

Returns the value of attribute cancelled_on.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def cancelled_on
  @cancelled_on
end

#client_idObject

Returns the value of attribute client_id.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def client_id
  @client_id
end

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def created_at
  @created_at
end

#custom_valuesObject

Returns the value of attribute custom_values.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def custom_values
  @custom_values
end

#delivery_dateObject

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_inObject

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_dateObject

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_descriptionObject

Returns the value of attribute flag_description.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def flag_description
  @flag_description
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def id
  @id
end

#paymentObject

Returns the value of attribute payment.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def payment
  @payment
end

#reseller_idObject

Returns the value of attribute reseller_id.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def reseller_id
  @reseller_id
end

#seller_idObject

Returns the value of attribute seller_id.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def seller_id
  @seller_id
end

#shipmentsObject

Returns the value of attribute shipments.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def shipments
  @shipments
end

#shipping_addressObject

Returns the value of attribute shipping_address.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def shipping_address
  @shipping_address
end

#shipping_instructionsObject

Returns the value of attribute shipping_instructions.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def shipping_instructions
  @shipping_instructions
end

#shopping_cartObject

Returns the value of attribute shopping_cart.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def shopping_cart
  @shopping_cart
end

#stateObject

Returns the value of attribute state.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def state
  @state
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def status
  @status
end

#totalObject

Returns the value of attribute total.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def total
  @total
end

#transaction_notesObject

Returns the value of attribute transaction_notes.



3
4
5
# File 'lib/channeladvisor/order.rb', line 3

def transaction_notes
  @transaction_notes
end

#updated_atObject

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

Examples:

List orders created between 11/11/2011 and 11/15/2011

ChannelAdvisor::Order.list(:created_between => DateTime.new(2011,11,11)..DateTime.new(2011,11,15))

Parameters:

  • criteria (Hash) (defaults to: {})

    Criteria used to filter the order list

Options Hash (criteria):

  • :created_between (Range<DateTime>)

    Range of order creation date-times in UTC (instead of created_from and created_to)

  • :updated_between (Range<DateTime>)

    Range of order update date-times in UTC (instead of updated_from and updated_to)

  • :created_from (DateTime)

    Order creation begin time in UTC

  • :created_to (DateTime)

    Order creation end time in UTC

  • :updated_from (DateTime)

    Order update begin time in UTC

  • :updated_to (DateTime)

    Order update end time in UTC

  • :join_dates (Boolean)

    true indicates that orders can satisfy either the created date range or the updated date range

  • :detail_level (String)

    Low, Medium, High or Complete

  • :export_state (String)

    Unknown, NotExported or Exported

  • :order_ids (Array<Integer>)

    Array of order IDs

  • :client_order_ids (Array<String>)

    Array of client order IDs

  • :state (String)

    Active, Archived, or Cancelled

  • :payment_status (String)

    NoChange, NotSubmitted, Cleared, Submitted, Failed, or Deposited

  • :checkout_status (String)

    NoChange, NotVisited, Completed, Visited, Cancelled, CompletedOffline, or OnHold

  • :shipping_status (String)

    NoChange, Unshipped, PendingShipment, PartiallyShipped, or Shipped

  • :refund_status (String)

    NoRefunds, OrderLevel, LineItemLevel, OrderAndLineItemLevel, or FailedAttemptsOnly

  • :distribution_center (String)

    Only orders containing at least one item from the specified distribution center

  • :page_number (Integer)

    Page number of result set

  • :page_size (Integer)

    Size of each page in result set

Returns:

Raises:

  • (ServiceFailure)

    If the service returns a Failure status

  • (SOAPFault)

    If the service responds with a SOAP fault

  • (HTTPError)

    If the service responds with an HTTP error



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

.pingBoolean

Check authorization for and availability of the order service

Returns:

  • (Boolean)

    Returns true if SOAP response status is Success

Raises:

  • (ServiceFailure)

    If the service returns a Failure status

  • (SOAPFault)

    If the service responds with a SOAP fault

  • (HTTPError)

    If the service responds with an HTTP error



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

Parameters:

  • client_order_ids (String, Array<String>)

    An client order ID or array of client order IDs

  • mark_as_exported (boolean)

    true (Exported) or false (NotExported)

Returns:

  • (boolean, Hash)

    Returns a boolean result or hash of client order IDs and their corresponding boolean results

Raises:

  • (ServiceFailure)

    If the service returns a Failure status

  • (SOAPFault)

    If the service responds with a SOAP fault

  • (HTTPError)

    If the service responds with an HTTP error



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_costObject



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_costObject



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

Parameters:

  • mark_as_exported (Boolean)

    true (Exported) or false (NotExported)

Returns:

  • (Boolean)

    Returns the boolean result for changing the export status

Raises:

  • (ServiceFailure)

    If the service returns a Failure status

  • (SOAPFault)

    If the service responds with a SOAP fault

  • (HTTPError)

    If the service responds with an HTTP error



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_costObject

set_export_status



58
59
60
# File 'lib/channeladvisor/order.rb', line 58

def total_ship_cost
  invoice_ship_cost || items_ship_cost
end