Class: NewStoreApi::SalesOrderV2

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

Overview

SalesOrderV2 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 = nil, currency = nil, customer = nil, fulfillment_type = nil, id = nil, items = nil, origin = nil, origin_id = nil, placed_at = nil, status = nil, extended_attributes = SKIP, is_historical = SKIP, is_offline = SKIP, shipping_address = SKIP, shop = SKIP, tax_information = SKIP, totals = SKIP) ⇒ SalesOrderV2

Returns a new instance of SalesOrderV2.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/new_store_api/models/sales_order_v2.rb', line 128

def initialize(channel = nil, currency = nil, customer = nil,
               fulfillment_type = nil, id = nil, items = nil, origin = nil,
               origin_id = nil, placed_at = nil, status = nil,
               extended_attributes = SKIP, is_historical = SKIP,
               is_offline = SKIP, shipping_address = SKIP, shop = SKIP,
               tax_information = SKIP, totals = SKIP)
  @channel = channel
  @currency = currency
  @customer = customer
  @extended_attributes = extended_attributes unless extended_attributes == SKIP
  @fulfillment_type = fulfillment_type
  @id = id
  @is_historical = is_historical unless is_historical == SKIP
  @is_offline = is_offline unless is_offline == SKIP
  @items = items
  @origin = origin
  @origin_id = origin_id
  @placed_at = placed_at
  @shipping_address = shipping_address unless shipping_address == SKIP
  @shop = shop unless shop == SKIP
  @status = status
  @tax_information = tax_information unless tax_information == SKIP
  @totals = totals unless totals == SKIP
end

Instance Attribute Details

#channelChannel

The information about the channel through which the order was placed.

Returns:



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

def channel
  @channel
end

#currencyString

Currency code (ISO 4217) used in internal accounting

Returns:

  • (String)


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

def currency
  @currency
end

#customerSalesOrderCustomer

Currency code (ISO 4217) used in internal accounting

Returns:



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

def customer
  @customer
end

#extended_attributesArray[SalesOrderExtendedAttribute]

Extended attributes of the sales order item.

Returns:



27
28
29
# File 'lib/new_store_api/models/sales_order_v2.rb', line 27

def extended_attributes
  @extended_attributes
end

#fulfillment_typeSalesOrderFulfillmentTypeEnum

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



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

def fulfillment_type
  @fulfillment_type
end

#idString

External ID of the order

Returns:

  • (String)


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

def id
  @id
end

#is_historicalTrueClass | FalseClass

Set to true if order is historical.

Returns:

  • (TrueClass | FalseClass)


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

def is_historical
  @is_historical
end

#is_offlineTrueClass | FalseClass

Set to true if order was created in offline mode.

Returns:

  • (TrueClass | FalseClass)


44
45
46
# File 'lib/new_store_api/models/sales_order_v2.rb', line 44

def is_offline
  @is_offline
end

#itemsArray[SalesOrderItemV2]

Set to true if order was created in offline mode.

Returns:



48
49
50
# File 'lib/new_store_api/models/sales_order_v2.rb', line 48

def items
  @items
end

#originSalesOrderOriginEnum

Describes in which Order Management System the order originated from.



52
53
54
# File 'lib/new_store_api/models/sales_order_v2.rb', line 52

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)


58
59
60
# File 'lib/new_store_api/models/sales_order_v2.rb', line 58

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)


63
64
65
# File 'lib/new_store_api/models/sales_order_v2.rb', line 63

def placed_at
  @placed_at
end

#shipping_addressSalesOrderAddress

Address

Returns:



67
68
69
# File 'lib/new_store_api/models/sales_order_v2.rb', line 67

def shipping_address
  @shipping_address
end

#shopShop

Details about the shop the products belong to.

Returns:



71
72
73
# File 'lib/new_store_api/models/sales_order_v2.rb', line 71

def shop
  @shop
end

#statusSalesOrderStatusEnum

Current status of the sales order



75
76
77
# File 'lib/new_store_api/models/sales_order_v2.rb', line 75

def status
  @status
end

#tax_informationTaxInformation

Metadata about the tax of the order.

Returns:



79
80
81
# File 'lib/new_store_api/models/sales_order_v2.rb', line 79

def tax_information
  @tax_information
end

#totalsSalesOrderTotals

Metadata about the tax of the order.

Returns:



83
84
85
# File 'lib/new_store_api/models/sales_order_v2.rb', line 83

