stall 0.3.4 → 0.3.5

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: ac018d181d2997364eeca462e80758d50ab4c9e2
4
- data.tar.gz: 4e3396a2466fab227f83d9d201a237e22147acc3
3
+ metadata.gz: 2ada0574ad0ed8cfa93095644bdf32a04bcb0509
4
+ data.tar.gz: a14972609cff3c4e91cc431dfcf052a8d32a646d
5
5
  SHA512:
6
- metadata.gz: c612280b92d9cbff047f8e7e0adf1f8dcc8abea245f7cd4cbf37170a68261c0d732f53266c11ba666fbf103c3b3998f267ce970fbb553b40880f88a2e52ee21e
7
- data.tar.gz: b35431b6aa8856a8b3dc21686dff0346d0b724ec443176f044d022e0495563584a7e6d8ff537b227be52f91aed929b9e23bbacfa85ff7fb1c827024d7749cb51
6
+ metadata.gz: a2d940165c3b6162689bc986170b9d0d43bbb66a4a093db2d36afd82f49119db11d70ecafd28ed44092d1dcaec48f1cc1eca4e1f88f3e9cec0121bb987b683d8
7
+ data.tar.gz: 6260a59db786d455c54a10dd4806ad19e568bb529f697d8dcf57d1c6675dcff52b4e1d4857a391a6023899528594640cbee24fde91c9a1c1fbe3b21c17597e9f
@@ -57,27 +57,42 @@ class VariantsMatrix.Input extends Vertebra.View
57
57
 
58
58
  refreshAvailableVariants: ->
59
59
  combinations = @buildPossibleCombinations()
60
- @removeVariantsNotIn(combinations)
61
- @createVariantsIn(combinations)
60
+ removeableVariants = @variantsNotIn(combinations)
61
+ createdVariants = @createVariantsIn(combinations)
62
62
 
63
- removeVariantsNotIn: (combinations) ->
63
+ # Copy default values from removeable variants before they're removed from
64
+ # the DOM, allowing the Variant#copyInputsFrom method to work
65
+ @applyDefaultValuesForNewVariants(removeableVariants, createdVariants)
66
+
67
+ @removeVariants(removeableVariants)
68
+
69
+ variantsNotIn: (combinations) ->
64
70
  removeableVariants = []
65
71
 
66
72
  for variant, index in @variants
67
- continue unless variant
73
+ continue if !variant or variant.isDestroyed
68
74
  matches = false
69
75
  matches = true for combination in combinations when variant.matches(combination)
70
76
  removeableVariants.push(variant) unless matches
71
77
 
72
- # We remove variants after iterating, avoiding to change array indexes
73
- # while we loop through it to match removeable variants
78
+ removeableVariants
79
+
80
+ removeVariants: (removeableVariants) ->
74
81
  variant.remove() for variant in removeableVariants
75
82
 
76
83
  createVariantsIn: (combinations) ->
84
+ @newVariants = []
85
+
77
86
  for combination in combinations
78
87
  existingVariant = @findVariantFor(combination)
79
- variant = existingVariant or @createVariantFor(combination)
88
+ newVariant = false
89
+
90
+ unless (variant = existingVariant)
91
+ variant = @createVariantFor(combination)
92
+ @newVariants.push(variant)
93
+
80
94
  variant.show()
95
+ variant
81
96
 
82
97
  findVariantFor: (combination) ->
83
98
  return variant for variant, index in @variants when variant.matches(combination)
@@ -128,6 +143,23 @@ class VariantsMatrix.Input extends Vertebra.View
128
143
 
129
144
  if !combinations.length && @allowEmptyVariant then [{}] else combinations
130
145
 
146
+ applyDefaultValuesForNewVariants: (removeableVariants, createdVariants) ->
147
+ existingVariants = if removeableVariants.length >= createdVariants.length
148
+ removeableVariants
149
+ else
150
+ (v for v in createdVariants when !@isNewVariant(v))
151
+
152
+ if existingVariants.length >= @newVariants.length
153
+ v.copyInputsFrom(existingVariants[i]) for v, i in @newVariants
154
+ else if existingVariants.length
155
+ v.copyInputsFrom(existingVariants[0]) for v, i in @newVariants
156
+
157
+ isNewVariant: (variant) ->
158
+ for v in @newVariants
159
+ return true if variant.cid is v.cid
160
+
161
+ false
162
+
131
163
  onVariantApplyToAll: (variant) =>
