spree_core 4.2.0.beta → 4.2.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/base_controller.rb +2 -3
- data/app/controllers/spree/errors_controller.rb +11 -0
- data/app/finders/spree/addresses/find.rb +6 -0
- 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 +2 -2
- data/app/finders/spree/products/find.rb +12 -1
- data/app/helpers/spree/base_helper.rb +38 -18
- data/app/helpers/spree/locale_helper.rb +19 -0
- data/app/helpers/spree/mail_helper.rb +12 -7
- data/app/helpers/spree/products_helper.rb +39 -13
- data/app/mailers/spree/base_mailer.rb +5 -5
- data/app/mailers/spree/order_mailer.rb +3 -3
- data/app/mailers/spree/reimbursement_mailer.rb +1 -1
- data/app/mailers/spree/shipment_mailer.rb +1 -1
- data/app/models/concerns/spree/default_price.rb +1 -5
- data/app/models/concerns/spree/user_methods.rb +2 -2
- 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 +2 -3
- data/app/models/spree/app_dependencies.rb +10 -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/image.rb +14 -14
- data/app/models/spree/inventory_unit.rb +2 -7
- data/app/models/spree/line_item.rb +9 -16
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_type.rb +2 -0
- data/app/models/spree/order.rb +12 -6
- data/app/models/spree/order/address_book.rb +7 -20
- 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 +1 -6
- data/app/models/spree/product.rb +24 -17
- data/app/models/spree/promotion.rb +10 -15
- data/app/models/spree/promotion/rules/option_value.rb +1 -1
- 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 -2
- data/app/models/spree/promotion_handler/promotion_duplicator.rb +9 -3
- data/app/models/spree/refund.rb +2 -2
- 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 +1 -1
- 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/store.rb +45 -1
- data/app/models/spree/store_credit.rb +1 -1
- data/app/models/spree/variant.rb +8 -15
- data/app/models/spree/zone.rb +17 -4
- data/app/presenters/spree/variant_presenter.rb +4 -6
- data/app/services/spree/account/addresses/create.rb +23 -0
- data/app/services/spree/account/addresses/helper.rb +37 -0
- data/app/services/spree/account/addresses/update.rb +23 -0
- data/app/services/spree/cart/estimate_shipping_rates.rb +1 -1
- data/app/services/spree/checkout/update.rb +13 -2
- 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/spree/errors/forbidden.html.erb +0 -0
- data/app/views/spree/errors/unauthorized.html.erb +0 -0
- data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +0 -2
- data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +1 -1
- data/config/initializers/inflections.rb +3 -0
- data/config/initializers/rails61_fixes.rb +3 -0
- data/config/locales/en.yml +42 -63
- data/config/routes.rb +2 -1
- data/db/default/spree/countries.rb +10 -4
- data/db/default/spree/states.rb +42 -5
- data/db/default/spree/stores.rb +18 -13
- data/db/default/spree/zones.rb +5 -2
- data/db/migrate/20130326175857_add_stock_location_to_rma.rb +1 -1
- data/db/migrate/20200610113542_add_label_to_spree_addresses.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/db/migrate/20210120142527_ensure_default_locale_in_spree_stores.rb +5 -0
- data/lib/generators/spree/install/templates/config/spree_storefront.yml +9 -9
- data/lib/spree/core.rb +3 -1
- data/lib/spree/core/controller_helpers/auth.rb +3 -1
- data/lib/spree/core/controller_helpers/common.rb +6 -8
- data/lib/spree/core/controller_helpers/currency.rb +45 -0
- data/lib/spree/core/controller_helpers/locale.rb +57 -0
- data/lib/spree/core/controller_helpers/order.rb +9 -4
- data/lib/spree/core/controller_helpers/store.rb +4 -16
- 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 +3 -3
- data/lib/spree/service_module.rb +6 -2
- 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/stock_location_factory.rb +2 -2
- 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 +7 -5
- metadata +90 -28
- data/lib/spree/core/controller_helpers/currency_helpers.rb +0 -15
- data/lib/spree/i18n/base.rb +0 -17
- data/lib/spree/i18n/initializer.rb +0 -1
@@ -25,7 +25,6 @@ module Spree
|
|
25
25
|
|
26
26
|
def remove(coupon_code)
|
27
27
|
promotion = order.promotions.with_coupon_code(coupon_code)
|
28
|
-
|
29
28
|
if promotion.present?
|
30
29
|
# Order promotion has to be destroyed before line item removing
|
31
30
|
order.order_promotions.where(promotion_id: promotion.id).destroy_all
|
@@ -76,7 +75,7 @@ module Spree
|
|
76
75
|
line_item = order.find_line_item_by_variant(item.variant)
|
77
76
|
next if line_item.blank?
|
78
77
|
|
79
|
-
Spree::Dependencies.cart_remove_item_service(order: order, item: item.variant, quantity: item.quantity)
|
78
|
+
Spree::Dependencies.cart_remove_item_service.constantize.call(order: order, item: item.variant, quantity: item.quantity)
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
@@ -1,15 +1,16 @@
|
|
1
1
|
module Spree
|
2
2
|
module PromotionHandler
|
3
3
|
class PromotionDuplicator
|
4
|
-
def initialize(promotion)
|
4
|
+
def initialize(promotion, random_string: nil)
|
5
5
|
@promotion = promotion
|
6
|
+
@random_string = random_string || generate_random_string(4)
|
6
7
|
end
|
7
8
|
|
8
9
|
def duplicate
|
9
10
|
@new_promotion = @promotion.dup
|
10
|
-
@new_promotion.path = "#{@promotion.path}
|
11
|
+
@new_promotion.path = "#{@promotion.path}_#{@random_string}"
|
11
12
|
@new_promotion.name = "New #{@promotion.name}"
|
12
|
-
@new_promotion.code = "#{@promotion.code}
|
13
|
+
@new_promotion.code = "#{@promotion.code}_#{@random_string}"
|
13
14
|
|
14
15
|
ActiveRecord::Base.transaction do
|
15
16
|
@new_promotion.save
|
@@ -33,6 +34,11 @@ module Spree
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
def generate_random_string(number)
|
38
|
+
charset = Array('A'..'Z') + Array('a'..'z')
|
39
|
+
Array.new(number) { charset.sample }.join
|
40
|
+
end
|
41
|
+
|
36
42
|
def copy_actions
|
37
43
|
@promotion.promotion_actions.each do |action|
|
38
44
|
new_action = action.dup
|
data/app/models/spree/refund.rb
CHANGED
@@ -61,14 +61,14 @@ module Spree
|
|
61
61
|
end
|
62
62
|
|
63
63
|
unless response.success?
|
64
|
-
logger.error(Spree.t(:gateway_error) + " #{response.to_yaml}")
|
64
|
+
Rails.logger.error(Spree.t(:gateway_error) + " #{response.to_yaml}")
|
65
65
|
text = response.params['message'] || response.params['response_reason_text'] || response.message
|
66
66
|
raise Core::GatewayError, text
|
67
67
|
end
|
68
68
|
|
69
69
|
response
|
70
70
|
rescue ActiveMerchant::ConnectionError => e
|
71
|
-
logger.error(Spree.t(:gateway_error) + " #{e.inspect}")
|
71
|
+
Rails.logger.error(Spree.t(:gateway_error) + " #{e.inspect}")
|
72
72
|
raise Core::GatewayError, Spree.t(:unable_to_connect_to_gateway)
|
73
73
|
end
|
74
74
|
|
data/app/models/spree/return_item/eligibility_validator/{r_m_a_required.rb → rma_required.rb}
RENAMED
File without changes
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
foreign_key: 'shipping_method_id'
|
20
20
|
has_many :zones, through: :shipping_method_zones, class_name: 'Spree::Zone'
|
21
21
|
|
22
|
-
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
|
22
|
+
belongs_to :tax_category, -> { with_deleted }, class_name: 'Spree::TaxCategory', optional: true
|
23
23
|
|
24
24
|
validates :name, :display_on, presence: true
|
25
25
|
|
@@ -44,10 +44,6 @@ module Spree
|
|
44
44
|
select { |c| c.to_s.constantize < Spree::ShippingCalculator }
|
45
45
|
end
|
46
46
|
|
47
|
-
def tax_category
|
48
|
-
Spree::TaxCategory.unscoped { super }
|
49
|
-
end
|
50
|
-
|
51
47
|
def available_to_display?(display_filter)
|
52
48
|
(frontend? && display_filter == DISPLAY_ON_FRONT_END) ||
|
53
49
|
(backend? && display_filter == DISPLAY_ON_BACK_END)
|
@@ -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
|
data/app/models/spree/store.rb
CHANGED
@@ -3,6 +3,7 @@ module Spree
|
|
3
3
|
has_many :orders, class_name: 'Spree::Order'
|
4
4
|
has_many :payment_methods, class_name: 'Spree::PaymentMethod'
|
5
5
|
belongs_to :default_country, class_name: 'Spree::Country'
|
6
|
+
belongs_to :checkout_zone, class_name: 'Spree::Zone'
|
6
7
|
|
7
8
|
with_options presence: true do
|
8
9
|
validates :name, :url, :mail_from_address, :default_currency, :code
|
@@ -18,6 +19,9 @@ module Spree
|
|
18
19
|
end
|
19
20
|
|
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']
|
21
25
|
|
22
26
|
before_save :ensure_default_exists_and_is_unique
|
23
27
|
before_destroy :validate_not_default
|
@@ -26,6 +30,8 @@ module Spree
|
|
26
30
|
|
27
31
|
after_commit :clear_cache
|
28
32
|
|
33
|
+
alias_attribute :contact_email, :customer_support_email
|
34
|
+
|
29
35
|
def self.current(domain = nil)
|
30
36
|
current_store = domain ? Store.by_url(domain).first : nil
|
31
37
|
current_store || Store.default
|
@@ -37,12 +43,49 @@ module Spree
|
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
46
|
+
def self.available_locales
|
47
|
+
Rails.cache.fetch('stores_available_locales') do
|
48
|
+
Spree::Store.all.map(&:supported_locales_list).flatten.uniq
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
def supported_currencies_list
|
41
|
-
(read_attribute(:supported_currencies).to_s.split(',') << default_currency).map(&:to_s).map do |code|
|
53
|
+
@supported_currencies_list ||= (read_attribute(:supported_currencies).to_s.split(',') << default_currency).map(&:to_s).map do |code|
|
42
54
|
::Money::Currency.find(code.strip)
|
43
55
|
end.uniq.compact
|
44
56
|
end
|
45
57
|
|
58
|
+
def supported_locales_list
|
59
|
+
# TODO: add support of multiple supported languages to a single Store
|
60
|
+
@supported_locales_list ||= [default_locale].compact.uniq
|
61
|
+
end
|
62
|
+
|
63
|
+
def unique_name
|
64
|
+
@unique_name ||= "#{name} (#{code})"
|
65
|
+
end
|
66
|
+
|
67
|
+
def formatted_url
|
68
|
+
return if url.blank?
|
69
|
+
|
70
|
+
@formatted_url ||= if url.match(/http:\/\/|https:\/\//)
|
71
|
+
url
|
72
|
+
else
|
73
|
+
Rails.env.development? ? "http://#{url}" : "https://#{url}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def countries_available_for_checkout
|
78
|
+
@countries_available_for_checkout ||= checkout_zone_or_default.try(:country_list) || Spree::Country.all
|
79
|
+
end
|
80
|
+
|
81
|
+
def states_available_for_checkout(country)
|
82
|
+
checkout_zone_or_default.try(:state_list_for, country) || country.states
|
83
|
+
end
|
84
|
+
|
85
|
+
def checkout_zone_or_default
|
86
|
+
@checkout_zone_or_default ||= checkout_zone || Spree::Zone.default_checkout_zone
|
87
|
+
end
|
88
|
+
|
46
89
|
private
|
47
90
|
|
48
91
|
def ensure_default_exists_and_is_unique
|
@@ -62,6 +105,7 @@ module Spree
|
|
62
105
|
|
63
106
|
def clear_cache
|
64
107
|
Rails.cache.delete('default_store')
|
108
|
+
Rails.cache.delete('stores_available_locales')
|
65
109
|
end
|
66
110
|
end
|
67
111
|
end
|
@@ -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,
|
@@ -123,15 +123,15 @@ module Spree
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def tax_category
|
126
|
-
if self[:tax_category_id].nil?
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
126
|
+
@tax_category ||= if self[:tax_category_id].nil?
|
127
|
+
product.tax_category
|
128
|
+
else
|
129
|
+
Spree::TaxCategory.find(self[:tax_category_id])
|
130
|
+
end
|
131
131
|
end
|
132
132
|
|
133
133
|
def options_text
|
134
|
-
Spree::Variants::OptionsPresenter.new(self).to_sentence
|
134
|
+
@options_text ||= Spree::Variants::OptionsPresenter.new(self).to_sentence
|
135
135
|
end
|
136
136
|
|
137
137
|
# Default to master name
|
@@ -150,13 +150,6 @@ module Spree
|
|
150
150
|
!!deleted_at
|
151
151
|
end
|
152
152
|
|
153
|
-
# Product may be created with deleted_at already set,
|
154
|
-
# which would make AR's default finder return nil.
|
155
|
-
# This is a stopgap for that little problem.
|
156
|
-
def product
|
157
|
-
Spree::Product.unscoped { super }
|
158
|
-
end
|
159
|
-
|
160
153
|
def options=(options = {})
|
161
154
|
options.each do |option|
|
162
155
|
set_option_value(option[:name], option[:value])
|
@@ -233,7 +226,7 @@ module Spree
|
|
233
226
|
end
|
234
227
|
|
235
228
|
def compare_at_price
|
236
|
-
price_in(cost_currency).try(:compare_at_amount)
|
229
|
+
@compare_at_price ||= price_in(cost_currency).try(:compare_at_amount)
|
237
230
|
end
|
238
231
|
|
239
232
|
def name_and_sku
|
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
|
@@ -2,14 +2,16 @@ module Spree
|
|
2
2
|
class VariantPresenter
|
3
3
|
include Rails.application.routes.url_helpers
|
4
4
|
include Spree::BaseHelper
|
5
|
+
include Spree::ProductsHelper
|
5
6
|
|
6
|
-
attr_reader :current_currency, :current_price_options
|
7
|
+
attr_reader :current_currency, :current_price_options, :current_store
|
7
8
|
|
8
9
|
def initialize(opts = {})
|
9
10
|
@variants = opts[:variants]
|
10
11
|
@is_product_available_in_currency = opts[:is_product_available_in_currency]
|
11
12
|
@current_currency = opts[:current_currency]
|
12
13
|
@current_price_options = opts[:current_price_options]
|
14
|
+
@current_store = opts[:current_store]
|
13
15
|
end
|
14
16
|
|
15
17
|
def call
|
@@ -18,7 +20,7 @@ module Spree
|
|
18
20
|
display_price: display_price(variant),
|
19
21
|
price: variant.price_in(current_currency),
|
20
22
|
display_compare_at_price: display_compare_at_price(variant),
|
21
|
-
should_display_compare_at_price: should_display_compare_at_price(variant),
|
23
|
+
should_display_compare_at_price: should_display_compare_at_price?(variant),
|
22
24
|
is_product_available_in_currency: @is_product_available_in_currency,
|
23
25
|
backorderable: backorderable?(variant),
|
24
26
|
in_stock: in_stock?(variant),
|
@@ -74,9 +76,5 @@ module Spree
|
|
74
76
|
purchasable: variant.purchasable?
|
75
77
|
}
|
76
78
|
end
|
77
|
-
|
78
|
-
def should_display_compare_at_price(variant)
|
79
|
-
variant.compare_at_price.present? && variant.compare_at_price > variant.price
|
80
|
-
end
|
81
79
|
end
|
82
80
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spree
|
2
|
+
module Account
|
3
|
+
module Addresses
|
4
|
+
class Create
|
5
|
+
prepend Spree::ServiceModule::Base
|
6
|
+
include Spree::Account::Addresses::Helper
|
7
|
+
|
8
|
+
attr_accessor :country
|
9
|
+
|
10
|
+
def call(user:, address_params:)
|
11
|
+
fill_country_and_state_ids(address_params)
|
12
|
+
|
13
|
+
address = user.addresses.new(address_params)
|
14
|
+
if address.save
|
15
|
+
success(address)
|
16
|
+
else
|
17
|
+
failure(address)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Spree
|
2
|
+
module Account
|
3
|
+
module Addresses
|
4
|
+
module Helper
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_accessor :country
|
8
|
+
|
9
|
+
def fill_country_and_state_ids(params)
|
10
|
+
replace_country_iso_with_id(params)
|
11
|
+
fill_state_id(params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def replace_country_iso_with_id(params)
|
15
|
+
iso = params[:country_iso]
|
16
|
+
return params unless iso.present?
|
17
|
+
|
18
|
+
country = Spree::Country.by_iso(iso)
|
19
|
+
params[:country_id] = country&.id
|
20
|
+
params.delete(:country_iso)
|
21
|
+
params
|
22
|
+
end
|
23
|
+
|
24
|
+
def fill_state_id(params)
|
25
|
+
state_name = params[:state_name]
|
26
|
+
return params unless state_name.present?
|
27
|
+
|
28
|
+
country ||= Spree::Country.find(params[:country_id]) if params[:country_id].present?
|
29
|
+
return params unless country
|
30
|
+
|
31
|
+
params[:state_id] = country.states.find_by(name: state_name)&.id
|
32
|
+
params
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|