Module: AboutYou::SDK::Model::BasketVariantItem

Included in:
BasketItem, BasketSetItem
Defined in:
lib/AboutYou/Model/Basket/basket_variant_item.rb

Overview

BasketVairantItem is a class representing a basket variant item

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_idObject

the app id of this variant item



17
18
19
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 17

def app_id
  @app_id
end

#json_objectObject

the json object from which this instance was created from



9
10
11
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 9

def json_object
  @json_object
end

#productObject

the product of this variant item



11
12
13
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 11

def product
  @product
end

#variantObject

Getter for the variant

  • Returns :

    • an instance of AboutYou::SDK::Model::Variant



13
14
15
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 13

def variant
  @variant
end

#variant_idObject

the variant id of this variant item



15
16
17
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 15

def variant_id
  @variant_id
end

Instance Method Details

#check_app_id(app_id) ⇒ Object

This method checks if an app id is valid

  • Fails :

    • if app_id is not an integer



150
151
152
153
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 150

def check_app_id(app_id)
  fail '\InvalidArgumentException! the app id must be
    an integer' unless app_id.is_a?(Integer)
end

#check_variant_id(variant_id) ⇒ Object

This method checks if a variant id is valid

  • Fails :

    • if variant_id is not an integer



139
140
141
142
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 139

def check_variant_id(variant_id)
  fail '\InvalidArgumentException! the variant id must be
    an integer' unless variant_id.is_a?(Integer)
end

#errors?Boolean

This method checks if there are errors in the variant item

  • Returns :

    • Boolean determining whether there are errors or not

Returns:

  • (Boolean)


50
51
52
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 50

def errors?
  error_code > 0
end

#initialize(variant_id, additional_data = nil, app_id = nil) ⇒ Object

Constructor for the AboutYou::SDK::Model::BasketVariantItem class

  • Args :

    • variant_id -> the id of the variant item

    • additional_data -> additional data of the variant item

    • app_id -> the app id for the variant item

  • Returns :

    • an instance of AboutYou::SDK::Model::BasketVariantItem



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 30

def initialize(variant_id, additional_data = nil, app_id = nil)
  check_variant_id(variant_id)
  check_addition_data(additional_data)
  self.variant_od = variant_id
  self.additional_data = additional_data

  return self unless app_id

  check_app_id(app_id)
  self.app_id = app_id

  self
end

#old_priceObject

Getter for the old price of the variant

  • Returns :

    • an Integer containing the old price of the variant



100
101
102
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 100

def old_price
  variant.old_price
end

#taxObject

Getter for the tax

  • Returns :

    • an Integer containing the tax



70
71
72
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 70

def tax
  json_object['tax']
end

#total_netObject

Getter for the total net

  • Returns :

    • an Integer containing the total net



90
91
92
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 90

def total_net
  json_object['total_net']
end

#total_priceObject

Getter for the total price

  • Returns :

    • an Integer containing the total price



60
61
62
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 60

def total_price
  json_object['total_price']
end

#total_vatObject

Getter for the total vat

  • Returns :

    • an Integer containing the total vat



80
81
82
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 80

def total_vat
  json_object['total_vat']
end

#unique_keyObject

This method is used for creating a unique key for the basket set

  • Returns :

    • a String containing a unique key for the basket set



123
124
125
126
127
128
129
130
131
# File 'lib/AboutYou/Model/Basket/basket_variant_item.rb', line 123

def unique_key
  key = variant_id
  if additionalData
    additionalData.sort!
    key += ':' + additionalData.to_json
  end

  key
end