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
43 44 45 |
# File 'lib/carter/cart.rb', line 43 def cart_item_for_cartable_and_owner(cartable, owner) cart_items.for_cartable_and_owner(cartable, owner).first end |
#cartables ⇒ Object
15 16 17 18 19 20 |
# File 'lib/carter/cart.rb', line 15 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
39 40 41 |
# File 'lib/carter/cart.rb', line 39 def in_cart?(cartable, owner=nil) cart_item_for_cartable_and_owner(cartable, owner).present? end |
#on_checkout ⇒ Object
22 23 24 25 26 |
# File 'lib/carter/cart.rb', line 22 def on_checkout if Carter.settings.on_checkout.is_a?(Proc) Carter.settings.on_checkout.call(self) end end |
#on_failed ⇒ Object
33 34 35 36 37 |
# File 'lib/carter/cart.rb', line 33 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.
29 30 31 |
# File 'lib/carter/cart.rb', line 29 def on_success self.cart_items.each{|cart_item| cart_item.add_to_owner } end |
#refresh ⇒ Object
47 48 49 |
# File 'lib/carter/cart.rb', line 47 def refresh cart_items.each{|cart_item| cart_item.refresh } end |