# methods for cart
module CartHelper
  def cookie_cart_number
    if cookies.encrypted[:cart_no].blank?
      # set cookie cart number
      cookies.encrypted[:cart_no] = { value: generate_cart_number,
                                      expires: 1.week.from_now }
    end
    cookies.encrypted[:cart_no]
  end

  private

  def delete_cookies_for_cart
    cookies.delete :cart_no
  end

  def generate_cart_number
    require 'securerandom'
    SecureRandom.uuid
  end
end
