Class: NewStoreApi::SalesOrderDiscount
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- NewStoreApi::SalesOrderDiscount
- Defined in:
- lib/new_store_api/models/sales_order_discount.rb
Overview
SalesOrderDiscount Model.
Instance Attribute Summary collapse
-
#coupon_code ⇒ String
The coupon code used for this discount.
-
#level ⇒ LevelEnum
On which level the discount was applied, either on the entire order or only on this item.
-
#price_adjustment ⇒ Float
The applied discount.
-
#promotion_uuid ⇒ String
The UUID of the the discount.
-
#reason ⇒ String
The reason of the discount.
-
#type ⇒ Type1Enum
The type of the discount, either 'fixed' or 'percentage'.
-
#value ⇒ Float
If the discount is of type 'fixed', this is equal to the adjusted price amount.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(level = nil, price_adjustment = nil, type = nil, value = nil, coupon_code = SKIP, promotion_uuid = SKIP, reason = SKIP) ⇒ SalesOrderDiscount
constructor
A new instance of SalesOrderDiscount.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
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_code ⇒ String
The coupon code used for this discount.
14 15 16 |
# File 'lib/new_store_api/models/sales_order_discount.rb', line 14 def coupon_code @coupon_code end |
#level ⇒ LevelEnum
On which level the discount was applied, either on the entire order or only on this item.
19 20 21 |
# File 'lib/new_store_api/models/sales_order_discount.rb', line 19 def level @level end |
#price_adjustment ⇒ Float
The applied discount.
23 24 25 |
# File 'lib/new_store_api/models/sales_order_discount.rb', line 23 def price_adjustment @price_adjustment end |
#promotion_uuid ⇒ String
The UUID of the the discount.
27 28 29 |
# File 'lib/new_store_api/models/sales_order_discount.rb', line 27 def promotion_uuid @promotion_uuid end |
#reason ⇒ String
The reason of the discount.
31 32 33 |
# File 'lib/new_store_api/models/sales_order_discount.rb', line 31 def reason @reason end |
#type ⇒ Type1Enum
The type of the discount, either 'fixed' or 'percentage'.
35 36 37 |
# File 'lib/new_store_api/models/sales_order_discount.rb', line 35 def type @type end |
#value ⇒ Float
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%.
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 |
.names ⇒ Object
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 |
.nullables ⇒ Object
An array for nullable fields
66 67 68 |
# File 'lib/new_store_api/models/sales_order_discount.rb', line 66 def self.nullables [] end |
.optionals ⇒ Object
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
#inspect ⇒ Object
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_s ⇒ Object
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 |