Sha256: 58c78f873744ef95d3a82e4ae7c46340af48b9138564999e08763335d771d4f8

Contents?: true

Size: 765 Bytes

Versions: 6

Compression:

Stored size: 765 Bytes

Contents

#
# This is for use with session-based carts. Token-based carts (V3 widget)
# can't use these methods
#
module CartFinder
  extend ActiveSupport::Concern

  included do |c|
    c.helper_method :current_cart
  end

  def current_cart
    (!session_cart || session_cart.approved?) ? create_new_cart : session_cart
  end

  def session_cart
    @current_cart ||= Cart.find_by_id(session[:cart_id])
  end

  def create_new_cart
    @current_cart = Cart.create
    session[:cart_id] = @current_cart ? @current_cart.id : nil
    @current_cart
  end

  #
  # Use with care. Only assign updated carts (in the case of discounts)
  # TODO: Enforce that this isn't used to actually switch to another cart object
  #
  def current_cart=(cart)
    @current_cart = cart
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.5 app/models/carts/cart_finder.rb
artfully_ose-1.2.0.pre.4 app/models/carts/cart_finder.rb
artfully_ose-1.2.0.pre.3 app/models/carts/cart_finder.rb
artfully_ose-1.2.0.pre.2 app/models/carts/cart_finder.rb
artfully_ose-1.2.0.pre.1 app/models/carts/cart_finder.rb
artfully_ose-1.2.0.pre app/models/carts/cart_finder.rb