Sha256: 31d2159d53d53dfee856f5fd8583b76de453397c77f8a080ca911627d184dbfd

Contents?: true

Size: 552 Bytes

Versions: 1

Compression:

Stored size: 552 Bytes

Contents

module Redshop
  class CartCountService
    def initialize(cart)
      @cart = cart
      @cart_count_name = parse_cart_count_name

      # if the cart count set doesn't exist (< 1 product in the cart)
      unless $redis.get @cart_count_name
        $redis.set @cart_count_name, 0
      end
    end

    def increment
      $redis.incr @cart_count_name
    end



    private

    def parse_cart_count_name
      # split cart name: cart_MD5 => MD5 (session[:guest_id])
      splitted = @cart.split('_').last
      "count_#{splitted}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redshop-0.0.1 app/services/redshop/cart_count_service.rb