spree_frontend 4.2.0 → 4.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
  SHA256:
3
- metadata.gz: b202f99393b22f252f8c79ce9dbb68bdb3886df0095db558b7aeb54649d7442a
4
- data.tar.gz: b6bf3f9b0dff2c97e90773fe58113d589711bb830ce921211b447b73b1a24631
3
+ metadata.gz: eb44ce8a344e6b78adcb87064ed90e0ec7f3f02cfc474dda6d16d41e1077e733
4
+ data.tar.gz: 7febb328e551e0396decabb7e357c626c39ab573d71895dc6e55d115bb9d6e7c
5
5
  SHA512:
6
- metadata.gz: 6ca9c497131e513e80a043e7dae75e7e3dacff782fc0d4111fa1c4883c68db5db58f351a734065accb375855cb3e05ec3d080453777865cf5a51d81507fa103a
7
- data.tar.gz: 459e4adc0b271ee193f9e99c7bec8b044d45ffc94449e897fcdc8ca1d1a2c696f13bc7adda5be001e59eaf5f3fdd07647c8a6b45890b1539990a5633393205da
6
+ metadata.gz: cd5453aa3218dbbedadfc27b7f3958b33560f0d8ec33d03aee58b1d22b3c255c6cded27469e2a1b6194fb73fd0e5c658545aeb90e6003dbc6355694457ec46be
7
+ data.tar.gz: 67815113708206d6f6bab183804c7005d8ccaa707005ff6392d38eebd4b9462951833d8507da6617011a6e4052c208c67bc3be49039f25c5b5cad9e3077b9c31
@@ -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
@@ -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') %>
@@ -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.1
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-03-05 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.1
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.1
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.1
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.1
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.1
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.1
798
799
  post_install_message:
799
800
  rdoc_options: []
800
801
  require_paths:
@@ -811,7 +812,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
811
812
  version: '0'
812
813
  requirements:
813
814
  - none
814
- rubygems_version: 3.1.4
815
+ rubygems_version: 3.2.3
815
816
  signing_key:
816
817
  specification_version: 4
817
818
  summary: Frontend e-commerce functionality for the Spree project.