Module: Carter::Cart::InstanceMethods
- Defined in:
- lib/carter/cart.rb
Instance Method Summary collapse
- #cart_item_for_cartable_and_owner(cartable, owner) ⇒ Object
- #cartables ⇒ Object
- #in_cart?(cartable, owner = nil) ⇒ Boolean
- #on_checkout ⇒ Object
- #on_failed ⇒ Object
-
#on_success ⇒ Object
On success from checkout call the add event on each cart item.
- #refresh ⇒ Object
Instance Method Details
#cart_item_for_cartable_and_owner(cartable, owner) ⇒ Object
39 40 41 |
# File 'lib/carter/cart.rb', line 39 def cart_item_for_cartable_and_owner(cartable, owner) cart_items.for_cartable_and_owner(cartable, owner).first end |
#cartables ⇒ Object
11 12 13 14 15 16 |
# File 'lib/carter/cart.rb', line 11 def cartables Carter.settings.cartables.inject([]) do |result, cartable_type| result.concat self.send(cartable_type.downcase.pluralize) result end end |
#in_cart?(cartable, owner = nil) ⇒ Boolean
35 36 37 |
# File 'lib/carter/cart.rb', line 35 def in_cart?(cartable, owner=nil) cart_item_for_cartable_and_owner(cartable, owner).nil? end |
#on_checkout ⇒ Object
18 19 20 21 22 |
# File 'lib/carter/cart.rb', line 18 def on_checkout if Carter.settings.on_checkout.is_a?(Proc) Carter.settings.on_checkout.call(self) end end |
#on_failed ⇒ Object
29 30 31 32 33 |
# File 'lib/carter/cart.rb', line 29 def on_failed if Carter.settings.on_failed.is_a?(Proc) Carter.settings.on_failed.call(self) end end |
#on_success ⇒ Object
On success from checkout call the add event on each cart item.
25 26 27 |
# File 'lib/carter/cart.rb', line 25 def on_success self.cart_items.each{|cart_item| cart_item.add_to_owner } end |
#refresh ⇒ Object
43 44 45 |
# File 'lib/carter/cart.rb', line 43 def refresh cart_items.each{|cart_item| cart_item.refresh } end |