solidus_core 2.11.10 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -2
- data/app/assets/javascripts/spree.js.erb +0 -51
- data/app/controllers/spree/base_controller.rb +1 -1
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/helpers/spree/products_helper.rb +2 -2
- data/app/helpers/spree/store_helper.rb +0 -11
- data/app/mailers/spree/carton_mailer.rb +1 -5
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- data/app/models/concerns/spree/adjustment_source.rb +0 -15
- data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
- data/app/models/concerns/spree/default_price.rb +39 -10
- data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
- data/app/models/concerns/spree/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +10 -37
- data/app/models/concerns/spree/user_methods.rb +38 -13
- data/app/models/spree/ability.rb +0 -37
- data/app/models/spree/address/name.rb +2 -20
- data/app/models/spree/address.rb +8 -186
- data/app/models/spree/adjustment.rb +7 -33
- data/app/models/spree/base.rb +0 -53
- data/app/models/spree/calculator/flat_fee.rb +21 -0
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -7
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/country.rb +2 -7
- data/app/models/spree/credit_card.rb +1 -28
- data/app/models/spree/customer_return.rb +5 -7
- data/app/models/spree/image/active_storage_attachment.rb +2 -7
- data/app/models/spree/image/paperclip_attachment.rb +2 -2
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +6 -49
- data/app/models/spree/log_entry.rb +74 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +10 -1
- data/app/models/spree/order/number_generator.rb +7 -1
- data/app/models/spree/order.rb +82 -170
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_contents.rb +2 -1
- data/app/models/spree/order_inventory.rb +1 -1
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_promotion.rb +1 -1
- data/app/models/spree/order_shipping.rb +6 -9
- data/app/models/spree/order_taxation.rb +6 -4
- data/app/models/spree/order_updater.rb +17 -16
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment/processing.rb +58 -55
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
- data/app/models/spree/payment_method.rb +26 -110
- data/app/models/spree/price.rb +3 -3
- data/app/models/spree/product/scopes.rb +24 -33
- data/app/models/spree/product.rb +15 -42
- data/app/models/spree/product_property.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
- data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
- data/app/models/spree/promotion/rules/item_total.rb +50 -6
- data/app/models/spree/promotion/rules/product.rb +20 -8
- data/app/models/spree/promotion/rules/store.rb +4 -0
- data/app/models/spree/promotion/rules/taxon.rb +6 -15
- data/app/models/spree/promotion/rules/user.rb +4 -0
- data/app/models/spree/promotion.rb +39 -32
- data/app/models/spree/promotion_action.rb +6 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_code.rb +11 -7
- data/app/models/spree/promotion_handler/cart.rb +26 -6
- data/app/models/spree/promotion_rule.rb +5 -0
- data/app/models/spree/property.rb +1 -1
- data/app/models/spree/refund.rb +8 -52
- data/app/models/spree/reimbursement.rb +5 -43
- data/app/models/spree/reimbursement_performer.rb +2 -8
- data/app/models/spree/reimbursement_type/credit.rb +1 -4
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
- data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
- data/app/models/spree/return_authorization.rb +2 -5
- data/app/models/spree/return_item.rb +4 -24
- data/app/models/spree/shipment.rb +3 -56
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/shipping_rate_tax.rb +1 -1
- data/app/models/spree/state.rb +1 -5
- data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
- data/app/models/spree/stock/availability.rb +11 -3
- data/app/models/spree/stock/quantifier.rb +12 -8
- data/app/models/spree/stock/simple_coordinator.rb +8 -26
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +2 -8
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit.rb +14 -1
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/store_credit_prioritizer.rb +17 -0
- data/app/models/spree/tax/item_tax.rb +3 -2
- data/app/models/spree/tax/order_tax.rb +3 -1
- data/app/models/spree/tax/tax_helpers.rb +2 -2
- data/app/models/spree/tax/tax_location.rb +4 -7
- data/app/models/spree/tax_calculator/default.rb +31 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
- data/app/models/spree/tax_rate.rb +9 -27
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
- data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
- data/app/models/spree/taxon.rb +1 -12
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
- data/app/models/spree/variant/price_selector.rb +34 -4
- data/app/models/spree/variant.rb +52 -66
- data/app/models/spree/zone.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +4 -0
- data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
- data/config/i18n-tasks.yml +134 -0
- data/config/locales/en.yml +406 -263
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
- data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
- data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
- data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
- data/db/seeds.rb +4 -1
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
- data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
- data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
- data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
- data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
- data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
- data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
- data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
- data/lib/generators/solidus/install/install_generator.rb +247 -149
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
- data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
- data/lib/generators/solidus/update/update_generator.rb +112 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
- data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
- data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
- data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/spree/app_configuration.rb +134 -64
- data/lib/spree/bus.rb +20 -0
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +10 -15
- data/lib/spree/core/controller_helpers/current_host.rb +5 -3
- data/lib/spree/core/controller_helpers/order.rb +12 -32
- data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
- data/lib/spree/core/controller_helpers/pricing.rb +0 -8
- data/lib/spree/core/controller_helpers/search.rb +1 -1
- data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +54 -50
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +1 -41
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +18 -35
- data/lib/spree/core/state_machines/order.rb +2 -2
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/stock_configuration.rb +18 -0
- data/lib/spree/core/validators/email.rb +5 -3
- data/lib/spree/core/version.rb +5 -1
- data/lib/spree/core/versioned_value.rb +75 -0
- data/lib/spree/core.rb +40 -11
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/event/configuration.rb +0 -5
- data/lib/spree/event/subscriber.rb +0 -18
- data/lib/spree/event/subscriber_registry.rb +7 -7
- data/lib/spree/event.rb +1 -32
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/migrations.rb +13 -11
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permission_sets/default_customer.rb +8 -1
- data/lib/spree/permitted_attributes.rb +17 -59
- data/lib/spree/preferences/configuration.rb +84 -0
- data/lib/spree/preferences/preferable.rb +13 -0
- data/lib/spree/preferences/preferable_class_methods.rb +37 -4
- data/lib/spree/preferences/preference_differentiator.rb +29 -0
- data/lib/spree/preferences/static_model_preferences.rb +25 -10
- data/lib/spree/rails_compatibility.rb +106 -0
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/bus_helpers.rb +101 -0
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/common_rake.rb +71 -23
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/database.yml +42 -22
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +47 -34
- data/lib/spree/testing_support/factories/address_factory.rb +9 -6
- data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
- data/lib/spree/testing_support/factories/country_factory.rb +1 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +8 -5
- data/lib/spree/testing_support/factories/product_factory.rb +4 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/factories/state_factory.rb +8 -2
- data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
- data/lib/spree/testing_support/factories/user_factory.rb +6 -0
- data/lib/spree/testing_support/factory_bot.rb +2 -2
- data/lib/spree/testing_support/order_walkthrough.rb +6 -8
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/spree/testing_support/silence_deprecations.rb +9 -0
- data/lib/tasks/colorado_delivery_fee.rake +28 -0
- data/lib/tasks/payment_method.rake +29 -0
- data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
- data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
- data/solidus_core.gemspec +14 -7
- metadata +127 -78
- data/app/mailers/spree/test_mailer.rb +0 -13
- data/app/models/concerns/spree/user_payment_source.rb +0 -26
- data/app/models/spree/calculator/free_shipping.rb +0 -22
- data/app/models/spree/calculator/percent_per_item.rb +0 -51
- data/app/models/spree/calculator/price_sack.rb +0 -28
- data/app/models/spree/gateway/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- data/app/models/spree/gateway.rb +0 -14
- data/app/models/spree/order/checkout.rb +0 -244
- data/app/models/spree/order_capturing.rb +0 -50
- data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
- data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
- data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
- data/lib/generators/spree/install/install_generator.rb +0 -15
- data/lib/solidus/migrations/rename_gateways.rb +0 -41
- data/lib/spree/core/current_store.rb +0 -24
- data/lib/spree/paranoia_deprecations.rb +0 -41
- data/lib/spree/promo/environment.rb +0 -12
- data/lib/spree/testing_support/bar_ability.rb +0 -19
- data/lib/tasks/core.rake +0 -104
- data/lib/tasks/email.rake +0 -12
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
- data/lib/tasks/migrations/migrate_address_names.rake +0 -158
- data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
- data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
- data/lib/tasks/migrations/rename_gateways.rake +0 -23
- data/lib/tasks/order_capturing.rake +0 -27
- data/lib/tasks/upgrade.rake +0 -13
@@ -26,11 +26,41 @@ module Spree
|
|
26
26
|
# @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
|
27
27
|
# @return [Spree::Money, nil] The most specific price for this set of pricing options.
|
28
28
|
def price_for(price_options)
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
Spree::Deprecation.warn(
|
30
|
+
"price_for is deprecated and will be removed. The price_for method
|
31
|
+
should return a Spree::Price as described. Please use
|
32
|
+
#price_for_options and adjust your frontend code to explicitly call
|
33
|
+
&.money where required"
|
34
|
+
)
|
35
|
+
price_for_options(price_options)&.money
|
36
|
+
end
|
37
|
+
|
38
|
+
# The variant's Spree::Price record, given a set of pricing options
|
39
|
+
# @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
|
40
|
+
# @return [Spree::Price, nil] The most specific price for this set of pricing options.
|
41
|
+
def price_for_options(price_options)
|
42
|
+
sorted_prices_for(variant).detect do |price|
|
43
|
+
(price.country_iso == price_options.desired_attributes[:country_iso] ||
|
44
|
+
price.country_iso.nil?
|
32
45
|
) && price.currency == price_options.desired_attributes[:currency]
|
33
|
-
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Returns `#prices` prioritized for being considered as default price
|
52
|
+
#
|
53
|
+
# @return [Array<Spree::Price>]
|
54
|
+
def sorted_prices_for(variant)
|
55
|
+
variant.prices.select do |price|
|
56
|
+
variant.discarded? || price.kept?
|
57
|
+
end.sort_by do |price|
|
58
|
+
[
|
59
|
+
price.country_iso.nil? ? 0 : 1,
|
60
|
+
price.updated_at || Time.zone.now,
|
61
|
+
price.id || Float::INFINITY,
|
62
|
+
]
|
63
|
+
end.reverse
|
34
64
|
end
|
35
65
|
end
|
36
66
|
end
|
data/app/models/spree/variant.rb
CHANGED
@@ -23,20 +23,21 @@ module Spree
|
|
23
23
|
after_discard do
|
24
24
|
stock_items.discard_all
|
25
25
|
images.destroy_all
|
26
|
-
prices.discard_all
|
27
|
-
currently_valid_prices.discard_all
|
28
26
|
end
|
29
27
|
|
30
28
|
attr_writer :rebuild_vat_prices
|
31
29
|
include Spree::DefaultPrice
|
32
30
|
|
33
|
-
belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :
|
31
|
+
belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants_including_master, optional: false
|
34
32
|
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
|
33
|
+
belongs_to :shipping_category, class_name: "Spree::ShippingCategory", optional: true
|
35
34
|
|
36
35
|
delegate :name, :description, :slug, :available_on, :discontinue_on, :discontinued?,
|
37
|
-
:
|
36
|
+
:meta_description, :meta_keywords,
|
38
37
|
to: :product
|
39
38
|
delegate :tax_category, to: :product, prefix: true
|
39
|
+
delegate :shipping_category, :shipping_category_id,
|
40
|
+
to: :product, prefix: true
|
40
41
|
delegate :tax_rates, to: :tax_category
|
41
42
|
|
42
43
|
has_many :inventory_units, inverse_of: :variant
|
@@ -53,13 +54,7 @@ module Spree
|
|
53
54
|
has_many :images, -> { order(:position) }, as: :viewable, dependent: :destroy, class_name: "Spree::Image"
|
54
55
|
|
55
56
|
has_many :prices,
|
56
|
-
|
57
|
-
dependent: :destroy,
|
58
|
-
inverse_of: :variant,
|
59
|
-
autosave: true
|
60
|
-
|
61
|
-
has_many :currently_valid_prices,
|
62
|
-
-> { currently_valid },
|
57
|
+
-> { with_discarded },
|
63
58
|
class_name: 'Spree::Price',
|
64
59
|
dependent: :destroy,
|
65
60
|
inverse_of: :variant,
|
@@ -74,7 +69,7 @@ module Spree
|
|
74
69
|
|
75
70
|
validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
|
76
71
|
validates :price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
|
77
|
-
validates_uniqueness_of :sku, allow_blank: true, case_sensitive: true, if: :enforce_unique_sku?
|
72
|
+
validates_uniqueness_of :sku, allow_blank: true, case_sensitive: true, conditions: -> { where(deleted_at: nil) }, if: :enforce_unique_sku?
|
78
73
|
|
79
74
|
after_create :create_stock_items
|
80
75
|
after_create :set_position
|
@@ -83,7 +78,7 @@ module Spree
|
|
83
78
|
after_save :clear_in_stock_cache
|
84
79
|
after_touch :clear_in_stock_cache
|
85
80
|
|
86
|
-
|
81
|
+
after_destroy :destroy_option_values_variants
|
87
82
|
|
88
83
|
# Returns variants that are in stock. When stock locations are provided as
|
89
84
|
# a parameter, the scope is limited to variants that are in stock in the
|
@@ -118,19 +113,8 @@ module Spree
|
|
118
113
|
joins(:stock_items).where(arel_conditions.inject(:or)).distinct
|
119
114
|
end
|
120
115
|
|
121
|
-
self.
|
122
|
-
self.
|
123
|
-
|
124
|
-
# Returns variants that are not deleted and have a price in the given
|
125
|
-
# currency.
|
126
|
-
#
|
127
|
-
# @deprecated Please use the .with_prices scope instead
|
128
|
-
# @param currency [String] the currency to filter by; defaults to Spree's default
|
129
|
-
# @return [ActiveRecord::Relation]
|
130
|
-
def self.active(currency = nil)
|
131
|
-
Spree::Deprecation.warn("`Variant.active(currency)` is deprecated. Please use `Variant.with_prices(pricing_options)` instead.", caller)
|
132
|
-
joins(:prices).where(deleted_at: nil).where('spree_prices.currency' => currency || Spree::Config[:currency]).where('spree_prices.amount IS NOT NULL')
|
133
|
-
end
|
116
|
+
self.allowed_ransackable_associations = %w[option_values product prices default_price]
|
117
|
+
self.allowed_ransackable_attributes = %w[weight sku]
|
134
118
|
|
135
119
|
# Returns variants that have a price for the given pricing options
|
136
120
|
# If you have modified the pricing options class, you might want to modify this scope too.
|
@@ -161,6 +145,23 @@ module Spree
|
|
161
145
|
super || product_tax_category
|
162
146
|
end
|
163
147
|
|
148
|
+
# @return [Spree::ShippingCategory] the variant's shipping category
|
149
|
+
#
|
150
|
+
# This returns the product's shipping category if the shipping category ID on the variant is nil. It looks
|
151
|
+
# like an association, but really is an override.
|
152
|
+
#
|
153
|
+
def shipping_category
|
154
|
+
super || product_shipping_category
|
155
|
+
end
|
156
|
+
|
157
|
+
# @return [Integer] the variant's shipping category id
|
158
|
+
#
|
159
|
+
# This returns the product's shipping category if if the shipping category ID on the variant is nil.
|
160
|
+
#
|
161
|
+
def shipping_category_id
|
162
|
+
super || product_shipping_category_id
|
163
|
+
end
|
164
|
+
|
164
165
|
# Sets the cost_price for the variant.
|
165
166
|
#
|
166
167
|
# @param price [Any] the price to set
|
@@ -229,8 +230,8 @@ module Spree
|
|
229
230
|
|
230
231
|
# Assign given options hash to option values.
|
231
232
|
#
|
232
|
-
# @param options [Array] array of hashes with a name and value.
|
233
|
-
def options=(options =
|
233
|
+
# @param options [Array<Hash{name: String, value: String}>] array of hashes with a name and value.
|
234
|
+
def options=(options = [])
|
234
235
|
options.each do |option|
|
235
236
|
set_option_value(option[:name], option[:value])
|
236
237
|
end
|
@@ -287,16 +288,17 @@ module Spree
|
|
287
288
|
end
|
288
289
|
|
289
290
|
# Chooses an appropriate price for the given pricing options
|
291
|
+
# This has been deprecated in favor of #price_for_options.
|
290
292
|
#
|
291
|
-
# @see Spree::Variant::PriceSelector#
|
293
|
+
# @see Spree::Variant::PriceSelector#price_for_options
|
292
294
|
delegate :price_for, to: :price_selector
|
293
295
|
|
294
296
|
# Returns the difference in price from the master variant
|
295
297
|
def price_difference_from_master(pricing_options = Spree::Config.default_pricing_options)
|
296
|
-
master_price = product.master.
|
297
|
-
variant_price =
|
298
|
+
master_price = product.master.price_for_options(pricing_options)
|
299
|
+
variant_price = price_for_options(pricing_options)
|
298
300
|
return unless master_price && variant_price
|
299
|
-
variant_price - master_price
|
301
|
+
Spree::Money.new(variant_price.amount - master_price.amount, currency: pricing_options.currency)
|
300
302
|
end
|
301
303
|
|
302
304
|
def price_same_as_master?(pricing_options = Spree::Config.default_pricing_options)
|
@@ -304,25 +306,16 @@ module Spree
|
|
304
306
|
diff && diff.zero?
|
305
307
|
end
|
306
308
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
prices.currently_valid.find_by(currency: currency)
|
314
|
-
end
|
315
|
-
deprecate price_in: :price_for, deprecator: Spree::Deprecation
|
309
|
+
def price_for_options(price_options)
|
310
|
+
if price_selector.respond_to?(:price_for_options)
|
311
|
+
price_selector.price_for_options(price_options)
|
312
|
+
else
|
313
|
+
money = price_for(price_options)
|
314
|
+
return if money.nil?
|
316
315
|
|
317
|
-
|
318
|
-
|
319
|
-
# @deprecated Please use #price_for instead and use a money object rathern than a BigDecimal.
|
320
|
-
# @param currency (see #price)
|
321
|
-
# @return [Float] the amount in the specified currency.
|
322
|
-
def amount_in(currency)
|
323
|
-
price_in(currency).try(:amount)
|
316
|
+
Spree::Price.new(amount: money.to_d, variant: self, currency: price_options.currency)
|
317
|
+
end
|
324
318
|
end
|
325
|
-
deprecate amount_in: :price_for, deprecator: Spree::Deprecation
|
326
319
|
|
327
320
|
# Generates a friendly name and sku string.
|
328
321
|
#
|
@@ -346,16 +339,22 @@ module Spree
|
|
346
339
|
end
|
347
340
|
|
348
341
|
# @param quantity [Fixnum] how many are desired
|
342
|
+
# @param stock_location [Spree::StockLocation] Optionally restrict stock
|
343
|
+
# quantity check to a specific stock location. If unspecified it will
|
344
|
+
# check inventory in all available StockLocations.
|
349
345
|
# @return [Boolean] true if the desired quantity can be supplied
|
350
|
-
def can_supply?(quantity = 1)
|
351
|
-
Spree::Stock::Quantifier.new(self).can_supply?(quantity)
|
346
|
+
def can_supply?(quantity = 1, stock_location = nil)
|
347
|
+
Spree::Stock::Quantifier.new(self, stock_location).can_supply?(quantity)
|
352
348
|
end
|
353
349
|
|
354
350
|
# Fetches the on-hand quantity of the variant.
|
355
351
|
#
|
352
|
+
# @param stock_location [Spree::StockLocation] Optionally restrict stock
|
353
|
+
# quantity check to a specific stock location. If unspecified it will
|
354
|
+
# check inventory in all available StockLocations.
|
356
355
|
# @return [Fixnum] the number currently on-hand
|
357
|
-
def total_on_hand
|
358
|
-
Spree::Stock::Quantifier.new(self).total_on_hand
|
356
|
+
def total_on_hand(stock_location = nil)
|
357
|
+
Spree::Stock::Quantifier.new(self, stock_location).total_on_hand
|
359
358
|
end
|
360
359
|
|
361
360
|
# Shortcut method to determine if inventory tracking is enabled for this
|
@@ -367,19 +366,6 @@ module Spree
|
|
367
366
|
track_inventory? && Spree::Config.track_inventory_levels
|
368
367
|
end
|
369
368
|
|
370
|
-
# Image that can be used for the variant.
|
371
|
-
#
|
372
|
-
# Will first search for images on the variant. If it doesn't find any,
|
373
|
-
# it'll fallback to any variant image (unless +fallback+ is +false+) or to
|
374
|
-
# a new {Spree::Image}.
|
375
|
-
# @param fallback [Boolean] whether or not we should fallback to an image
|
376
|
-
# not from this variant
|
377
|
-
# @return [Spree::Image] the image to display
|
378
|
-
def display_image(fallback: true)
|
379
|
-
Spree::Deprecation.warn('Spree::Variant#display_image is DEPRECATED. Choose an image from Spree::Variant#gallery instead')
|
380
|
-
images.first || (fallback && product.variant_images.first) || Spree::Image.new
|
381
|
-
end
|
382
|
-
|
383
369
|
# Determines the variant's property values by verifying which of the product's
|
384
370
|
# variant property rules apply to itself.
|
385
371
|
#
|
data/app/models/spree/zone.rb
CHANGED
@@ -42,7 +42,7 @@ module Spree
|
|
42
42
|
alias :members :zone_members
|
43
43
|
accepts_nested_attributes_for :zone_members, allow_destroy: true, reject_if: proc { |member| member['zoneable_id'].blank? }
|
44
44
|
|
45
|
-
self.
|
45
|
+
self.allowed_ransackable_attributes = %w[name description]
|
46
46
|
|
47
47
|
# Returns all zones that contain any of the zone members of the zone passed
|
48
48
|
# in. This also includes any country zones that contain the state of the
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
# Mailing after events on a {Spree::Order}
|
5
|
+
class OrderMailerSubscriber
|
6
|
+
include Omnes::Subscriber
|
7
|
+
|
8
|
+
handle :order_finalized,
|
9
|
+
with: :send_confirmation_email,
|
10
|
+
id: :spree_order_mailer_send_confirmation_email
|
11
|
+
|
12
|
+
handle :reimbursement_reimbursed,
|
13
|
+
with: :send_reimbursement_email,
|
14
|
+
id: :spree_order_mailer_send_reimbursement_email
|
15
|
+
|
16
|
+
# Sends confirmation email to the user
|
17
|
+
#
|
18
|
+
# @param event [Omnes::UnstructuredEvent]
|
19
|
+
def send_confirmation_email(event)
|
20
|
+
order = event[:order]
|
21
|
+
unless order.confirmation_delivered?
|
22
|
+
Spree::Config.order_mailer_class.confirm_email(order).deliver_later
|
23
|
+
order.update_column(:confirmation_delivered, true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Sends reimbursement email to the user
|
28
|
+
#
|
29
|
+
# @param event [Omnes::UnstructuredEvent]
|
30
|
+
def send_reimbursement_email(event)
|
31
|
+
reimbursement = event[:reimbursement]
|
32
|
+
Spree::Config.reimbursement_mailer_class.reimbursement_email(reimbursement.id).deliver_later
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks
|
2
|
+
|
3
|
+
# The "main" locale.
|
4
|
+
base_locale: en
|
5
|
+
## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
|
6
|
+
# locales: [es, fr]
|
7
|
+
## Reporting locale, default: en. Available: en, ru.
|
8
|
+
# internal_locale: en
|
9
|
+
|
10
|
+
# Read and write translations.
|
11
|
+
data:
|
12
|
+
## Translations are read from the file system. Supported format: YAML, JSON.
|
13
|
+
## Provide a custom adapter:
|
14
|
+
# adapter: I18n::Tasks::Data::FileSystem
|
15
|
+
|
16
|
+
# Locale files or `File.find` patterns where translations are read from:
|
17
|
+
read:
|
18
|
+
## Default:
|
19
|
+
# - config/locales/%{locale}.yml
|
20
|
+
## More files:
|
21
|
+
# - config/locales/**/*.%{locale}.yml
|
22
|
+
|
23
|
+
# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
|
24
|
+
# `i18n-tasks normalize -p` will force move the keys according to these rules
|
25
|
+
write:
|
26
|
+
## For example, write devise and simple form keys to their respective files:
|
27
|
+
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
|
28
|
+
## Catch-all default:
|
29
|
+
# - config/locales/%{locale}.yml
|
30
|
+
|
31
|
+
# External locale data (e.g. gems).
|
32
|
+
# This data is not considered unused and is never written to.
|
33
|
+
external:
|
34
|
+
## Example (replace %#= with %=):
|
35
|
+
# - "<%#= %x[bundle info vagrant --path].chomp %>/templates/locales/%{locale}.yml"
|
36
|
+
|
37
|
+
## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
|
38
|
+
# router: conservative_router
|
39
|
+
|
40
|
+
yaml:
|
41
|
+
write:
|
42
|
+
# do not wrap lines at 80 characters
|
43
|
+
line_width: -1
|
44
|
+
|
45
|
+
## Pretty-print JSON:
|
46
|
+
# json:
|
47
|
+
# write:
|
48
|
+
# indent: ' '
|
49
|
+
# space: ' '
|
50
|
+
# object_nl: "\n"
|
51
|
+
# array_nl: "\n"
|
52
|
+
|
53
|
+
# Find translate calls
|
54
|
+
search:
|
55
|
+
## Paths or `File.find` patterns to search in:
|
56
|
+
# paths:
|
57
|
+
# - app/
|
58
|
+
|
59
|
+
## Root directories for relative keys resolution.
|
60
|
+
# relative_roots:
|
61
|
+
# - app/controllers
|
62
|
+
# - app/helpers
|
63
|
+
# - app/mailers
|
64
|
+
# - app/presenters
|
65
|
+
# - app/views
|
66
|
+
|
67
|
+
## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting:
|
68
|
+
## %w(*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less *.yml *.json)
|
69
|
+
exclude:
|
70
|
+
- app/assets/images
|
71
|
+
- app/assets/fonts
|
72
|
+
- app/assets/videos
|
73
|
+
|
74
|
+
## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
|
75
|
+
## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
|
76
|
+
# only: ["*.rb", "*.html.slim"]
|
77
|
+
|
78
|
+
## If `strict` is `false`, guess usages such as t("categories.#{category}.title"). The default is `true`.
|
79
|
+
# strict: true
|
80
|
+
|
81
|
+
## Multiple scanners can be used. Their results are merged.
|
82
|
+
## The options specified above are passed down to each scanner. Per-scanner options can be specified as well.
|
83
|
+
## See this example of a custom scanner: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example
|
84
|
+
|
85
|
+
## Translation Services
|
86
|
+
# translation:
|
87
|
+
# # Google Translate
|
88
|
+
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
|
89
|
+
# google_translate_api_key: "AbC-dEf5"
|
90
|
+
# # DeepL Pro Translate
|
91
|
+
# # Get an API key and subscription at https://www.deepl.com/pro to use DeepL Pro
|
92
|
+
# deepl_api_key: "48E92789-57A3-466A-9959-1A1A1A1A1A1A"
|
93
|
+
|
94
|
+
## Do not consider these keys missing:
|
95
|
+
ignore_missing:
|
96
|
+
- 'number.currency.format.separator'
|
97
|
+
# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}'
|
98
|
+
# - '{devise,simple_form}.*'
|
99
|
+
|
100
|
+
## Consider these keys used:
|
101
|
+
#ignore_unused:
|
102
|
+
# - 'activerecord.attributes.*'
|
103
|
+
# - '{devise,kaminari,will_paginate}.*'
|
104
|
+
# - 'simple_form.{yes,no}'
|
105
|
+
# - 'simple_form.{placeholders,hints,labels}.*'
|
106
|
+
# - 'simple_form.{error_notification,required}.:'
|
107
|
+
|
108
|
+
## Exclude these keys from the `i18n-tasks eq-base' report:
|
109
|
+
# ignore_eq_base:
|
110
|
+
# all:
|
111
|
+
# - common.ok
|
112
|
+
# fr,es:
|
113
|
+
# - common.brand
|
114
|
+
|
115
|
+
## Exclude these keys from the `i18n-tasks check-consistent-interpolations` report:
|
116
|
+
# ignore_inconsistent_interpolations:
|
117
|
+
# - 'activerecord.attributes.*'
|
118
|
+
|
119
|
+
## Ignore these keys completely:
|
120
|
+
# ignore:
|
121
|
+
# - kaminari.*
|
122
|
+
|
123
|
+
## Sometimes, it isn't possible for i18n-tasks to match the key correctly,
|
124
|
+
## e.g. in case of a relative key defined in a helper method.
|
125
|
+
## In these cases you can use the built-in PatternMapper to map patterns to keys, e.g.:
|
126
|
+
#
|
127
|
+
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
|
128
|
+
# only: %w(*.html.haml *.html.slim),
|
129
|
+
# patterns: [['= title\b', '.page_title']] %>
|
130
|
+
#
|
131
|
+
# The PatternMapper can also match key literals via a special %{key} interpolation, e.g.:
|
132
|
+
#
|
133
|
+
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
|
134
|
+
# patterns: [['\bSpree\.t[( ]\s*%{key}', 'spree.%{key}']] %>
|