op_cart 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/op_cart/orders_controller.rb +24 -19
- data/app/models/op_cart/order.rb +1 -1
- data/lib/op_cart/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2e3218ad0131f81758ccc3f33a8cc3800bb8c68
|
4
|
+
data.tar.gz: 83a9efdfe925a67a27221b7f2f006191c54ef928
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d77f1f76b0edf91a31c891498ffe2434e151967e3105c37153d3bd37794ceff3904b76a97a096112996143eb7890fbf1a5aceaeaf5cd268d2c7f655f57ed6a49
|
7
|
+
data.tar.gz: db45bf60426be0d7669cbd356ed671e19b06678186dd7036c86d7780c67891721f837f38399b723f80be1fe456fc2f79ac3eeee8289a9b41c82cd29bce3aecb6
|
@@ -3,22 +3,31 @@ module OpCart
|
|
3
3
|
before_action :authenticate_user!, only: [:show, :edit, :update, :destroy]
|
4
4
|
before_action :set_order, only: [:show, :edit, :update, :destroy]
|
5
5
|
if defined? decorates_assigned
|
6
|
-
decorates_assigned :order, :orders, :
|
6
|
+
decorates_assigned :order, :orders, :plan, :card
|
7
7
|
end
|
8
8
|
|
9
9
|
def new
|
10
|
-
|
10
|
+
if params[:plan_id]
|
11
|
+
@plan = Plan.purchasable.find(params[:plan_id])
|
12
|
+
else
|
13
|
+
return redirect_to plans_path
|
14
|
+
end
|
15
|
+
|
11
16
|
@order = Order.new
|
17
|
+
@order.user = current_user || User.new
|
12
18
|
@order.line_items << LineItem.new
|
13
|
-
@
|
14
|
-
@user = current_user || User.new
|
19
|
+
@order.shipping_address = @order.user.shipping_addresses.first || @order.user.shipping_addresses.new
|
15
20
|
@card = current_user.try(:customer).try :default_card
|
16
|
-
@shipping_address = @user.shipping_addresses.first || @user.shipping_addresses.new
|
17
21
|
end
|
18
22
|
|
19
23
|
def create
|
24
|
+
if params[:plan_id]
|
25
|
+
@plan = Plan.purchasable.find(params[:plan_id])
|
26
|
+
else
|
27
|
+
return redirect_to plans_path
|
28
|
+
end
|
29
|
+
|
20
30
|
@order = Order.new order_params
|
21
|
-
@user = current_user || @order.user
|
22
31
|
add_user
|
23
32
|
add_line_items
|
24
33
|
add_shipping_address
|
@@ -27,9 +36,7 @@ module OpCart
|
|
27
36
|
sign_in @order.user
|
28
37
|
redirect_to @order, notice: 'Thank you for your purchase'
|
29
38
|
else
|
30
|
-
@
|
31
|
-
@user = User.new user_params unless signed_in?
|
32
|
-
@card = current_user.try(:customer).try :default_card
|
39
|
+
@order.user ||= User.new email: user_params[:email]
|
33
40
|
render :new
|
34
41
|
end
|
35
42
|
end
|
@@ -46,18 +53,17 @@ module OpCart
|
|
46
53
|
params.require(:order).permit :email, :password, :processor_token
|
47
54
|
end
|
48
55
|
|
49
|
-
|
50
56
|
def line_items_params
|
51
57
|
params.require(:line_items).permit :quantities_json
|
52
58
|
end
|
53
59
|
|
54
60
|
def shipping_address_params
|
55
|
-
params.require(:shipping_address).permit :full_name, :street, :postal_code,
|
61
|
+
params[:order].require(:shipping_address).permit :full_name, :street, :postal_code,
|
56
62
|
:locality, :region
|
57
63
|
end
|
58
64
|
|
59
65
|
def user_params
|
60
|
-
params.require(:user).permit :email, :password
|
66
|
+
params[:order].require(:user).permit :email, :password
|
61
67
|
end
|
62
68
|
|
63
69
|
def add_line_items
|
@@ -78,12 +84,12 @@ module OpCart
|
|
78
84
|
if !signed_in? && !@order.user
|
79
85
|
if user = find_user
|
80
86
|
if valid_password? user
|
81
|
-
@order.user =
|
87
|
+
@order.user = user
|
82
88
|
else
|
83
89
|
flash.now[:alert] = 'A user with that email already exists. Please sign in or pick another email.'
|
84
90
|
end
|
85
91
|
else
|
86
|
-
@order.user =
|
92
|
+
@order.user = new_user
|
87
93
|
end
|
88
94
|
else
|
89
95
|
@order.user = current_user
|
@@ -91,11 +97,11 @@ module OpCart
|
|
91
97
|
end
|
92
98
|
|
93
99
|
def find_user
|
94
|
-
User.find_by email: params[:user][:email]
|
100
|
+
User.find_by email: params[:order][:user][:email]
|
95
101
|
end
|
96
102
|
|
97
103
|
def valid_password? user
|
98
|
-
user.valid_password? params[:user][:password]
|
104
|
+
user.valid_password? params[:order][:user][:password]
|
99
105
|
end
|
100
106
|
|
101
107
|
def new_user
|
@@ -103,12 +109,11 @@ module OpCart
|
|
103
109
|
name: shipping_address_params[:full_name],
|
104
110
|
password_confirmation: user_params[:password]
|
105
111
|
))
|
106
|
-
user.valid? && user
|
107
112
|
end
|
108
113
|
|
109
114
|
def add_shipping_address
|
110
|
-
@order.shipping_address =
|
111
|
-
shipping_address_params.merge user: @user
|
115
|
+
@order.shipping_address = ShippingAddress.new(
|
116
|
+
shipping_address_params.merge user: @order.user
|
112
117
|
)
|
113
118
|
end
|
114
119
|
end
|
data/app/models/op_cart/order.rb
CHANGED
@@ -14,7 +14,7 @@ module OpCart
|
|
14
14
|
validates :status, presence: true
|
15
15
|
validates :line_items, presence: true
|
16
16
|
validates :shipping_address, associated: true
|
17
|
-
validates :user,
|
17
|
+
validates :user, associated: true
|
18
18
|
validate :validate_plan_addons_included
|
19
19
|
|
20
20
|
before_validation :set_total
|
data/lib/op_cart/version.rb
CHANGED