Class Cart
In: app/models/cart.rb
Parent: Object

Class to hande the cart at checkout process. It stores all reservations and force addons

Methods

Attributes

items  [R] 
total_price  [R] 

Public Class methods

Initialize the cart

[Source]

    # File app/models/cart.rb, line 20
20:                 def initialize
21:                                 empty!
22:                 end

Public Instance methods

Add a new line to the card - also the force addons are included. The total amount is calculated from room price and addons

[Source]

    # File app/models/cart.rb, line 26
26:                 def add_line(addons, room, total, arrival, departure, adults, children)
27:                                 #item_check = @items.find {|i| i.room.id == room.id and i.arrival  arrival}
28:                                 #if !item_check
29:                 if !check_doubles(room, arrival, departure)
30:                                 item = CartItem.new(@index, addons, room, total, arrival, departure, adults, children)
31:                                 @items << item
32:                                 @total_price += total.to_f
33:                                 @index = @index + 1
34:                                 return true
35:                                 else
36:                                 return false
37:                                 end
38:                 end

[Source]

    # File app/models/cart.rb, line 55
55:                 def change_total(amount)
56:                 @total_price = @total_price - amount.to_f
57:                 end

[Source]

    # File app/models/cart.rb, line 40
40:                 def check_doubles(room, arrival, departure)
41:                 item_check = @items.find {|i| i.room.id == room.id and \
42:                 ((i.arrival <= arrival and i.departure >= arrival) or \
43:                 (i.arrival <= departure and i.departure >= departure) or \
44:                 (arrival <= i.arrival and departure >= i.departure))}
45:                 end

Empty the cart

[Source]

    # File app/models/cart.rb, line 49
49:                 def empty!
50:                                 @items = []
51:                                 @total_price = 0.00
52:                                 @index = 0
53:                 end

[Validate]