Class: NewStoreApi::InjectedOrderShipmentItemPrice

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

Overview

InjectedOrderShipmentItemPrice 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(item_list_price = nil, item_price = nil, item_tax_lines = nil, group_ref = SKIP, item_discount_info = SKIP, item_order_discount_info = SKIP, pricebook = 'default') ⇒ InjectedOrderShipmentItemPrice

Returns a new instance of InjectedOrderShipmentItemPrice.



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 70

def initialize(item_list_price = nil, item_price = nil,
               item_tax_lines = nil, group_ref = SKIP,
               item_discount_info = SKIP, item_order_discount_info = SKIP,
               pricebook = 'default')
  @group_ref = group_ref unless group_ref == SKIP
  @item_discount_info = item_discount_info unless item_discount_info == SKIP
  @item_list_price = item_list_price
  @item_order_discount_info = item_order_discount_info unless item_order_discount_info == SKIP
  @item_price = item_price
  @item_tax_lines = item_tax_lines
  @pricebook = pricebook unless pricebook == SKIP
end

Instance Attribute Details

#group_refString

A reference to a group (bundle) if group pricing was used for the item.

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 14

def group_ref
  @group_ref
end

#item_discount_infoArray[Object]

Information about item-level discounts applied to the items.

Returns:

  • (Array[Object])


18
19
20
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 18

def item_discount_info
  @item_discount_info
end

#item_list_priceFloat

Price from the default pricebook.

Returns:

  • (Float)


22
23
24
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 22

def item_list_price
  @item_list_price
end

#item_order_discount_infoArray[Object]

Information about order-level discounts applied to the item. An order level discount is prorated for all the items across all shipments.

Returns:

  • (Array[Object])


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

def item_order_discount_info
  @item_order_discount_info
end

#item_priceFloat

Price of the item, including taxes or not, depending on the value of the price_method property. Can be affected by pricebooks and bundle pricing.

Returns:

  • (Float)


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

def item_price
  @item_price
end

#item_tax_linesArray[InjectedOrderItemTaxLine]

Describes the taxes applied to the item.

Returns:



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

def item_tax_lines
  @item_tax_lines
end

#pricebookString

A reference to the pricebook used to calculate the catalog price.

Returns:

  • (String)


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

def pricebook
  @pricebook
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



84
85
86
87
88
89
90
91
92
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
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 84

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  item_list_price =
    hash.key?('item_list_price') ? hash['item_list_price'] : nil
  item_price = hash.key?('item_price') ? hash['item_price'] : nil
  # Parameter is an array, so we need to iterate through it
  item_tax_lines = nil
  unless hash['item_tax_lines'].nil?
    item_tax_lines = []
    hash['item_tax_lines'].each do |structure|
      item_tax_lines << (InjectedOrderItemTaxLine.from_hash(structure) if structure)
    end
  end

  item_tax_lines = nil unless hash.key?('item_tax_lines')
  group_ref = hash.key?('group_ref') ? hash['group_ref'] : SKIP
  item_discount_info = hash.key?('item_discount_info') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InjectedOrderDiscountInfo2), hash['item_discount_info']
  ) : SKIP
  item_order_discount_info = hash.key?('item_order_discount_info') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InjectedOrderDiscountInfo2), hash['item_order_discount_info']
  ) : SKIP
  pricebook = hash['pricebook'] ||= 'default'

  # Create object from extracted values.
  InjectedOrderShipmentItemPrice.new(item_list_price,
                                     item_price,
                                     item_tax_lines,
                                     group_ref,
                                     item_discount_info,
                                     item_order_discount_info,
                                     pricebook)
end

.namesObject

A mapping from model property names to API property names.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 43

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['group_ref'] = 'group_ref'
  @_hash['item_discount_info'] = 'item_discount_info'
  @_hash['item_list_price'] = 'item_list_price'
  @_hash['item_order_discount_info'] = 'item_order_discount_info'
  @_hash['item_price'] = 'item_price'
  @_hash['item_tax_lines'] = 'item_tax_lines'
  @_hash['pricebook'] = 'pricebook'
  @_hash
end

.nullablesObject

An array for nullable fields



66
67
68
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 66

def self.nullables
  []
end

.optionalsObject

An array for optional fields



56
57
58
59
60
61
62
63
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 56

def self.optionals
  %w[
    group_ref
    item_discount_info
    item_order_discount_info
    pricebook
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.item_list_price,
                            ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.item_price,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.item_tax_lines,
                              ->(val) { InjectedOrderItemTaxLine.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['item_list_price'],
                          ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['item_price'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['item_tax_lines'],
                            ->(val) { InjectedOrderItemTaxLine.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} group_ref: #{@group_ref.inspect}, item_discount_info:"\
  " #{@item_discount_info.inspect}, item_list_price: #{@item_list_price.inspect},"\
  " item_order_discount_info: #{@item_order_discount_info.inspect}, item_price:"\
  " #{@item_price.inspect}, item_tax_lines: #{@item_tax_lines.inspect}, pricebook:"\
  " #{@pricebook.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



151
152
153
154
155
156
157
# File 'lib/new_store_api/models/injected_order_shipment_item_price.rb', line 151

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} group_ref: #{@group_ref}, item_discount_info: #{@item_discount_info},"\
  " item_list_price: #{@item_list_price}, item_order_discount_info:"\
  " #{@item_order_discount_info}, item_price: #{@item_price}, item_tax_lines:"\
  " #{@item_tax_lines}, pricebook: #{@pricebook}>"
end