spree_core 4.1.10 → 4.2.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/base_controller.rb +1 -0
  3. data/app/helpers/spree/base_helper.rb +61 -14
  4. data/app/helpers/spree/mail_helper.rb +29 -0
  5. data/app/helpers/spree/products_helper.rb +2 -1
  6. data/app/mailers/spree/base_mailer.rb +17 -3
  7. data/app/mailers/spree/order_mailer.rb +11 -2
  8. data/app/mailers/spree/reimbursement_mailer.rb +4 -2
  9. data/app/mailers/spree/shipment_mailer.rb +4 -2
  10. data/app/models/concerns/spree/default_price.rb +2 -1
  11. data/app/models/concerns/spree/user_methods.rb +11 -5
  12. data/app/models/concerns/spree/user_payment_source.rb +1 -1
  13. data/app/models/spree/address.rb +13 -1
  14. data/app/models/spree/adjustment.rb +1 -0
  15. data/app/models/spree/app_configuration.rb +4 -0
  16. data/app/models/spree/credit_card.rb +5 -0
  17. data/app/models/spree/line_item.rb +12 -2
  18. data/app/models/spree/log_entry.rb +1 -1
  19. data/app/models/spree/option_type.rb +7 -1
  20. data/app/models/spree/order.rb +33 -7
  21. data/app/models/spree/order/address_book.rb +7 -20
  22. data/app/models/spree/order/payments.rb +10 -2
  23. data/app/models/spree/preferences/store.rb +1 -1
  24. data/app/models/spree/price.rb +26 -2
  25. data/app/models/spree/product.rb +17 -7
  26. data/app/models/spree/promotion.rb +10 -15
  27. data/app/models/spree/promotion_handler/coupon.rb +2 -3
  28. data/app/models/spree/promotion_handler/promotion_duplicator.rb +9 -3
  29. data/app/models/spree/reimbursement.rb +2 -0
  30. data/app/models/spree/shipment.rb +2 -5
  31. data/app/models/spree/stock_location.rb +13 -2
  32. data/app/models/spree/store.rb +27 -2
  33. data/app/models/spree/variant.rb +15 -2
  34. data/app/models/spree/zone.rb +4 -0
  35. data/app/presenters/spree/variant_presenter.rb +9 -1
  36. data/app/presenters/spree/variants/option_types_presenter.rb +1 -0
  37. data/app/views/layouts/spree/base_mailer.html.erb +45 -40
  38. data/app/views/spree/order_mailer/cancel_email.html.erb +19 -25
  39. data/app/views/spree/order_mailer/cancel_email.text.erb +24 -2
  40. data/app/views/spree/order_mailer/confirm_email.html.erb +18 -65
  41. data/app/views/spree/order_mailer/confirm_email.text.erb +2 -1
  42. data/app/views/spree/order_mailer/store_owner_notification_email.html.erb +23 -0
  43. data/app/views/spree/order_mailer/store_owner_notification_email.text.erb +38 -0
  44. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +53 -58
  45. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +3 -1
  46. data/app/views/spree/shared/_base_mailer_footer.html.erb +6 -14
  47. data/app/views/spree/shared/_base_mailer_header.html.erb +12 -32
  48. data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +293 -625
  49. data/app/views/spree/shared/_purchased_items_table.html.erb +60 -0
  50. data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +13 -0
  51. data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +27 -0
  52. data/app/views/spree/shared/purchased_items_table/_subtotal.html.erb +13 -0
  53. data/app/views/spree/shared/purchased_items_table/_total.html.erb +13 -0
  54. data/app/views/spree/shipment_mailer/shipped_email.html.erb +31 -36
  55. data/app/views/spree/shipment_mailer/shipped_email.text.erb +2 -1
  56. data/config/initializers/assets.rb +1 -0
  57. data/config/locales/en.yml +125 -16
  58. data/db/default/spree/countries.rb +10 -4
  59. data/db/default/spree/states.rb +42 -5
  60. data/db/default/spree/stores.rb +17 -12
  61. data/db/default/spree/zones.rb +1 -1
  62. data/db/migrate/20140309033438_create_store_from_preferences.rb +1 -1
  63. data/db/migrate/20191017121054_add_supported_currencies_to_store.rb +10 -0
  64. data/db/migrate/20200102141311_add_social_to_spree_stores.rb +3 -0
  65. data/db/migrate/20200308210757_add_default_locale_to_spree_store.rb +7 -0
  66. data/db/migrate/20200310145140_add_customer_support_email_to_spree_store.rb +7 -0
  67. data/db/migrate/20200421095017_add_compare_at_amount_to_spree_prices.rb +7 -0
  68. data/db/migrate/20200423123001_add_default_country_id_to_spree_store.rb +9 -0
  69. data/db/migrate/20200430072209_add_footer_fields_to_spree_stores.rb +8 -0
  70. data/db/migrate/20200513154939_add_show_property_to_spree_product_properties.rb +5 -0
  71. data/db/migrate/20200607161221_add_store_owner_order_notification_delivered_to_spree_orders.rb +7 -0
  72. data/db/migrate/20200607161222_add_new_order_notifications_email_to_spree_stores.rb +7 -0
  73. data/db/migrate/20200610113542_add_label_to_spree_addresses.rb +5 -0
  74. data/db/migrate/20200826075557_add_unique_index_on_taxon_id_and_product_id_to_spree_products_taxons.rb +5 -0
  75. data/db/migrate/20201006110150_add_checkout_zone_field_to_store.rb +12 -0
  76. data/db/migrate/20201012091259_add_filterable_column_to_spree_option_types.rb +6 -0
  77. data/db/migrate/20201013084504_add_seo_robots_to_spree_stores.rb +5 -0
  78. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -2
  79. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -2
  80. data/lib/generators/spree/mailers_preview/mailers_preview_generator.rb +23 -0
  81. data/lib/generators/spree/mailers_preview/templates/mailers/previews/order_preview.rb +13 -0
  82. data/lib/generators/spree/mailers_preview/templates/mailers/previews/reimbursement_preview.rb +5 -0
  83. data/lib/generators/spree/mailers_preview/templates/mailers/previews/shipment_preview.rb +5 -0
  84. data/lib/generators/spree/mailers_preview/templates/mailers/previews/user_preview.rb +11 -0
  85. data/lib/spree/core.rb +2 -0
  86. data/lib/spree/core/controller_helpers/common.rb +1 -0
  87. data/lib/spree/core/controller_helpers/currency_helpers.rb +15 -0
  88. data/lib/spree/core/controller_helpers/order.rb +9 -4
  89. data/lib/spree/core/controller_helpers/store.rb +12 -1
  90. data/lib/spree/core/importer/order.rb +9 -9
  91. data/lib/spree/core/version.rb +1 -1
  92. data/lib/spree/permitted_attributes.rb +8 -5
  93. data/lib/spree/testing_support/authorization_helpers.rb +7 -4
  94. data/lib/spree/testing_support/factories/promotion_factory.rb +29 -17
  95. data/lib/spree/testing_support/factories/store_factory.rb +11 -8
  96. data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
  97. data/lib/spree/testing_support/i18n.rb +1 -1
  98. data/spree_core.gemspec +6 -5
  99. data/vendor/assets/javascripts/cleave.js +1669 -0
  100. metadata +57 -16
  101. data/app/views/spree/order_mailer/_adjustment.html.erb +0 -8
  102. data/app/views/spree/order_mailer/_subtotal.html.erb +0 -8
  103. data/app/views/spree/order_mailer/_total.html.erb +0 -8
@@ -1,18 +1,24 @@
1
1
  require 'carmen'
2
2
 
3
+ EXCLUDED_COUNTRIES = ['AQ', 'AX', 'GS', 'UM', 'HM', 'IO', 'EH', 'BV', 'TF'].freeze
4
+
3
5
  Carmen::Country.all.each do |country|
6
+ # Skip the creation of some territories, uninhabited islands and the Antarctic.
7
+ next if EXCLUDED_COUNTRIES.include?(country.alpha_2_code)
8
+
4
9
  Spree::Country.where(
5
10
  name: country.name,
6
11
  iso3: country.alpha_3_code,
7
12
  iso: country.alpha_2_code,
8
13
  iso_name: country.name.upcase,
9
- numcode: country.numeric_code,
10
- states_required: country.subregions?
14
+ numcode: country.numeric_code
11
15
  ).first_or_create
12
16
  end
13
17
 
14
18
  Spree::Config[:default_country_id] = Spree::Country.find_by(iso: 'US').id
15
19
 
16
- # find countries that do not use postal codes (by iso) and set 'zipcode_required' to false for them.
17
-
20
+ # Find countries that do not use postal codes (by iso) and set 'zipcode_required' to false for them.
18
21
  Spree::Country.where(iso: Spree::Address::NO_ZIPCODE_ISO_CODES).update_all(zipcode_required: false)
22
+
23
+ # Find all countries that require a state (province) at checkout and set 'states_required' to true.
24
+ Spree::Country.where(iso: Spree::Address::STATES_REQUIRED).update_all(states_required: true)
@@ -1,12 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ EXCLUDED_US_STATES = ['UM', 'AS', 'MP', 'VI', 'PR', 'GU'].freeze
4
+ EXCLUDED_CN_STATES = ['HK', 'MO', 'TW'].freeze
5
+
6
+ def state_level(country, subregion)
7
+ country.states.where(
8
+ name: subregion.name,
9
+ abbr: subregion.code
10
+ ).first_or_create
11
+ end
12
+
13
+ def province_level(country, subregion)
14
+ subregion.subregions.each do |province|
15
+ country.states.where(
16
+ name: province.name,
17
+ abbr: province.code
18
+ ).first_or_create
19
+ end
20
+ end
21
+
1
22
  Spree::Country.where(states_required: true).each do |country|
2
23
  carmen_country = Carmen::Country.named(country.name)
3
24
  next unless carmen_country
4
25
 
5
26
  carmen_country.subregions.each do |subregion|
6
- country.states.where(
7
- name: subregion.name,
8
- abbr: subregion.code,
9
- country_id: country.id
10
- ).first_or_create
27
+ if carmen_country.alpha_2_code == 'US'
28
+ # Produces 50 states, one postal district (Washington DC)
29
+ # and 3 APO's as you would expect to see on any good U.S. states list.
30
+ next if EXCLUDED_US_STATES.include?(subregion.code)
31
+
32
+ state_level(country, subregion)
33
+ elsif carmen_country.alpha_2_code == 'CA' || carmen_country.alpha_2_code == 'MX'
34
+ # Force Canada and Mexico to use state-level data import from Carmen Gem
35
+ # else we pull in a subset of provinces that are not common at checkout.
36
+ state_level(country, subregion)
37
+ elsif carmen_country.alpha_2_code == 'CN'
38
+ # Removes 3 "States" from that list that are also listed as Countries,
39
+ # Hong Kong, Taiwan and Macao
40
+ next if EXCLUDED_CN_STATES.include?(subregion.code)
41
+
42
+ state_level(country, subregion)
43
+ elsif subregion.subregions?
44
+ province_level(country, subregion)
45
+ else
46
+ state_level(country, subregion)
47
+ end
11
48
  end
12
49
  end
@@ -1,15 +1,20 @@
1
- # Possibly already created by a migration.
2
- unless Spree::Store.default.persisted?
1
+ default_store = Spree::Store.default
2
+
3
+ if default_store.persisted?
4
+ default_store.update!(default_country_id: Spree::Config[:default_country_id])
5
+ else
3
6
  Spree::Store.new do |s|
4
- s.name = 'Spree Demo Site'
5
- s.code = 'spree'
6
- s.url = Rails.application.routes.default_url_options[:host] || 'demo.spreecommerce.org'
7
- s.mail_from_address = 'spree@example.com'
8
- s.default_currency = 'USD'
9
- s.seo_title = 'Spree Commerce Demo Shop'
10
- s.meta_description = 'Spree Commerce is an open source Ecommerce framework decision makers want, developers enjoy.'
11
- s.facebook = 'spreecommerce'
12
- s.twitter = 'spreecommerce'
13
- s.instagram = 'spreecommerce'
7
+ s.name = 'Spree Demo Site'
8
+ s.code = 'spree'
9
+ s.url = Rails.application.routes.default_url_options[:host] || 'demo.spreecommerce.org'
10
+ s.mail_from_address = 'no-reply@example.com'
11
+ s.customer_support_email = 'support@example.com'
12
+ s.default_currency = 'USD'
13
+ s.default_country_id = Spree::Config[:default_country_id]
14
+ s.seo_title = 'Spree Commerce Demo Shop'
15
+ s.meta_description = 'This is the new Spree UX DEMO | OVERVIEW: http://bit.ly/new-spree-ux | DOCS: http://bit.ly/spree-ux-customization-docs | CONTACT: https://spreecommerce.org/contact/'
16
+ s.facebook = 'spreecommerce'
17
+ s.twitter = 'spreecommerce'
18
+ s.instagram = 'spreecommerce'
14
19
  end.save!
15
20
  end
@@ -16,7 +16,7 @@ end
16
16
  middle_east.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
17
17
  end
18
18
 
19
- %w(AF AM AZ BH BD BT BN KH CN CX CC IO GE HK IN ID IR IQ IL JP JO KZ KW KG LA LB MO MY MV MN MM NP
19
+ %w(AF AM AZ BH BD BT BN KH CN CX CC GE HK IN ID IR IQ IL JP JO KZ KW KG LA LB MO MY MV MN MM NP
20
20
  KP OM PK PS PH QA SA SG KR LK SY TW TJ TH TR TM AE UZ VN YE).each do |name|
21
21
  asia.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!
22
22
  end
@@ -28,7 +28,7 @@ class CreateStoreFromPreferences < ActiveRecord::Migration[4.2]
28
28
  end
29
29
 
30
30
  s.meta_description = preference_store.get('spree/app_configuration/default_meta_description') do
31
- 'Spree Commerce is an open source Ecommerce framework decision makers want, developers enjoy.'
31
+ 'This is the new Spree UX DEMO | OVERVIEW: http://bit.ly/new-spree-ux | DOCS: http://bit.ly/spree-ux-customization-docs | CONTACT: https://spreecommerce.org/contact/'
32
32
  end
33
33
  s.meta_keywords = preference_store.get('spree/app_configuration/default_meta_keywords') {}
34
34
  s.seo_title = preference_store.get('spree/app_configuration/default_seo_title') do
@@ -0,0 +1,10 @@
1
+ class AddSupportedCurrenciesToStore < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :supported_currencies)
4
+ add_column :spree_stores, :supported_currencies, :string
5
+ Spree::Store.all.each do |store|
6
+ store.update_attribute(:supported_currencies, store.default_currency)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -3,5 +3,8 @@ class AddSocialToSpreeStores < ActiveRecord::Migration[6.0]
3
3
  add_column :spree_stores, :facebook, :string
4
4
  add_column :spree_stores, :twitter, :string
5
5
  add_column :spree_stores, :instagram, :string
6
+
7
+ # Fix cache issue #10381
8
+ Rails.cache.delete('default_store')
6
9
  end
7
10
  end
@@ -0,0 +1,7 @@
1
+ class AddDefaultLocaleToSpreeStore < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :default_locale)
4
+ add_column :spree_stores, :default_locale, :string
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddCustomerSupportEmailToSpreeStore < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :customer_support_email)
4
+ add_column :spree_stores, :customer_support_email, :string
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddCompareAtAmountToSpreePrices < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_prices, :compare_at_amount)
4
+ add_column :spree_prices, :compare_at_amount, :decimal, precision: 10, scale: 2
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class AddDefaultCountryIdToSpreeStore < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :default_country_id)
4
+ add_column :spree_stores, :default_country_id, :integer
5
+ Spree::Store.reset_column_information
6
+ Spree::Store.update_all(default_country_id: Spree::Config[:default_country_id])
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class AddFooterFieldsToSpreeStores < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :spree_stores, :description, :text unless column_exists?(:spree_stores, :description)
4
+ add_column :spree_stores, :address, :text unless column_exists?(:spree_stores, :address)
5
+ add_column :spree_stores, :contact_phone, :string unless column_exists?(:spree_stores, :contact_phone)
6
+ add_column :spree_stores, :contact_email, :string unless column_exists?(:spree_stores, :contact_email)
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class AddShowPropertyToSpreeProductProperties < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :spree_product_properties, :show_property, :boolean, default: true unless column_exists?(:spree_product_properties, :show_property)
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class AddStoreOwnerOrderNotificationDeliveredToSpreeOrders < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_orders, :store_owner_notification_delivered)
4
+ add_column :spree_orders, :store_owner_notification_delivered, :boolean
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddNewOrderNotificationsEmailToSpreeStores < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :new_order_notifications_email)
4
+ add_column :spree_stores, :new_order_notifications_email, :string
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddLabelToSpreeAddresses < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :spree_addresses, :label, :string unless column_exists?(:spree_addresses, :label)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddUniqueIndexOnTaxonIdAndProductIdToSpreeProductsTaxons < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_index :spree_products_taxons, [:product_id, :taxon_id], unique: true unless index_exists? :spree_products_taxons, [:product_id, :taxon_id]
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ class AddCheckoutZoneFieldToStore < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :checkout_zone_id)
4
+ add_column :spree_stores, :checkout_zone_id, :integer
5
+
6
+ Spree::Store.reset_column_information
7
+
8
+ default_zone = Spree::Zone.default_checkout_zone
9
+ Spree::Store.update_all(checkout_zone_id: default_zone.id) if default_zone.present?
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ class AddFilterableColumnToSpreeOptionTypes < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :spree_option_types, :filterable, :boolean, default: true, null: false
4
+ add_index :spree_option_types, :filterable
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddSeoRobotsToSpreeStores < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :spree_stores, :seo_robots, :string unless column_exists?(:spree_stores, :seo_robots)
4
+ end
5
+ end
@@ -4,8 +4,6 @@
4
4
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
5
  // the compiled file.
6
6
  //
7
- //= require jquery
8
- //= require jquery_ujs
9
7
  //= require spree/backend
10
8
  <% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/backend' %>
11
9
  <% filename = "spree/backend/#{ options[:lib_name].gsub("/", "_") }" %>
@@ -4,8 +4,6 @@
4
4
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
5
  // the compiled file.
6
6
  //
7
- //= require jquery
8
- //= require jquery_ujs
9
7
  //= require accounting.min
10
8
  //= require spree/frontend
11
9
  <% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/frontend' %>
@@ -0,0 +1,23 @@
1
+ require 'rails/generators'
2
+ require 'spree/core'
3
+
4
+ module Spree
5
+ class MailersPreviewGenerator < Rails::Generators::Base
6
+ desc 'Generates mailers preview for development proposes'
7
+
8
+ def self.source_paths
9
+ [
10
+ File.expand_path('templates', __dir__)
11
+ ]
12
+ end
13
+
14
+ def copy_mailers_previews
15
+ preview_path = Rails.application.config.action_mailer.preview_path || 'test/mailers/previews'
16
+
17
+ template 'mailers/previews/order_preview.rb', "#{preview_path}/order_preview.rb"
18
+ template 'mailers/previews/shipment_preview.rb', "#{preview_path}/shipment_preview.rb"
19
+ template 'mailers/previews/reimbursement_preview.rb', "#{preview_path}/reimbursement_preview.rb"
20
+ template 'mailers/previews/user_preview.rb', "#{preview_path}/user_preview.rb"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ class OrderPreview < ActionMailer::Preview
2
+ def confirm_email
3
+ Spree::OrderMailer.confirm_email(Spree::Order.complete.first)
4
+ end
5
+
6
+ def cancel_email
7
+ Spree::OrderMailer.cancel_email(Spree::Order.complete.first)
8
+ end
9
+
10
+ def store_owner_notification_email
11
+ Spree::OrderMailer.store_owner_notification_email(Spree::Order.complete.first)
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class ReimbursementPreview < ActionMailer::Preview
2
+ def reimbursement_email
3
+ Spree::ReimbursementMailer.reimbursement_email(Spree::Reimbursement.first)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ShipmentPreview < ActionMailer::Preview
2
+ def shipped_email
3
+ Spree::ShipmentMailer.shipped_email(Spree::Shipment.shipped.first)
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class UserPreview < ActionMailer::Preview
2
+ def reset_password_instructions
3
+ Spree::UserMailer.reset_password_instructions(Spree.user_class.first, 'your_token', { current_store_id: Spree::Store.default.id })
4
+ end
5
+
6
+ if Spree::Auth::Config[:confirmable]
7
+ def confirmation_instructions
8
+ Spree::UserMailer.confirmation_instructions(Spree.user_class.first, 'your_token')
9
+ end
10
+ end
11
+ end
@@ -13,6 +13,7 @@ require 'premailer/rails'
13
13
  require 'ransack'
