Class: Workarea::WishListSession

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/wish_list_session.rb

Overview

WishListSession is responsible for storing a representation of a product that will later be added to a user’s Wish List.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookies) ⇒ WishListSession

Returns a new instance of WishListSession.

Parameters:

  • user's (Hash)

    cookies



8
9
10
# File 'app/services/workarea/wish_list_session.rb', line 8

def initialize(cookies)
  @cookies = cookies
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



5
6
7
# File 'app/services/workarea/wish_list_session.rb', line 5

def cookies
  @cookies
end

Instance Method Details

#add_item(wish_list) ⇒ void

This method returns an undefined value.

Add the current item in the cookies to a the given wish list.

Parameters:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/workarea/wish_list_session.rb', line 28

def add_item(wish_list)
  product_id = cookies['wish_list_product_id']
  sku = cookies['wish_list_sku']
  quantity = cookies['wish_list_quantity']
  customizations = cookies['wish_list_customizations']

  wish_list.add_item(
    product_id,
    sku,
    quantity.to_i,
    OrderItemDetails.find!(sku).to_h,
    customizations || {}
  )

  collection_keys.each do |key|
    cookies.delete("wish_list_#{key}")
  end
end

#store_item(params) ⇒ void

This method returns an undefined value.

Store a form-posted representation of a Wish List Item. This would include the product_id, sku and quantity of that item.

Parameters:

  • controller's (Hash)

    params



17
18
19
20
21
# File 'app/services/workarea/wish_list_session.rb', line 17

def store_item(params)
  collection_keys.each do |key|
    cookies["wish_list_#{key}"] = params[key] if params[key].present?
  end
end