comable_frontend 0.2.0 → 0.2.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 633b7c0815b6230271e217caa3fcb309699b8a5b
|
4
|
+
data.tar.gz: 93fbd100f5fb435a83bf00a0ee67faad1d46d202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 360d06fa73b0ddcc5d7598518c7edc3f27b77e01397f678e846071c8b5a7c2b8bd56cb99c37c30d8ce329c179642ccc0875bc8b907f9d0b9ad46c95a54e374c1
|
7
|
+
data.tar.gz: 336ad81da2599de8430ecdcb5e8bcadc9025fb86304d50b4bda80c743bc8e30a8dace03887ad366176adae8a653e3b8d629488812e80ae9f8aa845980b54410d
|
@@ -1,19 +1,17 @@
|
|
1
1
|
module Comable
|
2
|
-
class CartsController < ApplicationController
|
2
|
+
class CartsController < Comable::ApplicationController
|
3
|
+
rescue_from Comable::NoStock, with: :no_stock
|
4
|
+
|
3
5
|
def show
|
4
6
|
end
|
5
7
|
|
6
8
|
def add
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
if
|
11
|
-
stock = product.stocks.where(id: params[:stock_id]).first
|
12
|
-
return redirect_by_product_not_found unless stock
|
13
|
-
end
|
9
|
+
cart_item = Comable::Stock.where(id: params[:stock_id]).first
|
10
|
+
cart_item ||= Comable::Product.where(id: params[:product_id]).first
|
11
|
+
return redirect_by_product_not_found unless cart_item
|
12
|
+
return redirect_by_product_not_found if cart_item.is_a?(Comable::Product) && cart_item.sku?
|
14
13
|
|
15
|
-
|
16
|
-
current_customer.add_cart_item(stock || product, quantity: params[:quantity].to_i)
|
14
|
+
current_customer.add_cart_item(cart_item, cart_item_options)
|
17
15
|
|
18
16
|
flash[:notice] = I18n.t('comable.carts.add_product')
|
19
17
|
redirect_to cart_path
|
@@ -23,8 +21,7 @@ module Comable
|
|
23
21
|
stock = Comable::Stock.where(id: params[:stock_id]).first
|
24
22
|
return redirect_by_product_not_found unless stock
|
25
23
|
|
26
|
-
|
27
|
-
current_customer.reset_cart_item(stock, quantity: params[:quantity].to_i)
|
24
|
+
current_customer.reset_cart_item(stock, cart_item_options)
|
28
25
|
|
29
26
|
flash[:notice] = I18n.t('comable.carts.update')
|
30
27
|
redirect_to cart_path
|
@@ -33,8 +30,19 @@ module Comable
|
|
33
30
|
private
|
34
31
|
|
35
32
|
def redirect_by_product_not_found
|
36
|
-
flash[:
|
33
|
+
flash[:alert] = I18n.t('comable.errors.messages.products_not_found')
|
37
34
|
redirect_to :back
|
38
35
|
end
|
36
|
+
|
37
|
+
def no_stock
|
38
|
+
flash[:alert] = I18n.t('comable.errors.messages.products_soldout')
|
39
|
+
redirect_to cart_path
|
40
|
+
end
|
41
|
+
|
42
|
+
def cart_item_options
|
43
|
+
options = {}
|
44
|
+
options.update(quantity: params[:quantity].to_i) if params[:quantity]
|
45
|
+
options
|
46
|
+
end
|
39
47
|
end
|
40
48
|
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.1
|
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
|
+
date: 2014-10-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.1
|
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.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|