132
164
  v.copyInputsFrom(variant) for v in @variants when v.cid isnt variant.cid
133
165
 
@@ -137,4 +169,3 @@ class VariantsMatrix.Input extends Vertebra.View
137
169
  destroyedVariant.destroy()
138
170
  # Remove variant from @variants array
139
171
  @variants.splice(index, 1) for variant, index in @variants when variant?.matches(destroyedVariant.combination)
140
-
@@ -12,6 +12,8 @@ class VariantsMatrix.PropertiesSelect extends Vertebra.View
12
12
  # field name and the selected property values ids
13
13
  #
14
14
  getSelectedProperties: ->
15
+ selectedProperties = []
16
+
15
17
  for el in @$propertySelects.get()
16
18
  $field = $(el)
17
19
 
@@ -23,7 +25,16 @@ class VariantsMatrix.PropertiesSelect extends Vertebra.View
23
25
 
24
26
  fieldName = $field.data('variants-matrix-property-select')
25
27
  values = @serializeFieldValues($field, propertyId)
26
- { id: propertyId, name: fieldName, values: values, active: !!values.length }
28
+
29
+ continue unless values?.length
30
+
31
+ selectedProperties.push
32
+ id: propertyId
33
+ name: fieldName
34
+ values: values
35
+ active: !!values.length
36
+
37
+ selectedProperties
27
38
 
28
39
  serializeFieldValues: ($field, propertyId) ->
29
40
  for option in $field.find(':selected').get()
@@ -6,6 +6,7 @@ class VariantsMatrix.Variant extends Vertebra.View
6
6
  initialize: (options = {}) ->
7
7
  @combination = options.combination
8
8
  @persisted = @$el?.data('variant-id')
9
+ @isDestroyed = false
9
10
  @input = options.input
10
11
 
11
12
  renderTo: ($container) ->
@@ -16,6 +17,9 @@ class VariantsMatrix.Variant extends Vertebra.View
16
17
  @fillProperties()
17
18
 
18
19
  fillProperties: ->
20
+ # Reset all properties to hidden
21
+ @$("[data-variants-matrix-variant-property]").addClass('hidden')
22
+
19
23
  for propertyValue in @propertyValues()
20
24
  $propertyValue = @$("[data-variants-matrix-variant-property='#{ propertyValue.propertyId }']")
21
25
  $propertyValue.find('[data-property-name]').html(propertyValue.name)
@@ -23,9 +27,10 @@ class VariantsMatrix.Variant extends Vertebra.View
23
27
  $propertyValue.removeClass('hidden')
24
28
 
25
29
  remove: ->
30
+ @setDestroyed(true)
31
+
26
32
  if @persisted
27
33
  @$el.hide(0)
28
- @setDestroyed(true)
29
34
  else
30
35
  @$el.remove()
31
36
  @trigger('destroy', this)
@@ -54,15 +59,16 @@ class VariantsMatrix.Variant extends Vertebra.View
54
59
 
55
60
  onEnabledStateChanged: (e) ->
56
61
  checked = @$('[data-variants-matrix-variant-enabled]').prop('checked')
57
- @$el.toggleClass('disabled')
62
+ @$el.toggleClass('disabled', !checked)
58
63
 
59
64
  setDestroyed: (state) ->
60
- @$el.find('[data-variant-remove]').val(if state then 'true' else 'false')
65
+ @isDestroyed = state
66
+ @$el.find('[data-variant-remove]').val(if @isDestroyed then 'true' else 'false')
61
67
 
62
68
  onApplyToAllClicked: ->
63
69
  @trigger('applytoall', this)
64
70
 
65
71
  copyInputsFrom: (otherVariant) ->
66
- @$('input:visible').each (i, el) ->
72
+ @$('input:visible').each (i, el) =>
67
73
  otherValue = otherVariant.$('input:visible').eq(i).val()
68
74
  $(el).val(otherValue)
@@ -83,7 +83,6 @@ class Stall.WishListFormPopover extends Vertebra.View
83
83
  @trigger('added', resp)
84
84
 
85
85
  onCancelClicked: ->