14
14
  require 'responders'
15
15
  require 'state_machines-activerecord'
16
+ require 'active_storage_validations'
16
17
 
17
18
  # This is required because ActiveModel::Validations#invalid? conflicts with the
18
19
  # invalid state of a Payment. In the future this should be removed.
@@ -104,3 +105,4 @@ require 'spree/core/controller_helpers/order'
104
105
  require 'spree/core/controller_helpers/search'
105
106
  require 'spree/core/controller_helpers/store'
106
107
  require 'spree/core/controller_helpers/strong_parameters'
108
+ require 'spree/core/controller_helpers/currency_helpers'
@@ -44,6 +44,7 @@ module Spree
44
44
 
45
45
  def set_user_language
46
46
  locale = session[:locale]
47
+ locale = store_locale if respond_to?(:store_locale, true) && locale.blank?
47
48
  locale = config_locale if respond_to?(:config_locale, true) && locale.blank?
48
49
  locale = Rails.application.config.i18n.default_locale if locale.blank?
49
50
  locale = I18n.default_locale unless I18n.available_locales.map(&:to_s).include?(locale.to_s)
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module Core
3
+ module ControllerHelpers
4
+ module CurrencyHelpers
5
+ def self.included(receiver)
6
+ receiver.send :helper_method, :supported_currencies
7
+ end
8
+
9
+ def supported_currencies
10
+ current_store.supported_currencies_list
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -52,10 +52,15 @@ module Spree
52
52
  end
53
53
 
54
54
  def set_current_order
55
- if try_spree_current_user && current_order
56
- try_spree_current_user.orders.incomplete.where('id != ?', current_order.id).each do |order|
57
- current_order.merge!(order, try_spree_current_user)
58
- end
55
+ return unless try_spree_current_user && current_order
56
+
57
+ orders_scope = try_spree_current_user.orders.
58
+ incomplete.
59
+ where.not(id: current_order.id).
60
+ where(store_id: current_store.id)
61
+
62
+ orders_scope.each do |order|
63
+ current_order.merge!(order, try_spree_current_user)
59
64
  end
60
65
  end
61
66
 
@@ -5,13 +5,24 @@ module Spree
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
+ helper_method :supported_currencies
8
9
  helper_method :current_currency
9
10
  helper_method :current_store
10
11
  helper_method :current_price_options
11
12
  end
12
13
 
13
14
  def current_currency
14
- current_store.default_currency
15
+ if defined?(session) && session.key?(:currency) && supported_currencies.map(&:iso_code).include?(session[:currency])
16
+ session[:currency]
17
+ elsif params[:currency].present? && supported_currencies.map(&:iso_code).include?(params[:currency])
18
+ params[:currency]
19
+ else
20
+ current_store.default_currency
21
+ end
22
+ end
23
+
24
+ def supported_currencies
25
+ current_store.supported_currencies_list
15
26
  end
16
27
 
17
28
  def current_store