Class: NewStoreApi::SalesOrder

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/sales_order.rb

Overview

SalesOrder Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(channel_type = nil, currency = nil, fulfillment_type = nil, id = nil, items = nil, origin = nil, origin_id = nil, placed_at = nil, status = nil, catalog = SKIP) ⇒ SalesOrder

Returns a new instance of SalesOrder.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/new_store_api/models/sales_order.rb', line 85

def initialize(channel_type = nil, currency = nil, fulfillment_type = nil,
               id = nil, items = nil, origin = nil, origin_id = nil,
               placed_at = nil, status = nil, catalog = SKIP)
  @catalog = catalog unless catalog == SKIP
  @channel_type = channel_type
  @currency = currency
  @fulfillment_type = fulfillment_type
  @id = id
  @items = items
  @origin = origin
  @origin_id = origin_id
  @placed_at = placed_at
  @status = status
end

Instance Attribute Details

#catalogString

The catalog identifier (shop) associated with the order.

Returns:

  • (String)


15
16
17
# File 'lib/new_store_api/models/sales_order.rb', line 15

def catalog
  @catalog
end

#channel_typeSalesOrderChannelTypeEnum

The channel through which the order was placed.



19
20
21
# File 'lib/new_store_api/models/sales_order.rb', line 19

def channel_type
  @channel_type
end

#currencyString

Currency code (ISO 4217) used in internal accounting

Returns:

  • (String)


23
24
25
# File 'lib/new_store_api/models/sales_order.rb', line 23

def currency
  @currency
end

#fulfillment_typeSalesOrderFulfillmentTypeEnum

The fulfillment type of the order. In case of mixed cart orders, fulfillment type is always 'multiple'



28
29
30
# File 'lib/new_store_api/models/sales_order.rb', line 28

def fulfillment_type
  @fulfillment_type
end

#idString

External ID of the order

Returns:

  • (String)


32
33
34
# File 'lib/new_store_api/models/sales_order.rb', line 32

def id
  @id
end

#itemsArray[SalesOrderItem]

A list of line items which were ordered

Returns:



36
37
38
# File 'lib/new_store_api/models/sales_order.rb', line 36

def items
  @items
end

#originSalesOrderOriginEnum

Describes in which Order Management System the order originated from.



40
41
42
# File 'lib/new_store_api/models/sales_order.rb', line 40

def origin
  @origin
end

#origin_idString

The identifier of the order from the Order Management System where it originated from. If it originated in Newstore, it must be the identifier assigned to the order during the order creation process.

Returns:

  • (String)


46
47
48
# File 'lib/new_store_api/models/sales_order.rb', line 46

def origin_id
  @origin_id
end

#placed_atDateTime

The time when the order was placed. It should follow https://tools.ietf.org/html/rfc3339 in UTC.

Returns:

  • (DateTime)


51
52
53
# File 'lib/new_store_api/models/sales_order.rb', line 51

def placed_at
  @placed_at
end

#statusSalesOrderStatusEnum

Current status of the sales order



55
56
57
# File 'lib/new_store_api/models/sales_order.rb', line 55

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/new_store_api/models/sales_order.rb', line 101

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  channel_type = hash.key?('channel_type') ? hash['channel_type'] : nil
  currency = hash.key?('currency') ? hash['currency'] : nil
  fulfillment_type =
    hash.key?('fulfillment_type') ? hash['fulfillment_type'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  # Parameter is an array, so we need to iterate through it
  items = nil
  unless hash['items'].nil?
    items = []
    hash['items'].each do |structure|
      items << (SalesOrderItem.from_hash(structure) if structure)
    end
  end

  items = nil unless hash.key?('items')
  origin = hash.key?('origin') ? hash['origin'] : nil
  origin_id = hash.key?('origin_id') ? hash['origin_id'] : nil
  placed_at = if hash.key?('placed_at')
                (DateTimeHelper.from_rfc3339(hash['placed_at']) if hash['placed_at'])
              end
  status = hash.key?('status') ? hash['status'] : nil
  catalog = hash.key?('catalog') ? hash['catalog'] : SKIP

  # Create object from extracted values.
  SalesOrder.new(channel_type,
                 currency,
                 fulfillment_type,
                 id,
                 items,
                 origin,
                 origin_id,
                 placed_at,
                 status,
                 catalog)
end

.namesObject

A mapping from model property names to API property names.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/new_store_api/models/sales_order.rb', line 58

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['catalog'] = 'catalog'
  @_hash['channel_type'] = 'channel_type'
  @_hash['currency'] = 'currency'
  @_hash['fulfillment_type'] = 'fulfillment_type'
  @_hash['id'] = 'id'
  @_hash['items'] = 'items'
  @_hash['origin'] = 'origin'
  @_hash['origin_id'] = 'origin_id'
  @_hash['placed_at'] = 'placed_at'
  @_hash['status'] = 'status'
  @_hash
end

.nullablesObject

An array for nullable fields



81
82
83
# File 'lib/new_store_api/models/sales_order.rb', line 81

def self.nullables
  []
end

.optionalsObject

An array for optional fields



74
75
76
77
78
# File 'lib/new_store_api/models/sales_order.rb', line 74

def self.optionals
  %w[
    catalog
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



155
156
157
158
159
160
161
# File 'lib/new_store_api/models/sales_order.rb', line 155

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} catalog: #{@catalog.inspect}, channel_type: #{@channel_type.inspect},"\
  " currency: #{@currency.inspect}, fulfillment_type: #{@fulfillment_type.inspect}, id:"\
  " #{@id.inspect}, items: #{@items.inspect}, origin: #{@origin.inspect}, origin_id:"\
  " #{@origin_id.inspect}, placed_at: #{@placed_at.inspect}, status: #{@status.inspect}>"
end

#to_custom_placed_atObject



141
142
143
# File 'lib/new_store_api/models/sales_order.rb', line 141

def to_custom_placed_at
  DateTimeHelper.to_rfc3339(placed_at)
end

#to_sObject

Provides a human-readable string representation of the object.



146
147
148
149
150
151
152
# File 'lib/new_store_api/models/sales_order.rb', line 146

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} catalog: #{@catalog}, channel_type: #{@channel_type}, currency:"\
  " #{@currency}, fulfillment_type: #{@fulfillment_type}, id: #{@id}, items: #{@items},"\
  " origin: #{@origin}, origin_id: #{@origin_id}, placed_at: #{@placed_at}, status:"\
  " #{@status}>"
end