stall 0.1.2 → 0.1.3

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: 0524d2c5e775b699249a9e311d7eb05f2a28329a
4
- data.tar.gz: f13ac7bc4efa4013a6cabf3d92214669832b2610
3
+ metadata.gz: 93101cd6c71bd164e54d7f7a96009894eaee815d
4
+ data.tar.gz: e9e552e25b8fa6a49ac0423cacac158b267585ab
5
5
  SHA512:
6
- metadata.gz: d25def30d139c976bbcc3c25635bcc4321dc152b008c62ea4b9d64798b6402b0d1715625e14763588ee3b0d23bef7d88c9591bbc230d9b31ad486d3c8d147544
7
- data.tar.gz: c4a3e2c50f5770ad510c1cf8dce6329526e8dc3b5c16172960150976d0ea6ad75b3c87cf4f6735f1c345680a685ba6b6caf02c18352fe17610a0439d624fc337
6
+ metadata.gz: ad0c5c29e895dcadf8aff1631374685f209ce73db2e6c28ff313648e33c67093dbb0fbef762d34abcaaf9b3eb4f015a6a151285b47f8327fb194c3e162f0dfa1
7
+ data.tar.gz: ad331dadf79752be6c13933ef96060aa07c4b7ae5ebbea33f42757d2160bfb10825d30c2f6dbe0092d91edb1df82abbb419bc8e55f3b5583274bd889a1b3e7ad
@@ -4,8 +4,8 @@ module Stall
4
4
  include Stall::CheckoutHelper
5
5
 
6
6
  before_action :load_cart
7
- before_action :ensure_cart_checkoutable
8
7
  before_action :load_step
8
+ before_action :ensure_cart_checkoutable
9
9
 
10
10
  def show
11
11
  @step.prepare
@@ -41,7 +41,16 @@ module Stall
41
41
  @cart = current_cart
42
42
  end
43
43
 
44
+ def find_cart(identifier, ensure_active_cart = true)
45
+ super(identifier, false)
46
+ end
47
+
44
48
  def ensure_cart_checkoutable
49
+ unless @cart.active? || @step.allow_inactive_carts?
50
+ remove_cart_from_cookies(@cart.identifier)
51
+ @cart = @cart.class.new
52
+ end
53
+
45
54
  unless @cart.checkoutable?
46
55
  flash[:error] = t('stall.checkout.shared.not_checkoutable')
47
56
  redirect_to request.referrer || root_path
@@ -1,7 +1,7 @@
1
1
  module Stall
2
2
  module CheckoutHelper
3
3
  def step_path(*args)
4
- checkout_step_path(*([current_cart_key] + args))
4
+ checkout_step_path(*([current_cart.identifier] + args))
5
5
  end
6
6
 
7
7
  def available_shipping_methods_for(cart)
@@ -42,7 +42,8 @@ module Stall
42
42
  end
43
43
 
44
44
  def reset_state!
45
- update_column(:state, wizard.steps.first)
45
+ self.state = wizard.steps.first
46
+ save(validate: false) if persisted?
46
47
  end
47
48
 
48
49
  def to_param
@@ -59,5 +59,5 @@
59
59
  %button.btn.btn-default{ type: 'submit', data: { :'cart-update-button' => true } }
60
60
  = t('stall.carts.recap.update')
61
61
 
62
- = link_to checkout_path(current_cart_key), class: 'btn btn-primary' do
62
+ = link_to checkout_path(current_cart.identifier), class: 'btn btn-primary' do
63
63
  = t('stall.carts.recap.validate')
@@ -46,9 +46,11 @@ module Stall
46
46
  end
47
47
  end
48
48
 
49
- def find_cart(identifier)
49
+ def find_cart(identifier, ensure_active_cart = true)
50
50
  if (cart_token = cookies.encrypted[cart_key(identifier)])
51
- if (current_cart = ProductList.find_by_token(cart_token)) && current_cart.active?
51
+ if (current_cart = ProductList.find_by_token(cart_token)) &&
52
+ (!ensure_active_cart || current_cart.active?)
53
+ then
52
54
  return current_cart
53
55
  else
54
56
  # Remove any cart that can't be fetched, either because it's already
@@ -4,6 +4,13 @@ module Stall
4
4
  def process
5
5
  return true if params[:succeeded]
6
6
  end
7
+
8
+ # When we access this step after a payment to validate the step, the cart
9
+ # is "inactive", so we force processing the cart.
10
+ #
11
+ def allow_inactive_carts?
12
+ !!params[:succeeded]
13
+ end
7
14
  end
8
15
  end
9
16
  end
@@ -6,6 +6,13 @@ module Stall
6
6
  def prepare
7
7
  remove_cart_from_cookies(cart.identifier)
8
8
  end
9
+
10
+ # When we access this step, the cart is "inactive", since it is paid, so
11
+ # we force processing the cart.
12
+ #
13
+ def allow_inactive_carts?
14
+ true
15
+ end
9
16
  end
10
17
  end
11
18
  end
@@ -50,6 +50,18 @@ module Stall
50
50
  end
51
51
  end
52
52
 
53
+ # Allows subclasses to override this value with `true` to allow paid carts
54
+ # to be processed by that step too.
55
+ #
56
+ # Returning false redirects the user telling him that his cart is empty
57
+ #
58
+ # By default, the `PaymentReturn` checkout step returns true, since it's
59
+ # always called after the cart is paid
60
+ #
61
+ def allow_inactive_carts?
62
+ false
63
+ end
64
+
53
65
  # Abstracts the simple case of assigning the submitted parameters to the
54
66
  # cart object, running the step validations and saving the cart
55
67
  def save
data/lib/stall/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stall
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - vala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-08 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails