Class: NewStoreApi::InjectedOrderShipmentItem

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

Overview

A single product. The quantity of the item is always assumed to be 1 because products are flat, and each variant of a product is considered a separate item. The item is identified by external_item_id in the external system. In the response, an internal NewStore item ID is returned for each external_item_id. An item can be declared as an addon of another item via addon_parent_external_item_id.

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(external_item_id = nil, price = nil, product_id = nil, addon_parent_external_item_id = SKIP, extended_attributes = SKIP, gift_wrapping = SKIP) ⇒ InjectedOrderShipmentItem

Returns a new instance of InjectedOrderShipmentItem.



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 78

def initialize(external_item_id = nil, price = nil, product_id = nil,
               addon_parent_external_item_id = SKIP,
               extended_attributes = SKIP, gift_wrapping = SKIP)
  unless addon_parent_external_item_id == SKIP
    @addon_parent_external_item_id =
      addon_parent_external_item_id
  end
  @extended_attributes = extended_attributes unless extended_attributes == SKIP
  @external_item_id = external_item_id
  @gift_wrapping = gift_wrapping unless gift_wrapping == SKIP
  @price = price
  @product_id = product_id
end

Instance Attribute Details

#addon_parent_external_item_idString

The external_item_id of the item that this item is an addon of. The parent must belong to the same shipment as this addon. When set, this item becomes an addon line item linked to that parent.

Returns:

  • (String)


21
22
23
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 21

def addon_parent_external_item_id
  @addon_parent_external_item_id
end

#extended_attributesArray[InjectedOrderExtendedAttribute]

The external_item_id of the item that this item is an addon of. The parent must belong to the same shipment as this addon. When set, this item becomes an addon line item linked to that parent.

Returns:



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

def extended_attributes
  @extended_attributes
end

#external_item_idString

The external_item_id of the item that this item is an addon of. The parent must belong to the same shipment as this addon. When set, this item becomes an addon line item linked to that parent.

Returns:

  • (String)


33
34
35
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 33

def external_item_id
  @external_item_id
end

#gift_wrappingGiftWrapping1

Indicates if gift wrapping option was selected for the order. Only information from the first item (message and price) will be taken into account.

Returns:



39
40
41
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 39

def gift_wrapping
  @gift_wrapping
end

#priceInjectedOrderShipmentItemPrice

Indicates if gift wrapping option was selected for the order. Only information from the first item (message and price) will be taken into account.



45
46
47
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 45

def price
  @price
end

#product_idString

The identifier of the product as it was fetched from the catalog.

Returns:

  • (String)


49
50
51
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 49

def product_id
  @product_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 93

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  external_item_id =
    hash.key?('external_item_id') ? hash['external_item_id'] : nil
  price = InjectedOrderShipmentItemPrice.from_hash(hash['price']) if hash['price']
  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  addon_parent_external_item_id =
    hash.key?('addon_parent_external_item_id') ? hash['addon_parent_external_item_id'] : SKIP
  # 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 << (InjectedOrderExtendedAttribute.from_hash(structure) if structure)
    end
  end

  extended_attributes = SKIP unless hash.key?('extended_attributes')
  gift_wrapping = GiftWrapping1.from_hash(hash['gift_wrapping']) if hash['gift_wrapping']

  # Create object from extracted values.
  InjectedOrderShipmentItem.new(external_item_id,
                                price,
                                product_id,
                                addon_parent_external_item_id,
                                extended_attributes,
                                gift_wrapping)
end

.namesObject

A mapping from model property names to API property names.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 52

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['addon_parent_external_item_id'] =
    'addon_parent_external_item_id'
  @_hash['extended_attributes'] = 'extended_attributes'
  @_hash['external_item_id'] = 'external_item_id'
  @_hash['gift_wrapping'] = 'gift_wrapping'
  @_hash['price'] = 'price'
  @_hash['product_id'] = 'product_id'
  @_hash
end

.nullablesObject

An array for nullable fields



74
75
76
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 74

def self.nullables
  []
end

.optionalsObject

An array for optional fields



65
66
67
68
69
70
71
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 65

def self.optionals
  %w[
    addon_parent_external_item_id
    extended_attributes
    gift_wrapping
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.external_item_id,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.price,
                              ->(val) { InjectedOrderShipmentItemPrice.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.product_id,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['external_item_id'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['price'],
                            ->(val) { InjectedOrderShipmentItemPrice.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['product_id'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



161
162
163
164
165
166
167
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 161

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} addon_parent_external_item_id: #{@addon_parent_external_item_id.inspect},"\
  " extended_attributes: #{@extended_attributes.inspect}, external_item_id:"\
  " #{@external_item_id.inspect}, gift_wrapping: #{@gift_wrapping.inspect}, price:"\
  " #{@price.inspect}, product_id: #{@product_id.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



153
154
155
156
157
158
# File 'lib/new_store_api/models/injected_order_shipment_item.rb', line 153

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} addon_parent_external_item_id: #{@addon_parent_external_item_id},"\
  " extended_attributes: #{@extended_attributes}, external_item_id: #{@external_item_id},"\
  " gift_wrapping: #{@gift_wrapping}, price: #{@price}, product_id: #{@product_id}>"
end