Class: Redshop::AddToCart

Inherits:
Object
  • Object
show all
Defined in:
app/services/redshop/add_to_cart.rb

Instance Method Summary collapse

Constructor Details

#initialize(cart, product) ⇒ AddToCart

Returns a new instance of AddToCart.



3
4
5
6
# File 'app/services/redshop/add_to_cart.rb', line 3

def initialize(cart, product)
  @cart = cart
  @product = product
end

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/redshop/add_to_cart.rb', line 8

def call
  if product_added?
    # increment quantity of this product in the cart
    $redis.hincrby(@cart, @product, 1)
  else
    # create cart(hash) and put the one product
    $redis.hset(@cart, @product, 1)
  end

  increment_cart_count
end