comable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/comable/carts_controller.rb +12 -1
- data/app/models/comable/cart_item.rb +0 -2
- data/app/models/comable/customer.rb +37 -25
- data/app/views/comable/carts/show.slim +20 -16
- data/app/views/comable/products/show.slim +1 -0
- data/config/locales/ja.yml +1 -0
- data/lib/comable/engine.rb +0 -1
- data/lib/comable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56d44aba496e45370483a0b7a625fcf96f4dabf2
|
4
|
+
data.tar.gz: 03b299ed0c7bcfb019964d1da1758175951052d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d97538ce5e3a49d8c47b6f98da650be04606d4e51b535fc610ef9b9c334740bd17d9c6c66e4e2931c007851a27ce20eaa0b5bf2d0b718dd649e7bdfb6d326826
|
7
|
+
data.tar.gz: fd264578ddb1caffef0f74ece4c72d08cd73092250b833101f9708ab34687e489d487c8cf8e5757f0f91183d1316aef9cd9c4d2bd787e6b0a498ef1b0d69e74c
|
@@ -13,12 +13,23 @@ module Comable
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# TODO: 在庫確認
|
16
|
-
current_customer.add_cart_item(stock || product)
|
16
|
+
current_customer.add_cart_item(stock || product, quantity: params[:quantity].to_i)
|
17
17
|
|
18
18
|
flash[:notice] = I18n.t('comable.carts.add_product')
|
19
19
|
redirect_to cart_path
|
20
20
|
end
|
21
21
|
|
22
|
+
def update
|
23
|
+
stock = Comable::Stock.where(id: params[:stock_id]).first
|
24
|
+
return redirect_by_product_not_found unless stock
|
25
|
+
|
26
|
+
# TODO: 在庫確認
|
27
|
+
current_customer.reset_cart_item(stock, quantity: params[:quantity].to_i)
|
28
|
+
|
29
|
+
flash[:notice] = I18n.t('comable.carts.update')
|
30
|
+
redirect_to cart_path
|
31
|
+
end
|
32
|
+
|
22
33
|
private
|
23
34
|
|
24
35
|
def redirect_by_product_not_found
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module Comable
|
2
2
|
class CartItem < ActiveRecord::Base
|
3
|
-
utusemi!
|
4
|
-
|
5
3
|
belongs_to :customer, class_name: Comable::Customer.name, foreign_key: Comable::Customer.table_name.singularize.foreign_key
|
6
4
|
belongs_to :stock, class_name: Comable::Stock.name, foreign_key: Comable::Stock.table_name.singularize.foreign_key
|
7
5
|
|
@@ -24,25 +24,21 @@ module Comable
|
|
24
24
|
!logged_in?
|
25
25
|
end
|
26
26
|
|
27
|
-
def add_cart_item(obj)
|
28
|
-
|
29
|
-
|
30
|
-
add_stock_to_cart(obj.stocks.first)
|
31
|
-
when Comable::Stock
|
32
|
-
add_stock_to_cart(obj)
|
33
|
-
when Array
|
34
|
-
obj.map { |item| add_cart_item(item) }
|
35
|
-
else
|
36
|
-
fail
|
27
|
+
def add_cart_item(obj, quantity: 1)
|
28
|
+
process_cart_item(obj) do |stock|
|
29
|
+
add_stock_to_cart(stock, quantity)
|
37
30
|
end
|
38
31
|
end
|
39
32
|
|
40
|
-
def remove_cart_item(obj)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
33
|
+
def remove_cart_item(obj, quantity: -1)
|
34
|
+
process_cart_item(obj) do |stock|
|
35
|
+
add_stock_to_cart(stock, quantity)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset_cart_item(obj, quantity: 0)
|
40
|
+
process_cart_item(obj) do |stock|
|
41
|
+
reset_stock_from_cart(stock, quantity)
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
@@ -83,26 +79,42 @@ module Comable
|
|
83
79
|
@cookies.signed[:guest_token]
|
84
80
|
end
|
85
81
|
|
86
|
-
def
|
82
|
+
def process_cart_item(obj)
|
83
|
+
case obj
|
84
|
+
when Comable::Product
|
85
|
+
yield obj.stocks.first
|
86
|
+
when Comable::Stock
|
87
|
+
yield obj
|
88
|
+
when Array
|
89
|
+
obj.map { |item| yield item }
|
90
|
+
else
|
91
|
+
fail
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_stock_to_cart(stock, quantity)
|
87
96
|
fail I18n.t('comable.carts.product_not_stocked') if stock.soldout?
|
88
97
|
|
89
98
|
cart_items = find_cart_items_by(stock)
|
90
99
|
if cart_items.any?
|
91
100
|
cart_item = cart_items.first
|
92
|
-
cart_item.
|
101
|
+
cart_item.quantity += quantity
|
102
|
+
(cart_item.quantity > 0) ? cart_item.save : cart_item.destroy
|
93
103
|
else
|
94
|
-
cart_item = cart_items.create
|
104
|
+
cart_item = cart_items.create(quantity: quantity)
|
95
105
|
@cookies.permanent.signed[:guest_token] = cart_item.guest_token if not_logged_in?
|
96
106
|
end
|
97
107
|
end
|
98
108
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
cart_item.
|
109
|
+
def reset_stock_from_cart(stock, quantity)
|
110
|
+
cart_items = find_cart_items_by(stock)
|
111
|
+
if quantity > 0
|
112
|
+
return add_stock_to_cart(stock, quantity) if cart_items.empty?
|
113
|
+
cart_item = cart_items.first
|
114
|
+
cart_item.quantity = quantity
|
115
|
+
cart_item.save
|
105
116
|
else
|
117
|
+
return false if cart_items.empty?
|
106
118
|
cart_item.destroy
|
107
119
|
end
|
108
120
|
end
|
@@ -2,22 +2,26 @@ h1 カート
|
|
2
2
|
|
3
3
|
ul.cart
|
4
4
|
- current_customer.cart.each do |cart_item|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
5
|
+
= form_tag comable.cart_path, method: :put do
|
6
|
+
- stock = cart_item.stock
|
7
|
+
- product = stock.product
|
8
|
+
li.product
|
9
|
+
h2.name
|
10
|
+
- if stock.sku?
|
11
|
+
- sku_name = stock.sku_h_choice_name
|
12
|
+
- sku_name += '/' + stock.sku_v_choice_name if stock.sku_v_choice_name.present?
|
13
|
+
= link_to product.name + "(#{sku_name})", comable.product_path(product)
|
14
|
+
- else
|
15
|
+
= link_to product.name, comable.product_path(product)
|
16
|
+
.caption
|
17
|
+
= product.caption
|
18
|
+
.price
|
19
|
+
= number_to_currency product.price
|
20
|
+
.quantity
|
21
|
+
- selected = cart_item.quantity
|
22
|
+
= select_tag :quantity, options_for_select(1.upto([10, selected].max).to_a, selected)
|
23
|
+
= hidden_field_tag :stock_id, stock.id
|
24
|
+
= submit_tag '変更'
|
21
25
|
|
22
26
|
.order
|
23
27
|
= link_to '注文', comable.new_order_path
|
data/config/locales/ja.yml
CHANGED
data/lib/comable/engine.rb
CHANGED
data/lib/comable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-08-
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|