spree_frontend 4.2.0 → 4.2.4

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
  SHA256:
3
- metadata.gz: b202f99393b22f252f8c79ce9dbb68bdb3886df0095db558b7aeb54649d7442a
4
- data.tar.gz: b6bf3f9b0dff2c97e90773fe58113d589711bb830ce921211b447b73b1a24631
3
+ metadata.gz: e5617e23cebabecc619b763e288fb37fe0f55b3eae53a0a224c4d90f8f6267b7
4
+ data.tar.gz: 5c6f46207edac502a335fd545f0b0a38f91ad4cc32c7444d2c3907e5c7579875
5
5
  SHA512:
6
- metadata.gz: 6ca9c497131e513e80a043e7dae75e7e3dacff782fc0d4111fa1c4883c68db5db58f351a734065accb375855cb3e05ec3d080453777865cf5a51d81507fa103a
7
- data.tar.gz: 459e4adc0b271ee193f9e99c7bec8b044d45ffc94449e897fcdc8ca1d1a2c696f13bc7adda5be001e59eaf5f3fdd07647c8a6b45890b1539990a5633393205da
6
+ metadata.gz: 071d2ae392116772ee81430b2a9206576cf2e1d2caef2793b872992ada9257461f0f0b5206813ba8a188889f7cce97487d2c777047a532a000534a74e87170d8
7
+ data.tar.gz: efca049f831a75eb370d29d09d1944d1fd644cae397f7a00aab511e31dfaf9ef05876c0cf150327f74532c7b951cbf770abab127b8f237e3a51bf41ee328ffa7
@@ -44,11 +44,11 @@
44
44
 
45
45
  Spree.routes.api_tokens = Spree.pathFor('api_tokens')
46
46
  Spree.routes.ensure_cart = Spree.pathFor('ensure_cart')
47
- Spree.routes.api_v2_storefront_cart_apply_coupon_code = Spree.pathFor('api/v2/storefront/cart/apply_coupon_code')
48
- Spree.routes.api_v2_storefront_cart_remove_coupon_code = Spree.pathFor('api/v2/storefront/cart/remove_coupon_code')
49
- Spree.routes.product = function(id) { return Spree.pathFor('products/' + id) }
50
- Spree.routes.product_related = function(id) { return Spree.pathFor('products/' + id + '/related') }
51
- Spree.routes.product_carousel = function (taxonId) { return Spree.pathFor('product_carousel/' + taxonId) }
47
+ Spree.routes.api_v2_storefront_cart_apply_coupon_code = Spree.localizedPathFor('api/v2/storefront/cart/apply_coupon_code')
48
+ Spree.routes.api_v2_storefront_cart_remove_coupon_code = function(couponCode) { return Spree.localizedPathFor('api/v2/storefront/cart/remove_coupon_code/' + couponCode) }
49
+ Spree.routes.product = function(id) { return Spree.localizedPathFor('products/' + id) }
50
+ Spree.routes.product_related = function(id) { return Spree.localizedPathFor('products/' + id + '/related') }
51
+ Spree.routes.product_carousel = function (taxonId) { return Spree.localizedPathFor('product_carousel/' + taxonId) }
52
52
  Spree.routes.set_locale = function(locale) { return Spree.pathFor('locale/set?switch_to_locale=' + locale) }
53
53
  Spree.routes.set_currency = function(currency) { return Spree.pathFor('currency/set?switch_to_currency=' + currency) }
54
54
 
@@ -57,3 +57,26 @@ Spree.showProgressBar = function () {
57
57
  Turbolinks.controller.adapter.progressBar.setValue(0)
58
58
  Turbolinks.controller.adapter.progressBar.show()
59
59
  }
60
+
61
+ Spree.clearCache = function () {
62
+ if (!Turbolinks.supported) { return }
63
+
64
+ Turbolinks.clearCache()
65
+ }
66
+
67
+ Spree.setCurrency = function (currency) {
68
+ Spree.clearCache()
69
+
70
+ var params = (new URL(window.location)).searchParams
71
+ if (currency === SPREE_DEFAULT_CURRENCY) {
72
+ params.delete('currency')
73
+ } else {
74
+ params.set('currency', currency)
75
+ }
76
+ var queryString = params.toString()
77
+ if (queryString !== '') { queryString = '?' + queryString }
78
+
79
+ SPREE_CURRENCY = currency
80
+
81
+ Turbolinks.visit(window.location.pathname + queryString, { action: 'replace' })
82
+ }
@@ -49,7 +49,7 @@ CouponManager.prototype.sendRequest = function () {
49
49
  return $.ajax({
50
50
  async: false,
51
51
  method: 'PATCH',
52
- url: Spree.routes.api_v2_storefront_cart_apply_coupon_code + '?locale=' + SPREE_LOCALE,
52
+ url: Spree.routes.api_v2_storefront_cart_apply_coupon_code,
53
53
  dataType: 'json',
54
54
  headers: {
55
55
  'X-Spree-Order-Token': SpreeAPI.orderToken
@@ -74,7 +74,7 @@ CouponManager.prototype.sendRemoveRequest = function () {
74
74
  return $.ajax({
75
75
  async: false,
76
76
  method: 'DELETE',
77
- url: Spree.routes.api_v2_storefront_cart_remove_coupon_code + '/' + this.couponCode + '?locale=' + SPREE_LOCALE,
77
+ url: Spree.routes.api_v2_storefront_cart_remove_coupon_code(this.couponCode),
78
78
  dataType: 'json',
79
79
  headers: {
80
80
  'X-Spree-Order-Token': SpreeAPI.orderToken
@@ -1,11 +1,43 @@
1
- Spree.ready(function ($) {
2
- var currencySelect = $('#currency-select select')
1
+ document.addEventListener('turbolinks:load', function(event) {
2
+ // this condition checks if this is the first initial load of turbolinks application
3
+ if (!event.data.timing.visitStart) {
4
+ var currencySelect = document.querySelectorAll('select[name=switch_to_currency]')
3
5
 
4
- if (currencySelect.length) {
5
- currencySelect.on('change', function () {
6
- currencySelect.attr('disabled')
7
- Spree.showProgressBar()
8
- window.location = Spree.routes.set_currency(this.value)
9
- })
6
+ if (currencySelect.length) {
7
+ currencySelect.forEach(function (element) {
8
+ element.addEventListener('change', function () {
9
+ Spree.showProgressBar()
10
+ var newCurrency = this.value
11
+
12
+ // we need to make AJAX call here to the backend to set currency in session
13
+ fetch(Spree.routes.set_currency(newCurrency), {
14
+ method: 'GET'
15
+ }).then(function (response) {
16
+ switch (response.status) {
17
+ case 200:
18
+ Spree.setCurrency(newCurrency)
19
+ document.getElementById('internationalization-options-desktop').classList.remove('show')
20
+ break
21
+ }
22
+ })
23
+ })
24
+ })
25
+ }
26
+ }
27
+ })
28
+
29
+ // fix back button issue with different currency set
30
+ // invalidate page if cached page has different currency then the current one
31
+ document.addEventListener('turbolinks:load', function(event) {
32
+ if (SPREE_CURRENCY === SPREE_DEFAULT_CURRENCY) {
33
+ var regexAnyCurrency = new RegExp('currency=')
34
+ if (event.data.url.match(regexAnyCurrency) && !event.data.url.match(SPREE_CURRENCY)) {
35
+ Spree.setCurrency(SPREE_CURRENCY)
36
+ }
37
+ } else {
38
+ var regex = new RegExp('currency=' + SPREE_CURRENCY)
39
+ if (!event.data.url.match(regex)) {
40
+ Spree.setCurrency(SPREE_CURRENCY)
41
+ }
10
42
  }
11
43
  })
@@ -1,11 +1,13 @@
1
- Spree.ready(function ($) {
2
- var localeSelect = $('#locale-select select')
1
+ document.addEventListener('turbolinks:load', function () {
2
+ var localeSelect = document.querySelectorAll('select[name=switch_to_locale]')
3
3
 
4
4
  if (localeSelect.length) {
5
- localeSelect.on('change', function () {
6
- localeSelect.attr('disabled')
7
- Spree.showProgressBar()
8
- window.location = Spree.routes.set_locale(this.value)
5
+ localeSelect.forEach(function (element) {
6
+ element.addEventListener('change', function () {
7
+ Spree.clearCache()
8
+ Spree.showProgressBar()
9
+ this.form.submit()
10
+ })
9
11
  })
10
12
  }
11
13
  })
@@ -9,9 +9,7 @@ module Spree
9
9
  private
10
10
 
11
11
  def default_url_options
12
- return super if locale_param.nil?
13
-
14
- super.merge(locale: locale_param)
12
+ super.merge(locale: locale_param, currency: currency_param)
15
13
  end
16
14
 
17
15
  def redirect_to_default_locale
@@ -7,7 +7,11 @@ module Spree
7
7
  current_order&.update(currency: new_currency)
8
8
  session[:currency] = new_currency
9
9
  end
10
- redirect_back_or_default(root_path(currency: new_currency))
10
+
11
+ respond_to do |format|
12
+ format.html { redirect_back fallback_location: spree.root_path(currency: new_currency) }
13
+ format.json { head :ok }
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -41,8 +41,10 @@ module Spree
41
41
  [
42
42
  current_store,
43
43
  current_currency,
44
- I18n.locale
45
- ]
44
+ I18n.locale,
45
+ try_spree_current_user.present?,
46
+ try_spree_current_user.try(:has_spree_role?, 'admin')
47
+ ].compact
46
48
  end
47
49
 
48
50
  def store_last_modified
@@ -1,5 +1,5 @@
1
1
  <% if defined?(should_render_currency_dropdown?) && should_render_currency_dropdown? %>
2
- <%= form_tag spree.set_currency_path, method: :get, class: 'px-4 py-3 w-100', id: 'currency-select' do %>
2
+ <%= form_tag spree.set_currency_path, method: :get, class: 'px-4 py-3 w-100 currency-select' do %>
3
3
  <div class="form-group">
4
4
  <label for="switch_to_currency" class="dropdown-header text-center">
5
5
  <%= Spree.t(:choose_currency) %>
@@ -8,9 +8,6 @@
8
8
  <%= stylesheet_link_tag 'spree/frontend/all', media: 'screen', 'data-turbolinks-track': 'reload' %>
9
9
  <%= csrf_meta_tags %>
10
10
  <%= render 'spree/shared/paths' %>
11
- <script>
12
- var SPREE_LOCALE = '<%= I18n.locale %>'
13
- var SPREE_CURRENCY = '<%= current_currency %>'
14
- </script>
11
+ <%= render 'spree/shared/locale_and_currency' %>
15
12
  <%= javascript_include_tag 'spree/frontend/all', defer: true, 'data-turbolinks-track': 'reload' %>
16
13
  <%= yield :head %>
@@ -0,0 +1,6 @@
1
+ <script>
2
+ var SPREE_LOCALE = '<%= I18n.locale %>'
3
+ var SPREE_CURRENCY = '<%= current_currency %>'
4
+ var SPREE_DEFAULT_CURRENCY = '<%= current_store.default_currency %>'
5
+ var SPREE_DEFAULT_LOCALE = '<%= current_store.default_locale %>'
6
+ </script>
@@ -1,5 +1,5 @@
1
1
  <% if should_render_locale_dropdown? %>
2
- <%= form_tag spree.set_locale_path, method: :get, class: 'px-4 py-3 w-100', id: 'locale-select' do %>
2
+ <%= form_tag spree.set_locale_path, method: :get, class: 'px-4 py-3 w-100 locale-select' do %>
3
3
  <div class="form-group">
4
4
  <label for="switch_to_locale" class="dropdown-header text-center">
5
5
  <%= Spree.t('i18n.language') %>
@@ -34,7 +34,7 @@
34
34
  </div>
35
35
  <div class="row pt-5 justify-content-center align-items-center product-added-modal-product">
36
36
  <div class="col-4 col-sm-2 product-added-modal-product-image-container">
37
- <img class="product-added-modal-product-image-container-image" src="data:," alt="<%= @product.name %>">
37
+ <img class="product-added-modal-product-image-container-image" src="data:," alt="<%= @product&.name %>">
38
38
  </div>
39
39
  <div class="col-8 col-sm-6 col-lg-4 py-1 product-added-modal-product-details">
40
40
  <div class="product-added-modal-product-details-name"></div>
@@ -48,7 +48,7 @@
48
48
  <div class="row pb-4 justify-content-center">
49
49
  <div class="col-12 col-lg-8">
50
50
  <%= link_to spree.checkout_path, class: 'btn btn-primary w-100 font-weight-bold text-uppercase product-added-modal-button', method: :get do %>
51
- <%= Spree.t('pdp.checkout') %>
51
+ <%= Spree.t(:checkout) %>
52
52
  <% end %>
53
53
  </div>
54
54
  </div>
@@ -10,5 +10,5 @@ CanonicalRails.setup do |config|
10
10
  # Parameter spamming can cause index dilution by creating seemingly different URLs with identical or near-identical content.
11
11
  # Unless whitelisted, these parameters will be omitted
12
12
 
13
- config.allowed_parameters = [:keywords, :page, :search, :taxon]
13
+ config.allowed_parameters = [:keywords, :search, :taxon]
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_frontend
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-25 00:00:00.000000000 Z
12
+ date: 2021-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_api
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 4.2.0
20
+ version: 4.2.4
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 4.2.0
27
+ version: 4.2.4
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: spree_core
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 4.2.0
34
+ version: 4.2.4
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: 4.2.0
41
+ version: 4.2.4
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bootstrap
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -739,6 +739,7 @@ files:
739
739
  - app/views/spree/shared/_line_item.html.erb
740
740
  - app/views/spree/shared/_link_to_account.html.erb
741
741
  - app/views/spree/shared/_link_to_cart.html.erb
742
+ - app/views/spree/shared/_locale_and_currency.html.erb
742
743
  - app/views/spree/shared/_locale_dropdown.html.erb
743
744
  - app/views/spree/shared/_login.html.erb
744
745
  - app/views/spree/shared/_main_nav_bar.html.erb
@@ -792,9 +793,9 @@ licenses:
792
793
  - BSD-3-Clause
793
794
  metadata:
794
795
  bug_tracker_uri: https://github.com/spree/spree/issues
795
- changelog_uri: https://github.com/spree/spree/releases/tag/v4.2.0
796
+ changelog_uri: https://github.com/spree/spree/releases/tag/v4.2.4
796
797
  documentation_uri: https://guides.spreecommerce.org/
797
- source_code_uri: https://github.com/spree/spree/tree/v4.2.0
798
+ source_code_uri: https://github.com/spree/spree/tree/v4.2.4
798
799
  post_install_message:
799
800
  rdoc_options: []
800
801
  require_paths: