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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad47e8c3658d30668cbfaf4e1ad60ca64cf5806c
4
- data.tar.gz: d97883ff84bdc92bf310c5fb40370a07ab995e90
3
+ metadata.gz: b2e3218ad0131f81758ccc3f33a8cc3800bb8c68
4
+ data.tar.gz: 83a9efdfe925a67a27221b7f2f006191c54ef928
5
5
  SHA512:
6
- metadata.gz: b9be7bdaf88cb70f5c5880c8eadbdd082f168b2944c8bf6a0b9ef2a7653b926c54a837a7bfb415fe19ec471ce2041075141ab4e00e6e5e9b06e9aaf96bd8bb2d
7
- data.tar.gz: c746e0aa7b34e09c8ef9d53410a19ea69e0ea6ea9aaad4cfcce7546457e4046b3d440e6a69b5809cf7e6a69932442a3c0d47509d21af3fa7ffc74d1a4cb43e7d
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, :products, :plan, :user, :card, :shipping_address
6
+ decorates_assigned :order, :orders, :plan, :card
7
7
  end
8
8
 
9
9
  def new
10
- @products = Product.all
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
- @plan = Plan.purchasable.find(params[:plan_id]) if params[:plan_id]
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
- @products = Product.all
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 = @user = 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 = @user = new_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 = @shipping_address = ShippingAddress.new(
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
@@ -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, presence: true
17
+ validates :user, associated: true
18
18
  validate :validate_plan_addons_included
19
19
 
20
20
  before_validation :set_total
@@ -1,3 +1,3 @@
1
1
  module OpCart
2
- VERSION = "0.4.6"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: op_cart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs