spree_core 4.1.13 → 4.2.0.rc4
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 +4 -4
- data/app/controllers/spree/base_controller.rb +1 -2
- data/app/finders/spree/addresses/find.rb +1 -12
- data/app/finders/spree/base_finder.rb +14 -0
- data/app/finders/spree/countries/find.rb +11 -3
- data/app/finders/spree/credit_cards/find.rb +2 -2
- data/app/finders/spree/orders/find_current.rb +1 -1
- data/app/helpers/spree/base_helper.rb +61 -20
- data/app/helpers/spree/mail_helper.rb +29 -0
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/mailers/spree/base_mailer.rb +19 -5
- data/app/mailers/spree/order_mailer.rb +13 -4
- data/app/mailers/spree/reimbursement_mailer.rb +4 -2
- data/app/mailers/spree/shipment_mailer.rb +4 -2
- data/app/models/concerns/spree/default_price.rb +3 -6
- data/app/models/concerns/spree/user_methods.rb +11 -5
- data/app/models/concerns/spree/user_payment_source.rb +1 -1
- data/app/models/spree/ability.rb +45 -34
- data/app/models/spree/address.rb +17 -1
- data/app/models/spree/adjustment.rb +1 -0
- data/app/models/spree/app_configuration.rb +4 -0
- data/app/models/spree/app_dependencies.rb +4 -2
- data/app/models/spree/base.rb +5 -0
- data/app/models/spree/credit_card.rb +5 -0
- data/app/models/spree/fulfilment_changer.rb +58 -16
- data/app/models/spree/inventory_unit.rb +2 -7
- data/app/models/spree/line_item.rb +8 -7
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_type.rb +7 -1
- data/app/models/spree/order.rb +27 -5
- data/app/models/spree/order/payments.rb +10 -2
- data/app/models/spree/payment.rb +18 -4
- data/app/models/spree/payment/processing.rb +2 -2
- data/app/models/spree/payment_method.rb +3 -3
- data/app/models/spree/preferences/store.rb +1 -1
- data/app/models/spree/price.rb +25 -6
- data/app/models/spree/product.rb +29 -9
- data/app/models/spree/promotion.rb +10 -15
- data/app/models/spree/promotion/rules/product.rb +2 -1
- data/app/models/spree/promotion/rules/user.rb +2 -1
- data/app/models/spree/promotion_handler/coupon.rb +1 -1
- data/app/models/spree/promotion_handler/promotion_duplicator.rb +9 -3
- data/app/models/spree/refund.rb +2 -2
- data/app/models/spree/reimbursement.rb +2 -0
- data/app/models/spree/return_item/eligibility_validator/default.rb +0 -2
- data/app/models/spree/return_item/eligibility_validator/{r_m_a_required.rb → rma_required.rb} +0 -0
- data/app/models/spree/shipment.rb +3 -6
- data/app/models/spree/shipping_method.rb +1 -5
- data/app/models/spree/shipping_rate.rb +2 -11
- data/app/models/spree/stock/availability_validator.rb +3 -4
- data/app/models/spree/stock_item.rb +1 -5
- data/app/models/spree/stock_location.rb +13 -2
- data/app/models/spree/store.rb +51 -2
- data/app/models/spree/store_credit.rb +1 -1
- data/app/models/spree/variant.rb +16 -10
- data/app/models/spree/zone.rb +17 -4
- data/app/presenters/spree/variant_presenter.rb +9 -1
- data/app/presenters/spree/variants/option_types_presenter.rb +1 -0
- data/app/services/spree/account/addresses/create.rb +6 -1
- data/app/services/spree/account/addresses/{base.rb → helper.rb} +1 -3
- data/app/services/spree/account/addresses/update.rb +6 -1
- data/app/services/spree/compare_line_items.rb +4 -2
- data/app/sorters/spree/base_sorter.rb +35 -0
- data/app/sorters/spree/orders/sort.rb +1 -37
- data/app/sorters/spree/products/sort.rb +9 -32
- data/app/validators/email_validator.rb +1 -1
- data/app/views/layouts/spree/base_mailer.html.erb +45 -40
- data/app/views/spree/order_mailer/cancel_email.html.erb +19 -25
- data/app/views/spree/order_mailer/cancel_email.text.erb +24 -2
- data/app/views/spree/order_mailer/confirm_email.html.erb +18 -65
- data/app/views/spree/order_mailer/confirm_email.text.erb +2 -1
- data/app/views/spree/order_mailer/store_owner_notification_email.html.erb +23 -0
- data/app/views/spree/order_mailer/store_owner_notification_email.text.erb +38 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +53 -58
- data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +3 -1
- data/app/views/spree/shared/_base_mailer_footer.html.erb +6 -14
- data/app/views/spree/shared/_base_mailer_header.html.erb +12 -32
- data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +293 -625
- data/app/views/spree/shared/_purchased_items_table.html.erb +60 -0
- data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +13 -0
- data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +27 -0
- data/app/views/spree/shared/purchased_items_table/_subtotal.html.erb +13 -0
- data/app/views/spree/shared/purchased_items_table/_total.html.erb +13 -0
- data/app/views/spree/shipment_mailer/shipped_email.html.erb +31 -36
- data/app/views/spree/shipment_mailer/shipped_email.text.erb +2 -1
- data/config/initializers/assets.rb +1 -0
- data/config/initializers/inflections.rb +3 -0
- data/config/initializers/rails61_fixes.rb +3 -0
- data/config/locales/en.yml +145 -19
- data/db/default/spree/countries.rb +10 -4
- data/db/default/spree/states.rb +42 -5
- data/db/default/spree/stores.rb +17 -12
- data/db/default/spree/zones.rb +5 -2
- data/db/migrate/20130326175857_add_stock_location_to_rma.rb +1 -1
- data/db/migrate/20140309033438_create_store_from_preferences.rb +1 -1
- data/db/migrate/20191017121054_add_supported_currencies_to_store.rb +10 -0
- data/db/migrate/20200102141311_add_social_to_spree_stores.rb +3 -0
- data/db/migrate/20200308210757_add_default_locale_to_spree_store.rb +7 -0
- data/db/migrate/20200310145140_add_customer_support_email_to_spree_store.rb +7 -0
- data/db/migrate/20200421095017_add_compare_at_amount_to_spree_prices.rb +7 -0
- data/db/migrate/20200423123001_add_default_country_id_to_spree_store.rb +9 -0
- data/db/migrate/20200430072209_add_footer_fields_to_spree_stores.rb +8 -0
- data/db/migrate/20200513154939_add_show_property_to_spree_product_properties.rb +5 -0
- data/db/migrate/20200607161221_add_store_owner_order_notification_delivered_to_spree_orders.rb +7 -0
- data/db/migrate/20200607161222_add_new_order_notifications_email_to_spree_stores.rb +7 -0
- data/db/migrate/20200610113542_add_label_to_spree_addresses.rb +5 -0
- data/db/migrate/20200826075557_add_unique_index_on_taxon_id_and_product_id_to_spree_products_taxons.rb +5 -0
- data/db/migrate/20201006110150_add_checkout_zone_field_to_store.rb +12 -0
- data/db/migrate/20201012091259_add_filterable_column_to_spree_option_types.rb +6 -0
- data/db/migrate/20201013084504_add_seo_robots_to_spree_stores.rb +5 -0
- data/db/migrate/20201127084048_add_default_country_kind_to_spree_zones.rb +5 -0
- data/db/migrate/20210112193440_remove_contact_email_from_spree_stores.rb +5 -0
- data/db/migrate/20210114182625_create_spree_payment_methods_stores.rb +10 -0
- data/db/migrate/20210114220232_migrate_data_payment_methods_stores.rb +15 -0
- data/db/migrate/20210117112551_remove_store_id_from_spree_payment_methods.rb +5 -0
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +0 -2
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -2
- data/lib/generators/spree/mailers_preview/mailers_preview_generator.rb +23 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/order_preview.rb +13 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/reimbursement_preview.rb +5 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/shipment_preview.rb +5 -0
- data/lib/generators/spree/mailers_preview/templates/mailers/previews/user_preview.rb +11 -0
- data/lib/spree/core.rb +2 -0
- data/lib/spree/core/controller_helpers/common.rb +1 -0
- data/lib/spree/core/controller_helpers/currency_helpers.rb +15 -0
- data/lib/spree/core/controller_helpers/order.rb +9 -4
- data/lib/spree/core/controller_helpers/store.rb +16 -1
- data/lib/spree/core/importer/order.rb +9 -9
- data/lib/spree/core/product_filters.rb +3 -3
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/i18n.rb +7 -21
- data/lib/spree/permitted_attributes.rb +8 -5
- data/lib/spree/service_module.rb +6 -2
- data/lib/spree/testing_support/authorization_helpers.rb +7 -4
- data/lib/spree/testing_support/capybara_config.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +29 -17
- data/lib/spree/testing_support/factories/shipment_factory.rb +7 -9
- data/lib/spree/testing_support/factories/store_factory.rb +11 -8
- data/lib/spree/testing_support/factories/zone_factory.rb +16 -13
- data/lib/spree/testing_support/i18n.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +8 -3
- data/lib/spree/testing_support/rspec_retry_config.rb +10 -0
- data/spree_core.gemspec +10 -8
- data/vendor/assets/javascripts/cleave.js +1669 -0
- metadata +105 -30
- data/app/views/spree/order_mailer/_adjustment.html.erb +0 -8
- data/app/views/spree/order_mailer/_subtotal.html.erb +0 -8
- data/app/views/spree/order_mailer/_total.html.erb +0 -8
- data/lib/spree/i18n/base.rb +0 -17
- data/lib/spree/i18n/initializer.rb +0 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
class ShippingRate < Spree::Base
|
|
3
3
|
belongs_to :shipment, class_name: 'Spree::Shipment'
|
|
4
|
-
belongs_to :tax_rate, class_name: 'Spree::TaxRate'
|
|
5
|
-
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
|
|
6
|
-
|
|
4
|
+
belongs_to :tax_rate, -> { with_deleted }, class_name: 'Spree::TaxRate'
|
|
5
|
+
belongs_to :shipping_method, -> { with_deleted }, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
|
|
7
6
|
extend Spree::DisplayMoney
|
|
8
7
|
|
|
9
8
|
money_methods :base_price, :final_price, :tax_amount
|
|
@@ -32,14 +31,6 @@ module Spree
|
|
|
32
31
|
@tax_amount ||= tax_rate&.calculator&.compute_shipping_rate(self) || BigDecimal(0)
|
|
33
32
|
end
|
|
34
33
|
|
|
35
|
-
def shipping_method
|
|
36
|
-
Spree::ShippingMethod.unscoped { super }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def tax_rate
|
|
40
|
-
Spree::TaxRate.unscoped { super }
|
|
41
|
-
end
|
|
42
|
-
|
|
43
34
|
# returns base price - any available discounts for this Shipment
|
|
44
35
|
# useful when you want to present a list of available shipping rates
|
|
45
36
|
def final_price
|
|
@@ -14,10 +14,9 @@ module Spree
|
|
|
14
14
|
display_name = variant.name.to_s
|
|
15
15
|
display_name += " (#{variant.options_text})" unless variant.options_text.blank?
|
|
16
16
|
|
|
17
|
-
line_item.errors
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
17
|
+
line_item.errors.add(:quantity,
|
|
18
|
+
:selected_quantity_not_available,
|
|
19
|
+
message: Spree.t(:selected_quantity_not_available, item: display_name.inspect))
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
private
|
|
@@ -4,7 +4,7 @@ module Spree
|
|
|
4
4
|
|
|
5
5
|
with_options inverse_of: :stock_items do
|
|
6
6
|
belongs_to :stock_location, class_name: 'Spree::StockLocation'
|
|
7
|
-
belongs_to :variant, class_name: 'Spree::Variant'
|
|
7
|
+
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
|
8
8
|
end
|
|
9
9
|
has_many :stock_movements, inverse_of: :stock_item
|
|
10
10
|
|
|
@@ -56,10 +56,6 @@ module Spree
|
|
|
56
56
|
in_stock? || backorderable?
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
def variant
|
|
60
|
-
Spree::Variant.unscoped { super }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
59
|
def reduce_count_on_hand_to_zero
|
|
64
60
|
set_count_on_hand(0) if count_on_hand > 0
|
|
65
61
|
end
|
|
@@ -106,8 +106,19 @@ module Spree
|
|
|
106
106
|
private
|
|
107
107
|
|
|
108
108
|
def create_stock_items
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
variants_scope = Spree::Variant
|
|
110
|
+
prepared_stock_items = variants_scope.ids.map do |variant_id|
|
|
111
|
+
Hash[
|
|
112
|
+
'stock_location_id', id,
|
|
113
|
+
'variant_id', variant_id,
|
|
114
|
+
'backorderable', backorderable_default,
|
|
115
|
+
'created_at', Time.current,
|
|
116
|
+
'updated_at', Time.current
|
|
117
|
+
]
|
|
118
|
+
end
|
|
119
|
+
if prepared_stock_items.any?
|
|
120
|
+
stock_items.insert_all(prepared_stock_items)
|
|
121
|
+
variants_scope.touch_all
|
|
111
122
|
end
|
|
112
123
|
end
|
|
113
124
|
|
data/app/models/spree/store.rb
CHANGED
|
@@ -2,12 +2,27 @@ module Spree
|
|
|
2
2
|
class Store < Spree::Base
|
|
3
3
|
has_many :orders, class_name: 'Spree::Order'
|
|
4
4
|
has_many :payment_methods, class_name: 'Spree::PaymentMethod'
|
|
5
|
+
belongs_to :default_country, class_name: 'Spree::Country'
|
|
6
|
+
belongs_to :checkout_zone, class_name: 'Spree::Zone'
|
|
5
7
|
|
|
6
8
|
with_options presence: true do
|
|
7
|
-
validates :name, :url, :mail_from_address
|
|
8
|
-
validates :default_currency
|
|
9
|
+
validates :name, :url, :mail_from_address, :default_currency, :code
|
|
9
10
|
end
|
|
10
11
|
|
|
12
|
+
validates :code, uniqueness: true
|
|
13
|
+
|
|
14
|
+
if !ENV['SPREE_DISABLE_DB_CONNECTION'] &&
|
|
15
|
+
connected? &&
|
|
16
|
+
table_exists? &&
|
|
17
|
+
connection.column_exists?(:spree_stores, :new_order_notifications_email)
|
|
18
|
+
validates :new_order_notifications_email, email: { allow_blank: true }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
has_one_attached :logo
|
|
22
|
+
has_one_attached :mailer_logo
|
|
23
|
+
|
|
24
|
+
validates :mailer_logo, content_type: ['image/png', 'image/jpg', 'image/jpeg']
|
|
25
|
+
|
|
11
26
|
before_save :ensure_default_exists_and_is_unique
|
|
12
27
|
before_destroy :validate_not_default
|
|
13
28
|
|
|
@@ -15,6 +30,8 @@ module Spree
|
|
|
15
30
|
|
|
16
31
|
after_commit :clear_cache
|
|
17
32
|
|
|
33
|
+
alias_attribute :contact_email, :customer_support_email
|
|
34
|
+
|
|
18
35
|
def self.current(domain = nil)
|
|
19
36
|
current_store = domain ? Store.by_url(domain).first : nil
|
|
20
37
|
current_store || Store.default
|
|
@@ -26,6 +43,38 @@ module Spree
|
|
|
26
43
|
end
|
|
27
44
|
end
|
|
28
45
|
|
|
46
|
+
def supported_currencies_list
|
|
47
|
+
(read_attribute(:supported_currencies).to_s.split(',') << default_currency).map(&:to_s).map do |code|
|
|
48
|
+
::Money::Currency.find(code.strip)
|
|
49
|
+
end.uniq.compact
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def unique_name
|
|
53
|
+
"#{name} (#{code})"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def formatted_url
|
|
57
|
+
return if url.blank?
|
|
58
|
+
|
|
59
|
+
if url.match(/http:\/\/|https:\/\//)
|
|
60
|
+
url
|
|
61
|
+
else
|
|
62
|
+
Rails.env.development? ? "http://#{url}" : "https://#{url}"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def countries_available_for_checkout
|
|
67
|
+
checkout_zone_or_default.try(:country_list) || Spree::Country.all
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def states_available_for_checkout(country)
|
|
71
|
+
checkout_zone_or_default.try(:state_list_for, country) || country.states
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def checkout_zone_or_default
|
|
75
|
+
checkout_zone || Spree::Zone.default_checkout_zone
|
|
76
|
+
end
|
|
77
|
+
|
|
29
78
|
private
|
|
30
79
|
|
|
31
80
|
def ensure_default_exists_and_is_unique
|
|
@@ -68,7 +68,7 @@ module Spree
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def validate_authorization(amount, order_currency)
|
|
71
|
-
if amount_remaining
|
|
71
|
+
if BigDecimal(amount_remaining, 3) < BigDecimal(amount, 3)
|
|
72
72
|
errors.add(:base, Spree.t('store_credit_payment_method.insufficient_funds'))
|
|
73
73
|
elsif currency != order_currency
|
|
74
74
|
errors.add(:base, Spree.t('store_credit_payment_method.currency_mismatch'))
|
data/app/models/spree/variant.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Spree
|
|
|
3
3
|
acts_as_paranoid
|
|
4
4
|
acts_as_list scope: :product
|
|
5
5
|
|
|
6
|
-
belongs_to :product, touch: true, class_name: 'Spree::Product', inverse_of: :variants
|
|
6
|
+
belongs_to :product, -> { with_deleted }, touch: true, class_name: 'Spree::Product', inverse_of: :variants
|
|
7
7
|
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
|
|
8
8
|
|
|
9
9
|
delegate :name, :name=, :description, :slug, :available_on, :shipping_category_id,
|
|
@@ -103,10 +103,19 @@ module Spree
|
|
|
103
103
|
|
|
104
104
|
self.whitelisted_ransackable_associations = %w[option_values product prices default_price]
|
|
105
105
|
self.whitelisted_ransackable_attributes = %w[weight sku]
|
|
106
|
-
self.whitelisted_ransackable_scopes = %i(product_name_or_sku_cont)
|
|
106
|
+
self.whitelisted_ransackable_scopes = %i(product_name_or_sku_cont search_by_product_name_or_sku)
|
|
107
107
|
|
|
108
108
|
def self.product_name_or_sku_cont(query)
|
|
109
|
-
joins(:product).where("#{Product.table_name}.name LIKE :query OR sku LIKE :query", query: "%#{query}%")
|
|
109
|
+
joins(:product).where("LOWER(#{Product.table_name}.name) LIKE LOWER(:query) OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def self.search_by_product_name_or_sku(query)
|
|
113
|
+
if defined?(SpreeGlobalize)
|
|
114
|
+
joins(product: :translations).where("LOWER(#{Product::Translation.table_name}.name) LIKE LOWER(:query) OR LOWER(sku) LIKE LOWER(:query)",
|
|
115
|
+
query: "%#{query}%")
|
|
116
|
+
else
|
|
117
|
+
product_name_or_sku_cont(query)
|
|
118
|
+
end
|
|
110
119
|
end
|
|
111
120
|
|
|
112
121
|
def available?
|
|
@@ -141,13 +150,6 @@ module Spree
|
|
|
141
150
|
!!deleted_at
|
|
142
151
|
end
|
|
143
152
|
|
|
144
|
-
# Product may be created with deleted_at already set,
|
|
145
|
-
# which would make AR's default finder return nil.
|
|
146
|
-
# This is a stopgap for that little problem.
|
|
147
|
-
def product
|
|
148
|
-
Spree::Product.unscoped { super }
|
|
149
|
-
end
|
|
150
|
-
|
|
151
153
|
def options=(options = {})
|
|
152
154
|
options.each do |option|
|
|
153
155
|
set_option_value(option[:name], option[:value])
|
|
@@ -223,6 +225,10 @@ module Spree
|
|
|
223
225
|
end.sum
|
|
224
226
|
end
|
|
225
227
|
|
|
228
|
+
def compare_at_price
|
|
229
|
+
price_in(cost_currency).try(:compare_at_amount)
|
|
230
|
+
end
|
|
231
|
+
|
|
226
232
|
def name_and_sku
|
|
227
233
|
"#{name} - #{sku}"
|
|
228
234
|
end
|
data/app/models/spree/zone.rb
CHANGED
|
@@ -70,6 +70,10 @@ module Spree
|
|
|
70
70
|
matches.first
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
def self.default_checkout_zone
|
|
74
|
+
find_by(name: Spree::Config[:checkout_zone])
|
|
75
|
+
end
|
|
76
|
+
|
|
73
77
|
def kind
|
|
74
78
|
if self[:kind].present?
|
|
75
79
|
self[:kind]
|
|
@@ -97,8 +101,6 @@ module Spree
|
|
|
97
101
|
zone_member.zoneable_id == address.country_id
|
|
98
102
|
when 'Spree::State'
|
|
99
103
|
zone_member.zoneable_id == address.state_id
|
|
100
|
-
else
|
|
101
|
-
false
|
|
102
104
|
end
|
|
103
105
|
end
|
|
104
106
|
end
|
|
@@ -110,8 +112,6 @@ module Spree
|
|
|
110
112
|
zoneables
|
|
111
113
|
when 'state' then
|
|
112
114
|
zoneables.collect(&:country)
|
|
113
|
-
else
|
|
114
|
-
[]
|
|
115
115
|
end.flatten.compact.uniq
|
|
116
116
|
end
|
|
117
117
|
|
|
@@ -167,6 +167,19 @@ module Spree
|
|
|
167
167
|
true
|
|
168
168
|
end
|
|
169
169
|
|
|
170
|
+
def state_list
|
|
171
|
+
case kind
|
|
172
|
+
when 'country'
|
|
173
|
+
zoneables.map(&:states)
|
|
174
|
+
when 'state'
|
|
175
|
+
zoneables
|
|
176
|
+
end.flatten.compact.uniq
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def state_list_for(country)
|
|
180
|
+
state_list.select { |state| state.country == country }
|
|
181
|
+
end
|
|
182
|
+
|
|
170
183
|
private
|
|
171
184
|
|
|
172
185
|
def remove_defunct_members
|
|
@@ -3,19 +3,23 @@ module Spree
|
|
|
3
3
|
include Rails.application.routes.url_helpers
|
|
4
4
|
include Spree::BaseHelper
|
|
5
5
|
|
|
6
|
-
attr_reader :current_currency, :current_price_options
|
|
6
|
+
attr_reader :current_currency, :current_price_options, :current_store
|
|
7
7
|
|
|
8
8
|
def initialize(opts = {})
|
|
9
9
|
@variants = opts[:variants]
|
|
10
10
|
@is_product_available_in_currency = opts[:is_product_available_in_currency]
|
|
11
11
|
@current_currency = opts[:current_currency]
|
|
12
12
|
@current_price_options = opts[:current_price_options]
|
|
13
|
+
@current_store = opts[:current_store]
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def call
|
|
16
17
|
@variants.map do |variant|
|
|
17
18
|
{
|
|
18
19
|
display_price: display_price(variant),
|
|
20
|
+
price: variant.price_in(current_currency),
|
|
21
|
+
display_compare_at_price: display_compare_at_price(variant),
|
|
22
|
+
should_display_compare_at_price: should_display_compare_at_price(variant),
|
|
19
23
|
is_product_available_in_currency: @is_product_available_in_currency,
|
|
20
24
|
backorderable: backorderable?(variant),
|
|
21
25
|
in_stock: in_stock?(variant),
|
|
@@ -71,5 +75,9 @@ module Spree
|
|
|
71
75
|
purchasable: variant.purchasable?
|
|
72
76
|
}
|
|
73
77
|
end
|
|
78
|
+
|
|
79
|
+
def should_display_compare_at_price(variant)
|
|
80
|
+
variant.compare_at_price.present? && variant.compare_at_price > variant.price
|
|
81
|
+
end
|
|
74
82
|
end
|
|
75
83
|
end
|
|
@@ -76,6 +76,7 @@ module Spree
|
|
|
76
76
|
id: option_value.id,
|
|
77
77
|
position: option_value.position,
|
|
78
78
|
presentation: option_value.presentation,
|
|
79
|
+
name: option_value.name,
|
|
79
80
|
variant_id: option_value.variants.where(id: @variant_ids).order(:position).first.id,
|
|
80
81
|
is_default: option_value == default_variant_data[:option_value]
|
|
81
82
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
module Account
|
|
3
3
|
module Addresses
|
|
4
|
-
class Create
|
|
4
|
+
class Create
|
|
5
|
+
prepend Spree::ServiceModule::Base
|
|
6
|
+
include Spree::Account::Addresses::Helper
|
|
7
|
+
|
|
8
|
+
attr_accessor :country
|
|
9
|
+
|
|
5
10
|
def call(user:, address_params:)
|
|
6
11
|
fill_country_and_state_ids(address_params)
|
|
7
12
|
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
module Account
|
|
3
3
|
module Addresses
|
|
4
|
-
class Update
|
|
4
|
+
class Update
|
|
5
|
+
prepend Spree::ServiceModule::Base
|
|
6
|
+
include Spree::Account::Addresses::Helper
|
|
7
|
+
|
|
8
|
+
attr_accessor :country
|
|
9
|
+
|
|
5
10
|
def call(address:, address_params:)
|
|
6
11
|
address_params[:country_id] ||= address.country_id
|
|
7
12
|
fill_country_and_state_ids(address_params)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# This class should be refactored
|
|
2
2
|
module Spree
|
|
3
3
|
class CompareLineItems
|
|
4
|
-
prepend Spree::ServiceModule::
|
|
4
|
+
prepend Spree::ServiceModule::Base
|
|
5
|
+
|
|
6
|
+
def call(order:, line_item:, options: {}, comparison_hooks: nil)
|
|
7
|
+
comparison_hooks ||= Rails.application.config.spree.line_item_comparison_hooks
|
|
5
8
|
|
|
6
|
-
def call(order:, line_item:, options: {}, comparison_hooks: Rails.application.config.spree.line_item_comparison_hooks)
|
|
7
9
|
legacy_part = comparison_hooks.all? do |hook|
|
|
8
10
|
order.send(hook, line_item, options)
|
|
9
11
|
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class BaseSorter
|
|
3
|
+
def initialize(scope, params = {}, allowed_sort_attributes = [])
|
|
4
|
+
@scope = scope
|
|
5
|
+
@sort = params[:sort]
|
|
6
|
+
@allowed_sort_attributes = allowed_sort_attributes
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call
|
|
10
|
+
by_param_attribute(scope)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
protected
|
|
14
|
+
|
|
15
|
+
attr_reader :scope, :collection, :sort, :allowed_sort_attributes
|
|
16
|
+
|
|
17
|
+
def by_param_attribute(scope)
|
|
18
|
+
return scope if sort_field.blank? || !allowed_sort_attributes.include?(sort_field.to_sym)
|
|
19
|
+
|
|
20
|
+
scope.order("#{sort_field}": order_direction)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def desc_order
|
|
24
|
+
@desc_order ||= String(sort)[0] == '-'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def sort_field
|
|
28
|
+
@sort_field ||= desc_order ? sort[1..-1] : sort
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def order_direction
|
|
32
|
+
desc_order ? :desc : :asc
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,42 +1,6 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
module Orders
|
|
3
|
-
class Sort
|
|
4
|
-
attr_reader :scope, :sort
|
|
5
|
-
|
|
6
|
-
def initialize(scope, params)
|
|
7
|
-
@scope = scope
|
|
8
|
-
@sort = params[:sort]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def call
|
|
12
|
-
orders = completed_at(scope)
|
|
13
|
-
|
|
14
|
-
orders
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def desc_order
|
|
20
|
-
@desc_order ||= String(sort)[0] == '-'
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def sort_field
|
|
24
|
-
@sort_field ||= desc_order ? sort[1..-1] : sort
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def order_direction
|
|
28
|
-
desc_order ? :asc : :desc
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def completed_at?
|
|
32
|
-
sort_field.eql?('completed_at')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def completed_at(orders)
|
|
36
|
-
return orders unless completed_at?
|
|
37
|
-
|
|
38
|
-
orders.order(completed_at: order_direction)
|
|
39
|
-
end
|
|
3
|
+
class Sort < ::Spree::BaseSorter
|
|
40
4
|
end
|
|
41
5
|
end
|
|
42
6
|
end
|