Class: NewStoreApi::SalesOrderDiscount

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

Overview

SalesOrderDiscount 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(level = nil, price_adjustment = nil, type = nil, value = nil, coupon_code = SKIP, promotion_uuid = SKIP, reason = SKIP) ⇒ SalesOrderDiscount

Returns a new instance of SalesOrderDiscount.



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

def initialize(level = nil, price_adjustment = nil, type = nil, value = nil,
               coupon_code = SKIP, promotion_uuid = SKIP, reason = SKIP)
  @coupon_code = coupon_code unless coupon_code == SKIP
  @level = level
  @price_adjustment = price_adjustment
  @promotion_uuid = promotion_uuid unless promotion_uuid == SKIP
  @reason = reason unless reason == SKIP
  @type = type
  @value = value
end

Instance Attribute Details

#coupon_codeString

The coupon code used for this discount.

Returns:

  • (String)


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

def coupon_code
  @coupon_code
end

#levelLevelEnum

On which level the discount was applied, either on the entire order or only on this item.

Returns:



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

def level
  @level
end

#price_adjustmentFloat

The applied discount.

Returns:

  • (Float)


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

def price_adjustment
  @price_adjustment
end

#promotion_uuidString

The UUID of the the discount.

Returns:

  • (String)


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

def promotion_uuid
  @promotion_uuid
end

#reasonString

The reason of the discount.

Returns:

  • (String)


31
32
33
# File 'lib/new_store_api/models/sales_order_discount.rb', line 31

def reason
  @reason
end

#typeType1Enum

The type of the discount, either 'fixed' or 'percentage'.

Returns:



35
36
37
# File 'lib/new_store_api/models/sales_order_discount.rb', line 35

def type
  @type
end

#valueFloat

If the discount is of type 'fixed', this is equal to the adjusted price amount. If the discount is of type 'percentage', this is the percentage, e.g. 20%.

Returns:

  • (Float)


41
42
43
# File 'lib/new_store_api/models/sales_order_discount.rb', line 41

def value
  @value
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/new_store_api/models/sales_order_discount.rb', line 82

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  level = hash.key?('level') ? hash['level'] : nil
  price_adjustment =
    hash.key?('price_adjustment') ? hash['price_adjustment'] : nil
  type = hash.key?('type') ? hash['type'] : nil
  value = hash.key?('value') ? hash['value'] : nil
  coupon_code = hash.key?('coupon_code') ? hash['coupon_code'] : SKIP
  promotion_uuid =
    hash.key?('promotion_uuid') ? hash['promotion_uuid'] : SKIP
  reason = hash.key?('reason') ? hash['reason'] : SKIP

  # Create object from extracted values.
  SalesOrderDiscount.new(level,
                         price_adjustment,
                         type,
                         value,
                         coupon_code,
                         promotion_uuid,
                         reason)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['coupon_code'] = 'coupon_code'
  @_hash['level'] = 'level'
  @_hash['price_adjustment'] = 'price_adjustment'
  @_hash['promotion_uuid'] = 'promotion_uuid'
  @_hash['reason'] = 'reason'
  @_hash['type'] = 'type'
  @_hash['value'] = 'value'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    coupon_code
    promotion_uuid
    reason
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



115
116
117
118
119
120
121
# File 'lib/new_store_api/models/sales_order_discount.rb', line 115

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} coupon_code: #{@coupon_code.inspect}, level: #{@level.inspect},"\
  " price_adjustment: #{@price_adjustment.inspect}, promotion_uuid:"\
  " #{@promotion_uuid.inspect}, reason: #{@reason.inspect}, type: #{@type.inspect}, value:"\
  " #{@value.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



107
108
109
110
111
112
# File 'lib/new_store_api/models/sales_order_discount.rb', line 107

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} coupon_code: #{@coupon_code}, level: #{@level}, price_adjustment:"\
  " #{@price_adjustment}, promotion_uuid: #{@promotion_uuid}, reason: #{@reason}, type:"\
  " #{@type}, value: #{@value}>"
end