86
- console.log 'onCancelClicked', this
87
86
  @destroy()
88
87
 
89
88
  destroy: ->
@@ -17,7 +17,7 @@ module Stall
17
17
  def refresh_associated_services!
18
18
  # Recalculate shipping fee if available for calculation to ensure
19
19
  # that the fee us always up to date when displayed to the customer
20
- shipping_fee_service.call if shipping_fee_service.available?
20
+ shipping_fee_service.call
21
21
 
22
22
  # Recalculate the credit usage amount if already used to avoid negative
23
23
  # cart totals
@@ -7,7 +7,7 @@ module Stall
7
7
  end
8
8
 
9
9
  def call
10
- return unless cart.shipment && cart.shipment.shipping_method
10
+ return reset_shipment_price unless available?
11
11
 
12
12
  update_price_for(cart.shipment, calculator) if calculator
13
13
  end
@@ -32,6 +32,12 @@ module Stall
32
32
  end
33
33
  end
34
34
 
35
+ def reset_shipment_price
36
+ return unless cart.shipment
37
+
38
+ cart.shipment.update_attributes(price: 0, eot_price: 0, vat_rate: 0)
39
+ end
40
+
35
41
  def calculator
36
42
  @calculator ||= calculator_class && calculator_class.new(cart, cart.shipment.shipping_method)
37
43
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  %span.checkbox
7
7
  %label
8
- = form.check_box :published, checked: (form.object.published? || form.object.new_record?), data: { :'variants-matrix-variant-enabled' => true }
8
+ = form.check_box :published, checked: (form.object.published? || form.object.new_record?), autocomplete: 'off', data: { :'variants-matrix-variant-enabled' => true }
9
9
  %i.checkbox-icon
10
10
 
11
11
  - all_properties.each do |property_config|
@@ -3,8 +3,8 @@
3
3
  #
4
4
  module Stall
5
5
  module RoutingMapper
6
- def mount_stall(mount_location)
7
- Stall::Routes.new(self).draw(mount_location)
6
+ def mount_stall(*args)
7
+ Stall::Routes.new(self).draw(*args)
8
8
  end
9
9
  end
10
10
  end
@@ -6,67 +6,87 @@ module Stall
6
6
  @router = router
7
7
  end
8
8
 
9
- def draw(mount_location)
9
+ # This method is called with the options passed to the `mount_stall` routes
10
+ # helper.
11
+ #
12
+ # You can pass it one of the following options to disable parts of the
13
+ # routing :
14
+ #
15
+ # - { users: false } => Disables built in devise user authentication
16
+ # - { products: false } => Disables all products related routing
17
+ # - { checkout: false } => Disables all checkout and cart related routing
18
+ #
19
+ def draw(mount_location, options = {})
10
20
  routes = self
11
21
 
22
+ users = options.fetch(:users, true)
23
+ products = options.fetch(:products, true)
24
+ checkout = options.fetch(:checkout, true)
25
+
12
26
  router.instance_eval do
13
- devise_for :users, Stall.config.devise_for_user_config
27
+ if users
28
+ devise_for :users, Stall.config.devise_for_user_config
14
29
 
15
- devise_scope :user do
16
- get '/users/omniauth/:provider/redirect' => 'stall/omniauth_callbacks#redirect', as: :user_omniauth_redirect
30
+ devise_scope :user do
31
+ get '/users/omniauth/:provider/redirect' => 'stall/omniauth_callbacks#redirect', as: :user_omniauth_redirect
32
+ end
17
33
  end
18
34
 
19
35
  scope mount_location do
20
- resources :products, only: [:index], as: :products, controller: routes.controller_for(:products)
36
+ if products
37
+ resources :products, only: [:index], as: :products, controller: routes.controller_for(:products)
21
38
 
22
- constraints ProductExistsConstraint.new do
23
- resources :products, path: '/', only: [:show], controller: routes.controller_for(:products)
24
- end
39
+ constraints ProductExistsConstraint.new do
40
+ resources :products, path: '/', only: [:show], controller: routes.controller_for(:products)
41
+ end
25
42
 
26
- constraints ProductCategoryExistsConstraint.new do
27
- resources :product_categories, path: '/', only: [:show], controller: routes.controller_for(:product_categories)
28
- end
43
+ constraints ProductCategoryExistsConstraint.new do
44
+ resources :product_categories, path: '/', only: [:show], controller: routes.controller_for(:product_categories)
45
+ end
29
46
 
30
- constraints CuratedProductListExistsConstraint.new do
31
- resources :curated_product_lists, path: '/', only: [:show], controller: routes.controller_for(:curated_product_lists) do
32
- resources :products, only: [:show], path: '/', controller: routes.controller_for(:products)
47
+ constraints CuratedProductListExistsConstraint.new do
48
+ resources :curated_product_lists, path: '/', only: [:show], controller: routes.controller_for(:curated_product_lists) do
49
+ resources :products, only: [:show], path: '/', controller: routes.controller_for(:products)
50
+ end
33
51
  end
34
- end
35
52
 
36
- constraints ManufacturerExistsConstraint.new do
37
- resources :manufacturers, path: '/', only: [:show], controller: routes.controller_for(:manufacturers) do
38
- resources :products, only: [:show], path: '/', controller: routes.controller_for(:products)
53
+ constraints ManufacturerExistsConstraint.new do
54
+ resources :manufacturers, path: '/', only: [:show], controller: routes.controller_for(:manufacturers) do
55
+ resources :products, only: [:show], path: '/', controller: routes.controller_for(:products)
56
+ end
39
57
  end
40
58
  end
41
59
 
42
- resources :carts, controller: routes.controller_for(:carts) do
43
- resources :line_items, only: [:create], controller: routes.controller_for(:cart_line_items)
44
- resource :credit, only: [:update, :destroy], controller: routes.controller_for(:cart_credits)
45
- end
60
+ if checkout
61
+ resources :carts, controller: routes.controller_for(:carts) do
62
+ resources :line_items, only: [:create], controller: routes.controller_for(:cart_line_items)
63
+ resource :credit, only: [:update, :destroy], controller: routes.controller_for(:cart_credits)
64
+ end
46
65
 
47
- resources :wish_lists, only: [:show], controller: routes.controller_for(:wish_lists) do
48
- resources :line_items, only: [:create, :destroy], controller: routes.controller_for(:wish_list_line_items)
49
- end
66
+ resources :wish_lists, only: [:show], controller: routes.controller_for(:wish_lists) do
67
+ resources :line_items, only: [:create, :destroy], controller: routes.controller_for(:wish_list_line_items)
68
+ end
50
69
 
51
- get 'checkout/:cart_key' => "#{routes.controller_for(:checkouts)}#show", as: :checkout
52
-
53
- scope 'checkout', as: :checkout do
54
- scope '(:cart_key)' do
55
- resource :step, only: [:show, :update], controller: routes.controller_for(:'checkout/steps') do
56
- post '/', action: :update, as: :update
57
- get '/process', action: :update, as: :process
58
- # Allow external URLs process steps, allowing some payment
59
- # gateways to return the user through a POST request
60
- post '/process', action: :foreign_update
61
- get 'change/:step', action: :change, as: :change
70
+ get 'checkout/:cart_key' => "#{routes.controller_for(:checkouts)}#show", as: :checkout
71
+
72
+ scope 'checkout', as: :checkout do
73
+ scope '(:cart_key)' do
74
+ resource :step, only: [:show, :update], controller: routes.controller_for(:'checkout/steps') do
75
+ post '/', action: :update, as: :update
76
+ get '/process', action: :update, as: :process
77
+ # Allow external URLs process steps, allowing some payment
78
+ # gateways to return the user through a POST request
79
+ post '/process', action: :foreign_update
80
+ get 'change/:step', action: :change, as: :change
81
+ end
62
82
  end
63
83
  end
64
- end
65
84
 
66
- scope '/:gateway' do
67
- resource :payment, only: [], controller: routes.controller_for(:payments) do
68
- member do
69
- match 'notify', action: 'notify', via: [:get, :post]
85
+ scope '/:gateway' do
86
+ resource :payment, only: [], controller: routes.controller_for(:payments) do
87
+ member do
88
+ match 'notify', action: 'notify', via: [:get, :post]
89
+ end
70
90
  end
71
91
  end
72
92
  end
@@ -1,3 +1,3 @@
1
1
  module Stall
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
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.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - vala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails