class AboutYou::SDK::Model::BasketSetItem

BasketSetItem is a class used for adding a variant set item into the basket

Constants

ERROR_CODE_PRODUCT_NOT_INCLUDED

erorr code if a product is not included

Public Instance Methods

create_from_json(json_object, products) click to toggle source

This method is used for creating a basket set item from a given api json response. It is best practice to use this method.

# File lib/AboutYou/Model/Basket/basket_set_item.rb, line 23
def create_from_json(json_object, products)
  item = new(
    json_object['variant_id'],
    if json_object.key?('additional_data')
      [json_object['additional_data']]
    else
      nil
    end,
    json_object.key?('app_id') ? json_object['app_id'] : nil
  )

  item.parse_error_result(json_object)
  item.json_object = json_object

  unless json_object['product_id'].nil?
    if products.key?(json_object['product_id'])
      item.product = products[json_object['product_id']]
    else
      item.errorCode    = ERROR_CODE_PRODUCT_NOT_INCLUDED
      item.errorMessage = 'Product with ID ' +
        json_object['product_id'] + ' expected but wasnt received
        with the basket'
    end
  end

  item
end