def totals
  @totals
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/new_store_api/models/sales_order_v2.rb', line 154

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  channel = Channel.from_hash(hash['channel']) if hash['channel']
  currency = hash.key?('currency') ? hash['currency'] : nil
  customer = SalesOrderCustomer.from_hash(hash['customer']) if hash['customer']
  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 << (SalesOrderItemV2.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
  # Parameter is an array, so we need to iterate through it
  extended_attributes = nil
  unless hash['extended_attributes'].nil?
    extended_attributes = []
    hash['extended_attributes'].each do |structure|
      extended_attributes << (SalesOrderExtendedAttribute.from_hash(structure) if structure)
    end
  end

  extended_attributes = SKIP unless hash.key?('extended_attributes')
  is_historical = hash.key?('is_historical') ? hash['is_historical'] : SKIP
  is_offline = hash.key?('is_offline') ? hash['is_offline'] : SKIP
  shipping_address = SalesOrderAddress.from_hash(hash['shipping_address']) if
    hash['shipping_address']
  shop = Shop.from_hash(hash['shop']) if hash['shop']
  tax_information = TaxInformation.from_hash(hash['tax_information']) if
    hash['tax_information']
  totals = SalesOrderTotals.from_hash(hash['totals']) if hash['totals']

  # Create object from extracted values.
  SalesOrderV2.new(channel,
                   currency,
                   customer,
                   fulfillment_type,
                   id,
                   items,
                   origin,
                   origin_id,
                   placed_at,
                   status,
                   extended_attributes,
                   is_historical,
                   is_offline,
                   shipping_address,
                   shop,
                   tax_information,
                   totals)
end

.namesObject

A mapping from model property names to API property names.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/new_store_api/models/sales_order_v2.rb', line 86

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['channel'] = 'channel'
  @_hash['currency'] = 'currency'
  @_hash['customer'] = 'customer'
  @_hash['extended_attributes'] = 'extended_attributes'
  @_hash['fulfillment_type'] = 'fulfillment_type'
  @_hash['id'] = 'id'
  @_hash['is_historical'] = 'is_historical'
  @_hash['is_offline'] = 'is_offline'
  @_hash['items'] = 'items'
  @_hash['origin'] = 'origin'
  @_hash['origin_id'] = 'origin_id'
  @_hash['placed_at'] = 'placed_at'
  @_hash['shipping_address'] = 'shipping_address'
  @_hash['shop'] = 'shop'
  @_hash['status'] = 'status'
  @_hash['tax_information'] = 'tax_information'
  @_hash['totals'] = 'totals'
  @_hash
end

.nullablesObject

An array for nullable fields



122
123
124
125
126
# File 'lib/new_store_api/models/sales_order_v2.rb', line 122

def self.nullables
  %w[
    extended_attributes
  ]
end

.optionalsObject

An array for optional fields



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/new_store_api/models/sales_order_v2.rb', line 109

def self.optionals
  %w[
    extended_attributes
    is_historical
    is_offline
    shipping_address
    shop
    tax_information
    totals
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



235
236
237
238
239
240
241
242
243
244
245
# File 'lib/new_store_api/models/sales_order_v2.rb', line 235

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} channel: #{@channel.inspect}, currency: #{@currency.inspect}, customer:"\
  " #{@customer.inspect}, extended_attributes: #{@extended_attributes.inspect},"\
  " fulfillment_type: #{@fulfillment_type.inspect}, id: #{@id.inspect}, is_historical:"\
  " #{@is_historical.inspect}, is_offline: #{@is_offline.inspect}, items: #{@items.inspect},"\
  " origin: #{@origin.inspect}, origin_id: #{@origin_id.inspect}, placed_at:"\
  " #{@placed_at.inspect}, shipping_address: #{@shipping_address.inspect}, shop:"\
  " #{@shop.inspect}, status: #{@status.inspect}, tax_information:"\
  " #{@tax_information.inspect}, totals: #{@totals.inspect}>"
end

#to_custom_placed_atObject



219
220
221
# File 'lib/new_store_api/models/sales_order_v2.rb', line 219

def to_custom_placed_at
  DateTimeHelper.to_rfc3339(placed_at)
end

#to_sObject

Provides a human-readable string representation of the object.



224
225
226
227
228
229
230
231
232
# File 'lib/new_store_api/models/sales_order_v2.rb', line 224

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} channel: #{@channel}, currency: #{@currency}, customer: #{@customer},"\
  " extended_attributes: #{@extended_attributes}, fulfillment_type: #{@fulfillment_type}, id:"\
  " #{@id}, is_historical: #{@is_historical}, is_offline: #{@is_offline}, items: #{@items},"\
  " origin: #{@origin}, origin_id: #{@origin_id}, placed_at: #{@placed_at}, shipping_address:"\
  " #{@shipping_address}, shop: #{@shop}, status: #{@status}, tax_information:"\
  " #{@tax_information}, totals: #{@totals}>"
end