module MongoidCart::ViewHelpers
Public Instance Methods
add_or_remove_cart_link(item)
click to toggle source
shows the add_to_cart or remove_from_cart link, depending if the item is already in cart or not
# File lib/mongoid_cart/view_helpers.rb, line 19 def add_or_remove_cart_link(item) if current_cart.add item remove_from_cart_link item else add_to_cart_link item end end
add_to_cart_link(item)
click to toggle source
link_to mongoid_cart.add_item_path
# File lib/mongoid_cart/view_helpers.rb, line 12 def add_to_cart_link(item) link_to(mongoid_cart.add_item_path(item: {type: item.class.to_s, id: item._id}), {class: "btn btn-default"}) do (tag :i, class: 'fa fa-cart-plus').concat('Add to cart') end end
link_to_product(item, *options)
click to toggle source
# File lib/mongoid_cart/view_helpers.rb, line 27 def link_to_product(item, *options) action = options.include?(:action) ? options[:action] : :show controller = options.include?(:controller) ? options[:controller] : item.type.pluralize.downcase link_to item.title, controller: controller, action: action, id: item.id end
remove_from_cart_link(item)
click to toggle source
link_to mongoid_cart.remove_item_path
# File lib/mongoid_cart/view_helpers.rb, line 5 def remove_from_cart_link(item) link_to(mongoid_cart.remove_item_path(item: {type: item.class.to_s, id: item._id}), {class: "btn btn-default"}) do (tag :i, class: 'fa fa-cart-plus').concat('Remove from cart') end end
sum()
click to toggle source
sums net_price of cart contentç
# File lib/mongoid_cart/view_helpers.rb, line 35 def sum self.current.map { |item| [item.amount, item.net_price] } end