Class: NewStoreApi::Cart
- Defined in:
- lib/new_store_api/models/cart.rb
Overview
A shopping cart without promotions applied.
Instance Attribute Summary collapse
-
#cart_id ⇒ String
Cart id.
-
#channel_type ⇒ String
Typically web or store.
-
#coupon_codes ⇒ Array[String]
The coupon codes to be applied.
-
#currency ⇒ String
The currency of the cart.
-
#customer_id ⇒ String
The customer ID.
-
#items ⇒ Array[Item7]
The individual items that the cart contains.
-
#locale ⇒ String
The locale.
-
#selected_shipping_options ⇒ Array[String]
The selected shipping option.
-
#shop_id ⇒ String
The shop ID.
-
#store_id ⇒ String
The store ID.
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(cart_id = nil, coupon_codes = nil, currency = nil, items = nil, selected_shipping_options = nil, channel_type = SKIP, customer_id = SKIP, locale = SKIP, shop_id = SKIP, store_id = SKIP) ⇒ Cart
constructor
A new instance of Cart.
-
#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(cart_id = nil, coupon_codes = nil, currency = nil, items = nil, selected_shipping_options = nil, channel_type = SKIP, customer_id = SKIP, locale = SKIP, shop_id = SKIP, store_id = SKIP) ⇒ Cart
Returns a new instance of Cart.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/new_store_api/models/cart.rb', line 84 def initialize(cart_id = nil, coupon_codes = nil, currency = nil, items = nil, = nil, channel_type = SKIP, customer_id = SKIP, locale = SKIP, shop_id = SKIP, store_id = SKIP) @cart_id = cart_id @channel_type = channel_type unless channel_type == SKIP @coupon_codes = coupon_codes @currency = currency @customer_id = customer_id unless customer_id == SKIP @items = items @locale = locale unless locale == SKIP @selected_shipping_options = @shop_id = shop_id unless shop_id == SKIP @store_id = store_id unless store_id == SKIP end |
Instance Attribute Details
#cart_id ⇒ String
Cart id.
14 15 16 |
# File 'lib/new_store_api/models/cart.rb', line 14 def cart_id @cart_id end |
#channel_type ⇒ String
Typically web or store.
18 19 20 |
# File 'lib/new_store_api/models/cart.rb', line 18 def channel_type @channel_type end |
#coupon_codes ⇒ Array[String]
The coupon codes to be applied.
22 23 24 |
# File 'lib/new_store_api/models/cart.rb', line 22 def coupon_codes @coupon_codes end |
#currency ⇒ String
The currency of the cart.
26 27 28 |
# File 'lib/new_store_api/models/cart.rb', line 26 def currency @currency end |
#customer_id ⇒ String
The customer ID.
30 31 32 |
# File 'lib/new_store_api/models/cart.rb', line 30 def customer_id @customer_id end |
#items ⇒ Array[Item7]
The individual items that the cart contains.
34 35 36 |
# File 'lib/new_store_api/models/cart.rb', line 34 def items @items end |
#locale ⇒ String
The locale.
38 39 40 |
# File 'lib/new_store_api/models/cart.rb', line 38 def locale @locale end |
#selected_shipping_options ⇒ Array[String]
The selected shipping option.
42 43 44 |
# File 'lib/new_store_api/models/cart.rb', line 42 def @selected_shipping_options end |
#shop_id ⇒ String
The shop ID.
46 47 48 |
# File 'lib/new_store_api/models/cart.rb', line 46 def shop_id @shop_id end |
#store_id ⇒ String
The store ID.
50 51 52 |
# File 'lib/new_store_api/models/cart.rb', line 50 def store_id @store_id end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/new_store_api/models/cart.rb', line 101 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. cart_id = hash.key?('cart_id') ? hash['cart_id'] : nil coupon_codes = hash.key?('coupon_codes') ? hash['coupon_codes'] : nil currency = hash.key?('currency') ? hash['currency'] : 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 << (Item7.from_hash(structure) if structure) end end items = nil unless hash.key?('items') = hash.key?('selected_shipping_options') ? hash['selected_shipping_options'] : nil channel_type = hash.key?('channel_type') ? hash['channel_type'] : SKIP customer_id = hash.key?('customer_id') ? hash['customer_id'] : SKIP locale = hash.key?('locale') ? hash['locale'] : SKIP shop_id = hash.key?('shop_id') ? hash['shop_id'] : SKIP store_id = hash.key?('store_id') ? hash['store_id'] : SKIP # Create object from extracted values. Cart.new(cart_id, coupon_codes, currency, items, , channel_type, customer_id, locale, shop_id, store_id) end |
.names ⇒ Object
A mapping from model property names to API property names.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/new_store_api/models/cart.rb', line 53 def self.names @_hash = {} if @_hash.nil? @_hash['cart_id'] = 'cart_id' @_hash['channel_type'] = 'channel_type' @_hash['coupon_codes'] = 'coupon_codes' @_hash['currency'] = 'currency' @_hash['customer_id'] = 'customer_id' @_hash['items'] = 'items' @_hash['locale'] = 'locale' @_hash['selected_shipping_options'] = 'selected_shipping_options' @_hash['shop_id'] = 'shop_id' @_hash['store_id'] = 'store_id' @_hash end |
.nullables ⇒ Object
An array for nullable fields
80 81 82 |
# File 'lib/new_store_api/models/cart.rb', line 80 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
69 70 71 72 73 74 75 76 77 |
# File 'lib/new_store_api/models/cart.rb', line 69 def self.optionals %w[ channel_type customer_id locale shop_id store_id ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
149 150 151 152 153 154 155 156 |
# File 'lib/new_store_api/models/cart.rb', line 149 def inspect class_name = self.class.name.split('::').last "<#{class_name} cart_id: #{@cart_id.inspect}, channel_type: #{@channel_type.inspect},"\ " coupon_codes: #{@coupon_codes.inspect}, currency: #{@currency.inspect}, customer_id:"\ " #{@customer_id.inspect}, items: #{@items.inspect}, locale: #{@locale.inspect},"\ " selected_shipping_options: #{@selected_shipping_options.inspect}, shop_id:"\ " #{@shop_id.inspect}, store_id: #{@store_id.inspect}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
140 141 142 143 144 145 146 |
# File 'lib/new_store_api/models/cart.rb', line 140 def to_s class_name = self.class.name.split('::').last "<#{class_name} cart_id: #{@cart_id}, channel_type: #{@channel_type}, coupon_codes:"\ " #{@coupon_codes}, currency: #{@currency}, customer_id: #{@customer_id}, items: #{@items},"\ " locale: #{@locale}, selected_shipping_options: #{@selected_shipping_options}, shop_id:"\ " #{@shop_id}, store_id: #{@store_id}>" end |