-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_code.rb
77 lines (48 loc) · 1.41 KB
/
test_code.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module CurrentCart
private
def set_cart
if user_signed_in? && shopping_cart.line_items != nil
flash[:notice] = "User already has a cart with line items"
@cart = Cart.find_by(user_id: current_user.id)
else
if user_signed_in? && shopping_cart.line_items == nil
flash[:notice] = "User had empty cart, now has cart with line items from session"
@cart = Cart.find(session[:cart_id])
@cart.user_id = current_user.id
@cart.save
old_cart.destroy
else
if user_signed_in? && shopping_cart.none?
flash[:notice] = "Already existing session cart assigned to new user"
@cart = Cart.find(session[:cart_id])
@cart.user_id = current_user.id
@cart.save
else
if user_signed_in? && session[:cart_id] == nil
flash[:notice] = "RESCUE"
@cart = Cart.create
session[:cart_id] = @cart.id
@cart.user_id = current_user.id
@cart.save
else
if session[:cart_id] == nil
flash[:notice] = "New session cart created"
@cart = Cart.create
session[:cart_id] = @cart.id
else
flash[:notice] = "Already existing session cart found"
@cart = Cart.find(session[:cart_id])
end
end
end
end
end
end
def shopping_cart
@cart = Cart.find_by(user_id: current_user.id) || @cart = Cart.find(session[:cart_id])
end
def old_cart
oldCart = Cart.find_by(user_id: current_user.id)
oldCart.id_asc.first
end
end