comable_frontend 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/comable/customers_controller.rb +21 -0
- data/app/controllers/comable/orders_controller.rb +35 -10
- data/app/controllers/concerns/comable/permitted_attributes.rb +15 -0
- data/app/views/comable/carts/show.slim +1 -3
- data/app/views/comable/customers/_address.slim +14 -0
- data/app/views/comable/customers/addresses.slim +52 -0
- data/app/views/comable/orders/confirm.slim +22 -24
- data/app/views/comable/orders/delivery.slim +39 -8
- data/app/views/comable/orders/new.slim +1 -1
- data/app/views/comable/orders/orderer.slim +46 -8
- data/app/views/comable/shared/_address.slim +20 -0
- data/app/views/comable/shared/_address_form.slim +21 -0
- data/app/views/layouts/comable/application.slim +3 -0
- data/config/routes.rb +6 -1
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32dbeca21c4c86948b916e807e6aaa2ed9bc0bcf
|
4
|
+
data.tar.gz: a54136ef96d2c802dbcd42b400877d1a1d93abea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c5bf6ff78e805fc86083aea2d7165d96ede22ef59bedd72f937a7c18bcd06a45f46970a866f9973eaf70088d21b3d3b3ac13bd8f6ca1bed19d551d18abe0515
|
7
|
+
data.tar.gz: 327fa0e0ae8e74745ecdceaaccd77fa998246c6f2389ec933bf7219303c0a7d53aba68f42fea3906d50ed21c4926c12ce7a1cc65e471bd7ab0e1029d10709015
|
@@ -1,8 +1,29 @@
|
|
1
1
|
module Comable
|
2
2
|
class CustomersController < Comable::ApplicationController
|
3
|
+
include Comable::PermittedAttributes
|
4
|
+
|
3
5
|
before_filter :authenticate_customer!
|
4
6
|
|
5
7
|
def show
|
6
8
|
end
|
9
|
+
|
10
|
+
def addresses
|
11
|
+
return unless request.put?
|
12
|
+
|
13
|
+
current_customer.attributes = customer_params
|
14
|
+
if current_customer.save
|
15
|
+
flash.now[:notice] = 'Success'
|
16
|
+
else
|
17
|
+
flash.now[:alert] = 'Error'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def customer_params
|
22
|
+
params.require(:customer).permit(
|
23
|
+
:bill_address_id,
|
24
|
+
:ship_address_id,
|
25
|
+
addresses_attributes: permitted_address_attributes
|
26
|
+
)
|
27
|
+
end
|
7
28
|
end
|
8
29
|
end
|
@@ -2,24 +2,33 @@ module Comable
|
|
2
2
|
class OrdersController < Comable::ApplicationController
|
3
3
|
prepend Comable::ShipmentAction
|
4
4
|
prepend Comable::PaymentAction
|
5
|
+
include Comable::PermittedAttributes
|
5
6
|
|
7
|
+
helper_method :next_order_path
|
8
|
+
|
9
|
+
# TODO: Change the method name to load_order_with_params
|
6
10
|
before_filter :load_order
|
7
11
|
before_filter :verify
|
12
|
+
# TODO: Remove
|
8
13
|
after_filter :save_order, except: :create
|
9
14
|
|
10
15
|
rescue_from Comable::InvalidOrder, with: :order_invalid
|
11
16
|
|
17
|
+
def new
|
18
|
+
redirect_to next_order_path unless agreement_required?
|
19
|
+
end
|
20
|
+
|
12
21
|
def orderer
|
13
22
|
case request.method_symbol
|
14
23
|
when :post
|
15
|
-
redirect_to
|
24
|
+
redirect_to next_order_path if @order.save
|
16
25
|
end
|
17
26
|
end
|
18
27
|
|
19
28
|
def delivery
|
20
29
|
case request.method_symbol
|
21
30
|
when :post
|
22
|
-
redirect_to next_order_path
|
31
|
+
redirect_to next_order_path if @order.save
|
23
32
|
end
|
24
33
|
end
|
25
34
|
|
@@ -40,8 +49,14 @@ module Comable
|
|
40
49
|
Comable::OrderMailer.complete(@order).deliver if current_store.email_activate?
|
41
50
|
end
|
42
51
|
|
52
|
+
# TODO: Switch to state_machine
|
53
|
+
# rubocop:disable all
|
43
54
|
def next_order_path(target_action_name = nil)
|
44
55
|
case (target_action_name || action_name).to_sym
|
56
|
+
when :new
|
57
|
+
orderer_required? ? comable.orderer_order_path : next_order_path(:orderer)
|
58
|
+
when :orderer
|
59
|
+
delivery_required? ? comable.delivery_order_path : next_order_path(:delivery)
|
45
60
|
when :delivery
|
46
61
|
shipment_required? ? comable.shipment_order_path : next_order_path(:shipment)
|
47
62
|
when :shipment
|
@@ -50,6 +65,19 @@ module Comable
|
|
50
65
|
comable.confirm_order_path
|
51
66
|
end
|
52
67
|
end
|
68
|
+
# rubocop:enable all
|
69
|
+
|
70
|
+
def agreement_required?
|
71
|
+
@order.customer.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
def orderer_required?
|
75
|
+
@order.bill_address.nil?
|
76
|
+
end
|
77
|
+
|
78
|
+
def delivery_required?
|
79
|
+
@order.ship_address.nil?
|
80
|
+
end
|
53
81
|
|
54
82
|
def verify
|
55
83
|
return if current_customer.cart.any?
|
@@ -77,19 +105,16 @@ module Comable
|
|
77
105
|
|
78
106
|
def order_params_for_orderer
|
79
107
|
params.require(:order).permit(
|
80
|
-
:family_name,
|
81
|
-
:first_name,
|
82
|
-
:email
|
108
|
+
:family_name, # TODO: Remove
|
109
|
+
:first_name, # TODO: Remove
|
110
|
+
:email,
|
111
|
+
bill_address_attributes: permitted_address_attributes
|
83
112
|
)
|
84
113
|
end
|
85
114
|
|
86
115
|
def order_params_for_delivery
|
87
116
|
params.require(:order).permit(
|
88
|
-
|
89
|
-
:id,
|
90
|
-
:family_name,
|
91
|
-
:first_name
|
92
|
-
]
|
117
|
+
ship_address_attributes: permitted_address_attributes
|
93
118
|
)
|
94
119
|
end
|
95
120
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
= render 'comable/shared/address', address: address
|
2
|
+
|
3
|
+
.buttons
|
4
|
+
.use_bill_address
|
5
|
+
- if address != address.customer.bill_address
|
6
|
+
= form_for current_customer, as: :customer, url: comable.addresses_customer_url, method: :put do |f|
|
7
|
+
= f.hidden_field :bill_address_id, value: address.id
|
8
|
+
= f.submit 'use as billing address'
|
9
|
+
|
10
|
+
.use_ship_address
|
11
|
+
- if address != address.customer.ship_address
|
12
|
+
= form_for current_customer, as: :customer, url: comable.addresses_customer_url, method: :put do |f|
|
13
|
+
= f.hidden_field :ship_address_id, value: address.id
|
14
|
+
= f.submit 'use as shipping address'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
.customer
|
2
|
+
.addresses
|
3
|
+
h1
|
4
|
+
| Addresses
|
5
|
+
|
6
|
+
- if current_customer.errors.any?
|
7
|
+
.errors
|
8
|
+
ul
|
9
|
+
- current_customer.errors.full_messages.each do |full_message|
|
10
|
+
li = full_message
|
11
|
+
|
12
|
+
- if current_customer.addresses.empty?
|
13
|
+
.not_found
|
14
|
+
p
|
15
|
+
| Not found.
|
16
|
+
- else
|
17
|
+
.bill_address
|
18
|
+
h2
|
19
|
+
| Bill address
|
20
|
+
- if current_customer.bill_address
|
21
|
+
= render 'address', address: current_customer.bill_address
|
22
|
+
- else
|
23
|
+
.not_found
|
24
|
+
p
|
25
|
+
| Not found.
|
26
|
+
|
27
|
+
.ship_address
|
28
|
+
h2
|
29
|
+
| Ship address
|
30
|
+
- if current_customer.ship_address
|
31
|
+
= render 'address', address: current_customer.ship_address
|
32
|
+
- else
|
33
|
+
.not_found
|
34
|
+
p
|
35
|
+
| Not found.
|
36
|
+
|
37
|
+
.other_addresses
|
38
|
+
h2
|
39
|
+
| Other addresses
|
40
|
+
ul
|
41
|
+
- current_customer.other_addresses.each do |address|
|
42
|
+
li
|
43
|
+
= render 'address', address: address
|
44
|
+
|
45
|
+
.new_address
|
46
|
+
h2
|
47
|
+
| New Address
|
48
|
+
= form_for current_customer, as: :customer, url: comable.addresses_customer_url, method: :put do |f|
|
49
|
+
= f.fields_for :addresses, current_customer.addresses.build do |ff|
|
50
|
+
= render 'comable/shared/address_form', address: ff
|
51
|
+
.submit
|
52
|
+
= f.submit
|
@@ -1,37 +1,35 @@
|
|
1
1
|
h1 注文情報確認
|
2
2
|
|
3
3
|
.order
|
4
|
-
.
|
5
|
-
h2
|
6
|
-
|
7
|
-
|
8
|
-
.first_name
|
9
|
-
= @order.first_name
|
4
|
+
.bill_address
|
5
|
+
h2
|
6
|
+
| Billing address
|
7
|
+
= render 'comable/shared/address', address: @order.bill_address if @order.bill_address
|
10
8
|
|
11
|
-
.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
9
|
+
.ship_address
|
10
|
+
h2
|
11
|
+
| Shipping address
|
12
|
+
= render 'comable/shared/address', address: @order.ship_address if @order.ship_address
|
13
|
+
|
14
|
+
.details
|
15
|
+
h2
|
16
|
+
| Order details
|
17
|
+
- @order.order_deliveries.first.order_details.each do |order_detail|
|
18
|
+
.name
|
19
|
+
= order_detail.stock.name
|
20
|
+
.price
|
21
|
+
= order_detail.price
|
22
|
+
.quantity
|
23
|
+
= order_detail.quantity
|
26
24
|
|
27
25
|
.total
|
28
26
|
h2 お会計
|
29
27
|
.item_total_price
|
30
|
-
= @order.current_item_total_price
|
28
|
+
= number_to_currency @order.current_item_total_price
|
31
29
|
.shipment_fee
|
32
|
-
= @order.current_shipment_fee
|
30
|
+
= number_to_currency @order.current_shipment_fee
|
33
31
|
.total_price
|
34
|
-
= @order.current_total_price
|
32
|
+
= number_to_currency @order.current_total_price
|
35
33
|
|
36
34
|
= form_for @order, as: :order, url: comable.order_path, method: :post do |f|
|
37
35
|
= f.submit
|
@@ -1,8 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
=
|
8
|
-
|
1
|
+
.order
|
2
|
+
.ship_address
|
3
|
+
h1
|
4
|
+
| Shipping address
|
5
|
+
|
6
|
+
- if @order.ship_address
|
7
|
+
= render 'comable/shared/address', address: @order.ship_address
|
8
|
+
= link_to 'Next step', next_order_path
|
9
|
+
|
10
|
+
- if current_customer.other_addresses.any?
|
11
|
+
.other_addresses
|
12
|
+
h2
|
13
|
+
| Other addresses
|
14
|
+
ul
|
15
|
+
- current_customer.addresses.each do |address|
|
16
|
+
- next if @order.ship_address.same_as? address
|
17
|
+
li
|
18
|
+
= render 'comable/shared/address', address: address
|
19
|
+
= form_for @order, as: :order, url: comable.delivery_order_path, method: :put do |f|
|
20
|
+
.hidden
|
21
|
+
= f.fields_for :ship_address, address.clone do |ff|
|
22
|
+
= render 'comable/shared/address_form', address: ff
|
23
|
+
= f.submit 'Use this'
|
24
|
+
|
25
|
+
- else
|
26
|
+
/ TODO: Standardize
|
27
|
+
- if @order.errors.any?
|
28
|
+
.error_messages
|
29
|
+
ul
|
30
|
+
- @order.errors.full_messages.each do |full_message|
|
31
|
+
li = full_message
|
32
|
+
|
33
|
+
.new
|
34
|
+
h2
|
35
|
+
| New shipping address
|
36
|
+
= form_for @order, as: :order, url: comable.delivery_order_path, method: :put do |f|
|
37
|
+
= f.fields_for :ship_address do |ff|
|
38
|
+
= render 'comable/shared/address_form', address: ff
|
39
|
+
= f.submit
|
@@ -1,8 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
.order
|
2
|
+
.bill_address
|
3
|
+
h1
|
4
|
+
| Billing address
|
5
|
+
|
6
|
+
- if @order.bill_address
|
7
|
+
= render 'comable/shared/address', address: @order.bill_address
|
8
|
+
= link_to 'Next step', next_order_path
|
9
|
+
|
10
|
+
- if current_customer.other_addresses.any?
|
11
|
+
.other_addresses
|
12
|
+
h2
|
13
|
+
| Other addresses
|
14
|
+
ul
|
15
|
+
- current_customer.addresses.each do |address|
|
16
|
+
- next if @order.bill_address.same_as? address
|
17
|
+
li
|
18
|
+
= render 'comable/shared/address', address: address
|
19
|
+
= form_for @order, as: :order, url: comable.orderer_order_path, method: :put do |f|
|
20
|
+
.hidden
|
21
|
+
= f.fields_for :bill_address, address.clone do |ff|
|
22
|
+
= render 'comable/shared/address_form', address: ff
|
23
|
+
= f.submit 'Use this'
|
24
|
+
|
25
|
+
- else
|
26
|
+
/ TODO: Standardize
|
27
|
+
- if @order.errors.any?
|
28
|
+
.error_messages
|
29
|
+
ul
|
30
|
+
- @order.errors.full_messages.each do |full_message|
|
31
|
+
li = full_message
|
32
|
+
|
33
|
+
.new
|
34
|
+
h2
|
35
|
+
| New billing address
|
36
|
+
= form_for @order, as: :order, url: comable.orderer_order_path, method: :put do |f|
|
37
|
+
= f.email_field :email, placeholder: @order.class.human_attribute_name(:email)
|
38
|
+
= f.fields_for :bill_address do |ff|
|
39
|
+
= render 'comable/shared/address_form', address: ff
|
40
|
+
= f.submit
|
41
|
+
|
42
|
+
/ for old spec
|
43
|
+
/ TODO: Remove
|
44
|
+
.hidden
|
45
|
+
= f.text_field :family_name, placeholder: '姓'
|
46
|
+
= f.text_field :first_name, placeholder: '名'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
dl
|
2
|
+
.name
|
3
|
+
dt = address.class.human_attribute_name(:family_name)
|
4
|
+
dd = address.family_name
|
5
|
+
dt = address.class.human_attribute_name(:first_name)
|
6
|
+
dd = address.first_name
|
7
|
+
.address
|
8
|
+
.state
|
9
|
+
dt = address.class.human_attribute_name(:state_name)
|
10
|
+
dd = address.state_name
|
11
|
+
.zip_code
|
12
|
+
dt = address.class.human_attribute_name(:zip_code)
|
13
|
+
dd = address.zip_code
|
14
|
+
.city
|
15
|
+
dt = address.class.human_attribute_name(:city)
|
16
|
+
dd = address.city
|
17
|
+
.other
|
18
|
+
.phone_number
|
19
|
+
dt = address.class.human_attribute_name(:phone_number)
|
20
|
+
dd = address.phone_number
|
@@ -0,0 +1,21 @@
|
|
1
|
+
.name
|
2
|
+
= address.label :family_name
|
3
|
+
= address.text_field :family_name
|
4
|
+
= address.label :first_name
|
5
|
+
= address.text_field :first_name
|
6
|
+
|
7
|
+
.address
|
8
|
+
.state
|
9
|
+
= address.label :state_name
|
10
|
+
= address.text_field :state_name
|
11
|
+
.zip_code
|
12
|
+
= address.label :zip_code
|
13
|
+
= address.text_field :zip_code, max_length: 8
|
14
|
+
.city
|
15
|
+
= address.label :city
|
16
|
+
= address.text_field :city
|
17
|
+
|
18
|
+
.other
|
19
|
+
.phone_number
|
20
|
+
= address.label :phone_number
|
21
|
+
= address.text_field :phone_number, max_length: 18
|
data/config/routes.rb
CHANGED
@@ -25,5 +25,10 @@ Comable::Core::Engine.routes.draw do
|
|
25
25
|
|
26
26
|
devise_for :customer, path: :member, class_name: Comable::Customer.name, module: :devise
|
27
27
|
|
28
|
-
resource :customer, path: :member
|
28
|
+
resource :customer, path: :member do
|
29
|
+
member do
|
30
|
+
get :addresses
|
31
|
+
put :addresses
|
32
|
+
end
|
33
|
+
end
|
29
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comable_frontend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YOSHIDA Hiroki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: comable_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
19
|
+
version: 0.2.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.
|
26
|
+
version: 0.2.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,8 +81,11 @@ files:
|
|
81
81
|
- app/controllers/comable/orders_controller.rb
|
82
82
|
- app/controllers/comable/products_controller.rb
|
83
83
|
- app/controllers/concerns/comable/payment_action.rb
|
84
|
+
- app/controllers/concerns/comable/permitted_attributes.rb
|
84
85
|
- app/controllers/concerns/comable/shipment_action.rb
|
85
86
|
- app/views/comable/carts/show.slim
|
87
|
+
- app/views/comable/customers/_address.slim
|
88
|
+
- app/views/comable/customers/addresses.slim
|
86
89
|
- app/views/comable/customers/show.slim
|
87
90
|
- app/views/comable/orders/confirm.slim
|
88
91
|
- app/views/comable/orders/create.slim
|
@@ -93,6 +96,8 @@ files:
|
|
93
96
|
- app/views/comable/orders/shipment.slim
|
94
97
|
- app/views/comable/products/index.slim
|
95
98
|
- app/views/comable/products/show.slim
|
99
|
+
- app/views/comable/shared/_address.slim
|
100
|
+
- app/views/comable/shared/_address_form.slim
|
96
101
|
- app/views/layouts/comable/application.slim
|
97
102
|
- config/routes.rb
|
98
103
|
- lib/comable/frontend/engine.rb
|