comable_frontend 0.2.0 → 0.2.1

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: 818130115846669a1166faed5413d2ae2ed988e9
4
- data.tar.gz: d024d10b74212e576fe0b68d3776e4875ea6a5e7
3
+ metadata.gz: 633b7c0815b6230271e217caa3fcb309699b8a5b
4
+ data.tar.gz: 93fbd100f5fb435a83bf00a0ee67faad1d46d202
5
5
  SHA512:
6
- metadata.gz: 2fef8557e1d66e73985642526013ee0d7532f873c897b0b6f8e87cf993cbc2970746f46bea364c55e3172c4741dc1ff98453122a334ac26fd7d15bf71bd16e40
7
- data.tar.gz: 24d80b8c5c0f182eaa586ceeadcdab503b3841b6b21a5f41e612dfdeb2603beccd5daa3bc246d1207eba241fc03102af5c280f71a156d17a01251734f0a9c92c
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
- product = Comable::Product.where(id: params[:product_id]).first
8
- return redirect_by_product_not_found unless product
9
-
10
- if product.sku?
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
- # TODO: 在庫確認
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
- # TODO: 在庫確認
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[:error] = I18n.t('comable.carts.product_not_found')
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
@@ -1,5 +1,5 @@
1
1
  module Comable
2
- class OrdersController < ApplicationController
2
+ class OrdersController < Comable::ApplicationController
3
3
  prepend Comable::ShipmentAction
4
4
  prepend Comable::PaymentAction
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Comable
2
- class ProductsController < ApplicationController
2
+ class ProductsController < Comable::ApplicationController
3
3
  def index
4
4
  @products = Comable::Product.all
5
5
  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.0
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-09-28 00:00:00.000000000 Z
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.0
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.0
26
+ version: 0.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement