solidus_core 2.9.6 → 2.10.3
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/helpers/spree/base_helper.rb +4 -4
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
- data/app/models/concerns/spree/user_address_book.rb +2 -2
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/spree/address.rb +13 -17
- data/app/models/spree/adjustment.rb +20 -9
- data/app/models/spree/asset.rb +1 -1
- data/app/models/spree/base.rb +0 -2
- data/app/models/spree/calculator.rb +1 -1
- data/app/models/spree/calculator/price_sack.rb +1 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
- data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
- data/app/models/spree/calculator/tiered_percent.rb +6 -6
- data/app/models/spree/carton.rb +3 -3
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/credit_card.rb +4 -4
- data/app/models/spree/customer_return.rb +1 -1
- data/app/models/spree/image/paperclip_attachment.rb +1 -1
- data/app/models/spree/inventory_unit.rb +5 -23
- data/app/models/spree/line_item.rb +4 -4
- data/app/models/spree/line_item_action.rb +2 -2
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/option_values_variant.rb +2 -2
- data/app/models/spree/order.rb +11 -27
- data/app/models/spree/order/checkout.rb +1 -1
- data/app/models/spree/order/payments.rb +2 -2
- data/app/models/spree/order_cancellations.rb +1 -1
- data/app/models/spree/order_capturing.rb +2 -2
- data/app/models/spree/order_contents.rb +2 -2
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_promotion.rb +3 -3
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/order_taxation.rb +3 -3
- data/app/models/spree/payment.rb +8 -45
- data/app/models/spree/payment/processing.rb +3 -3
- data/app/models/spree/payment_capture_event.rb +1 -1
- data/app/models/spree/payment_method.rb +5 -2
- data/app/models/spree/payment_method/bogus_credit_card.rb +1 -1
- data/app/models/spree/payment_source.rb +1 -1
- data/app/models/spree/price.rb +2 -2
- data/app/models/spree/product.rb +5 -5
- data/app/models/spree/product/scopes.rb +218 -210
- data/app/models/spree/product_option_type.rb +2 -2
- data/app/models/spree/product_promotion_rule.rb +2 -2
- data/app/models/spree/product_property.rb +2 -2
- data/app/models/spree/promotion.rb +28 -13
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/option_value.rb +2 -2
- data/app/models/spree/promotion/rules/product.rb +3 -3
- data/app/models/spree/promotion_action.rb +2 -2
- data/app/models/spree/promotion_chooser.rb +2 -2
- data/app/models/spree/promotion_code.rb +11 -10
- data/app/models/spree/promotion_code/batch_builder.rb +3 -3
- data/app/models/spree/promotion_code_batch.rb +1 -1
- data/app/models/spree/promotion_rule.rb +2 -2
- data/app/models/spree/promotion_rule_role.rb +2 -2
- data/app/models/spree/promotion_rule_store.rb +2 -2
- data/app/models/spree/promotion_rule_taxon.rb +2 -2
- data/app/models/spree/promotion_rule_user.rb +2 -2
- data/app/models/spree/refund.rb +5 -5
- data/app/models/spree/reimbursement.rb +5 -13
- data/app/models/spree/reimbursement/credit.rb +2 -2
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
- data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
- data/app/models/spree/return_authorization.rb +4 -10
- data/app/models/spree/return_item.rb +13 -52
- data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
- data/app/models/spree/role_user.rb +2 -2
- data/app/models/spree/shipment.rb +7 -41
- data/app/models/spree/shipping_calculator.rb +0 -4
- data/app/models/spree/shipping_manifest.rb +3 -3
- data/app/models/spree/shipping_method.rb +2 -2
- data/app/models/spree/shipping_method_category.rb +2 -2
- data/app/models/spree/shipping_method_stock_location.rb +2 -2
- data/app/models/spree/shipping_method_zone.rb +2 -2
- data/app/models/spree/shipping_rate.rb +2 -2
- data/app/models/spree/shipping_rate_tax.rb +2 -2
- data/app/models/spree/state.rb +2 -2
- data/app/models/spree/state_change.rb +2 -2
- data/app/models/spree/stock/differentiator.rb +1 -1
- data/app/models/spree/stock/package.rb +1 -1
- data/app/models/spree/stock_item.rb +3 -3
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/stock_quantities.rb +13 -12
- data/app/models/spree/store_credit.rb +8 -8
- data/app/models/spree/store_credit_event.rb +3 -3
- data/app/models/spree/store_payment_method.rb +2 -2
- data/app/models/spree/store_shipping_method.rb +2 -2
- data/app/models/spree/tax_calculator/default.rb +0 -4
- data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
- data/app/models/spree/tax_rate.rb +5 -1
- data/app/models/spree/tax_rate_tax_category.rb +2 -2
- data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
- data/app/models/spree/unit_cancel.rb +5 -2
- data/app/models/spree/user_address.rb +2 -2
- data/app/models/spree/user_last_url_storer.rb +46 -0
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
- data/app/models/spree/user_stock_location.rb +2 -2
- data/app/models/spree/variant.rb +10 -10
- data/app/models/spree/variant/scopes.rb +37 -29
- data/app/models/spree/variant_property_rule.rb +1 -1
- data/app/models/spree/variant_property_rule_condition.rb +2 -2
- data/app/models/spree/variant_property_rule_value.rb +2 -2
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/wallet_payment_source.rb +2 -2
- data/app/models/spree/zone.rb +1 -1
- data/app/models/spree/zone_member.rb +2 -2
- data/config/initializers/inflections.rb +5 -0
- data/config/initializers/money.rb +2 -0
- data/config/locales/en.yml +34 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +2 -0
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
- data/lib/spree/app_configuration.rb +18 -3
- data/lib/spree/core.rb +12 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -13
- data/lib/spree/core/engine.rb +2 -2
- data/lib/spree/core/importer/order.rb +28 -28
- data/lib/spree/core/importer/product.rb +2 -2
- data/lib/spree/core/product_filters.rb +15 -15
- data/lib/spree/core/role_configuration.rb +2 -2
- data/lib/spree/core/search/variant.rb +1 -1
- data/lib/spree/core/state_machines.rb +78 -0
- data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
- data/lib/spree/core/state_machines/payment.rb +61 -0
- data/lib/spree/core/state_machines/reimbursement.rb +33 -0
- data/lib/spree/core/state_machines/return_authorization.rb +32 -0
- data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
- data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
- data/lib/spree/core/state_machines/shipment.rb +58 -0
- data/lib/spree/core/stock_configuration.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -8
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/money.rb +2 -2
- data/lib/spree/permission_sets/default_customer.rb +1 -1
- data/lib/spree/permission_sets/user_management.rb +3 -0
- data/lib/spree/permitted_attributes.rb +3 -3
- data/lib/spree/preferences/static_model_preferences.rb +2 -2
- data/lib/spree/testing_support/dummy_app.rb +4 -1
- data/lib/spree/testing_support/dummy_app/rake_tasks.rb +6 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
- data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +4 -1
- data/solidus_core.gemspec +6 -6
- data/spec/lib/search/base_spec.rb +5 -1
- data/spec/lib/search/variant_spec.rb +1 -1
- data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
- data/spec/lib/spree/core/validators/email_spec.rb +18 -18
- data/spec/lib/spree/event_spec.rb +15 -3
- data/spec/models/spree/ability_spec.rb +1 -1
- data/spec/models/spree/address_spec.rb +23 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
- data/spec/models/spree/carton_spec.rb +10 -2
- data/spec/models/spree/classification_spec.rb +21 -9
- data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
- data/spec/models/spree/concerns/user_methods_spec.rb +5 -4
- data/spec/models/spree/credit_card_spec.rb +2 -2
- data/spec/models/spree/customer_return_spec.rb +1 -1
- data/spec/models/spree/order/checkout_spec.rb +1 -1
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +5 -5
- data/spec/models/spree/order/payment_spec.rb +1 -1
- data/spec/models/spree/order_contents_spec.rb +1 -1
- data/spec/models/spree/order_inventory_spec.rb +3 -3
- data/spec/models/spree/order_merger_spec.rb +3 -3
- data/spec/models/spree/order_shipping_spec.rb +1 -1
- data/spec/models/spree/order_spec.rb +14 -21
- data/spec/models/spree/order_updater_spec.rb +4 -3
- data/spec/models/spree/payment_create_spec.rb +6 -16
- data/spec/models/spree/payment_spec.rb +12 -12
- data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
- data/spec/models/spree/preference_spec.rb +4 -4
- data/spec/models/spree/preferences/preferable_spec.rb +3 -3
- data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/nth_order_spec.rb +2 -2
- data/spec/models/spree/promotion_rule_spec.rb +6 -6
- data/spec/models/spree/promotion_spec.rb +71 -54
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +3 -3
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
- data/spec/models/spree/return_item_spec.rb +11 -11
- data/spec/models/spree/returns_calculator_spec.rb +2 -2
- data/spec/models/spree/shipment_spec.rb +6 -6
- data/spec/models/spree/shipping_calculator_spec.rb +1 -13
- data/spec/models/spree/shipping_method_spec.rb +32 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
- data/spec/models/spree/stock/differentiator_spec.rb +2 -2
- data/spec/models/spree/stock/estimator_spec.rb +3 -3
- data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +4 -4
- data/spec/models/spree/stock/package_spec.rb +28 -28
- data/spec/models/spree/stock/quantifier_spec.rb +2 -2
- data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
- data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
- data/spec/models/spree/stock_quantities_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +8 -8
- data/spec/models/spree/tax_category_spec.rb +1 -1
- data/spec/models/spree/tax_rate_spec.rb +1 -0
- data/spec/models/spree/taxon_spec.rb +2 -2
- data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
- data/spec/models/spree/unit_cancel_spec.rb +5 -0
- data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
- data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
- data/spec/models/spree/user_spec.rb +3 -3
- metadata +49 -43
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -148
- data/spec/models/spree/order/updating_spec.rb +0 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08330f4d1ddbd2bddacc80a0dcb54b9feed5eea413c7d52510c7464e478de07e'
|
|
4
|
+
data.tar.gz: 76a7a91ca6d8e416894d4b4c4b09601683f53f8686c638fdcf92823e991dbcd7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f29f33c694ad957f5d43a4da1bfe640342289cfb62c21fe4d2af9a08d91b02a5ce14a3e6b5acaaedef33141e4c593f8ddc0426230ac327da1251236e83e0803
|
|
7
|
+
data.tar.gz: 95a104a06300c1bb231bfd20e1b6220829b7b6e46afc96aa59c708869d48c3b9685c622e1e209fd70e8b0abee604e1c34efccd99ea0775e1ae993874aaf696d9
|
|
@@ -79,16 +79,16 @@ module Spree
|
|
|
79
79
|
|
|
80
80
|
crumbs << [t('spree.products'), products_path]
|
|
81
81
|
if taxon
|
|
82
|
-
crumbs += taxon.ancestors.collect { |
|
|
82
|
+
crumbs += taxon.ancestors.collect { |ancestor| [ancestor.name, spree.nested_taxons_path(ancestor.permalink)] } unless taxon.ancestors.empty?
|
|
83
83
|
crumbs << [taxon.name, spree.nested_taxons_path(taxon.permalink)]
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
separator = raw(separator)
|
|
87
87
|
|
|
88
|
-
items = crumbs.each_with_index.collect do |crumb,
|
|
88
|
+
items = crumbs.each_with_index.collect do |crumb, index|
|
|
89
89
|
content_tag(:li, itemprop: 'itemListElement', itemscope: '', itemtype: 'https://schema.org/ListItem') do
|
|
90
90
|
link_to(crumb.last, itemprop: 'item') do
|
|
91
|
-
content_tag(:span, crumb.first, itemprop: 'name') + tag('meta', { itemprop: 'position', content: (
|
|
91
|
+
content_tag(:span, crumb.first, itemprop: 'name') + tag('meta', { itemprop: 'position', content: (index + 1).to_s }, false, false)
|
|
92
92
|
end + (crumb == crumbs.last ? '' : separator)
|
|
93
93
|
end
|
|
94
94
|
end
|
|
@@ -122,7 +122,7 @@ module Spree
|
|
|
122
122
|
countries.collect do |country|
|
|
123
123
|
country.name = country_names.fetch(country.iso, country.name)
|
|
124
124
|
country
|
|
125
|
-
end.sort_by { |
|
|
125
|
+
end.sort_by { |country| country.name.parameterize }
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
def seo_url(taxon)
|
|
@@ -36,7 +36,8 @@ module Spree
|
|
|
36
36
|
def variant_full_price(variant)
|
|
37
37
|
return if variant.product.variants
|
|
38
38
|
.with_prices(current_pricing_options)
|
|
39
|
-
.all? { |
|
|
39
|
+
.all? { |variant_with_prices| variant_with_prices.price_same_as_master?(current_pricing_options) }
|
|
40
|
+
|
|
40
41
|
variant.price_for(current_pricing_options).to_html
|
|
41
42
|
end
|
|
42
43
|
|
|
@@ -14,13 +14,13 @@ module Spree
|
|
|
14
14
|
.promotion_code_batch_finished(promotion_code_batch)
|
|
15
15
|
.deliver_now
|
|
16
16
|
end
|
|
17
|
-
rescue StandardError =>
|
|
17
|
+
rescue StandardError => error
|
|
18
18
|
if promotion_code_batch.email?
|
|
19
19
|
Spree::Config.promotion_code_batch_mailer_class
|
|
20
20
|
.promotion_code_batch_errored(promotion_code_batch)
|
|
21
21
|
.deliver_now
|
|
22
22
|
end
|
|
23
|
-
raise
|
|
23
|
+
raise error
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -25,7 +25,7 @@ module Spree
|
|
|
25
25
|
has_many :addresses, through: :user_addresses
|
|
26
26
|
|
|
27
27
|
# bill_address is only minimally used now, but we can't get rid of it without a major version release
|
|
28
|
-
belongs_to :bill_address, class_name: 'Spree::Address'
|
|
28
|
+
belongs_to :bill_address, class_name: 'Spree::Address', optional: true
|
|
29
29
|
|
|
30
30
|
has_one :default_user_address, ->{ default }, class_name: 'Spree::UserAddress', foreign_key: 'user_id'
|
|
31
31
|
has_one :default_address, through: :default_user_address, source: :address
|
|
@@ -130,7 +130,7 @@ module Spree
|
|
|
130
130
|
def remove_from_address_book(address_id)
|
|
131
131
|
user_address = user_addresses.find_by(address_id: address_id)
|
|
132
132
|
if user_address
|
|
133
|
-
user_address.
|
|
133
|
+
user_address.update(archived: true, default: false)
|
|
134
134
|
else
|
|
135
135
|
false
|
|
136
136
|
end
|
|
@@ -73,8 +73,8 @@ module Spree
|
|
|
73
73
|
deprecate total_available_store_credit: :available_store_credit_total, deprecator: Spree::Deprecation
|
|
74
74
|
|
|
75
75
|
def available_store_credit_total(currency:)
|
|
76
|
-
store_credits.
|
|
77
|
-
select { |
|
|
76
|
+
store_credits.to_a.
|
|
77
|
+
select { |credit| credit.currency == currency }.
|
|
78
78
|
sum(&:amount_remaining)
|
|
79
79
|
end
|
|
80
80
|
|
data/app/models/spree/address.rb
CHANGED
|
@@ -8,8 +8,8 @@ module Spree
|
|
|
8
8
|
class Address < Spree::Base
|
|
9
9
|
extend ActiveModel::ForbiddenAttributesProtection
|
|
10
10
|
|
|
11
|
-
belongs_to :country, class_name: "Spree::Country"
|
|
12
|
-
belongs_to :state, class_name: "Spree::State"
|
|
11
|
+
belongs_to :country, class_name: "Spree::Country", optional: true
|
|
12
|
+
belongs_to :state, class_name: "Spree::State", optional: true
|
|
13
13
|
|
|
14
14
|
validates :firstname, :address1, :city, :country_id, presence: true
|
|
15
15
|
validates :zipcode, presence: true, if: :require_zipcode?
|
|
@@ -30,8 +30,9 @@ module Spree
|
|
|
30
30
|
where(value_attributes(attributes))
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
# @return [Address] an address with default attributes
|
|
34
|
+
def self.build_default(*args, &block)
|
|
35
|
+
where(country: Spree::Country.default).build(*args, &block)
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
# @return [Address] an equal address already in the database or a newly created one
|
|
@@ -58,21 +59,16 @@ module Spree
|
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
# @return [Hash] hash of attributes contributing to value equality with optional merge
|
|
61
|
-
def self.value_attributes(base_attributes, merge_attributes =
|
|
62
|
-
|
|
63
|
-
base = base_attributes.dup
|
|
64
|
-
|
|
65
|
-
base.stringify_keys!
|
|
66
|
-
|
|
67
|
-
if merge_attributes
|
|
68
|
-
base.merge!(merge_attributes.stringify_keys)
|
|
69
|
-
end
|
|
62
|
+
def self.value_attributes(base_attributes, merge_attributes = {})
|
|
63
|
+
base = base_attributes.stringify_keys.merge(merge_attributes.stringify_keys)
|
|
70
64
|
|
|
71
65
|
# TODO: Deprecate these aliased attributes
|
|
72
|
-
base['firstname'] = base
|
|
73
|
-
base['lastname'] = base
|
|
66
|
+
base['firstname'] = base['first_name'] if base.key?('first_name')
|
|
67
|
+
base['lastname'] = base['last_name'] if base.key?('last_name')
|
|
68
|
+
|
|
69
|
+
excluded_attributes = DB_ONLY_ATTRS + %w(first_name last_name)
|
|
74
70
|
|
|
75
|
-
base.except
|
|
71
|
+
base.except(*excluded_attributes)
|
|
76
72
|
end
|
|
77
73
|
|
|
78
74
|
# @return [Hash] hash of attributes contributing to value equality
|
|
@@ -121,7 +117,7 @@ module Spree
|
|
|
121
117
|
# @deprecated Do not use this
|
|
122
118
|
def empty?
|
|
123
119
|
Spree::Deprecation.warn("Address#empty? is deprecated.", caller)
|
|
124
|
-
attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_,
|
|
120
|
+
attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_, value| value.nil? }
|
|
125
121
|
end
|
|
126
122
|
|
|
127
123
|
# This exists because the default Object#blank?, checks empty? if it is
|
|
@@ -16,11 +16,11 @@ module Spree
|
|
|
16
16
|
# order's adjustment total. This allows an adjustment to be preserved if
|
|
17
17
|
# it becomes ineligible so it might be reinstated.
|
|
18
18
|
class Adjustment < Spree::Base
|
|
19
|
-
belongs_to :adjustable, polymorphic: true, touch: true
|
|
20
|
-
belongs_to :source, polymorphic: true
|
|
21
|
-
belongs_to :order, class_name: 'Spree::Order', inverse_of: :all_adjustments
|
|
22
|
-
belongs_to :promotion_code, class_name: 'Spree::PromotionCode'
|
|
23
|
-
belongs_to :adjustment_reason, class_name: 'Spree::AdjustmentReason', inverse_of: :adjustments
|
|
19
|
+
belongs_to :adjustable, polymorphic: true, touch: true, optional: true
|
|
20
|
+
belongs_to :source, polymorphic: true, optional: true
|
|
21
|
+
belongs_to :order, class_name: 'Spree::Order', inverse_of: :all_adjustments, optional: true
|
|
22
|
+
belongs_to :promotion_code, class_name: 'Spree::PromotionCode', optional: true
|
|
23
|
+
belongs_to :adjustment_reason, class_name: 'Spree::AdjustmentReason', inverse_of: :adjustments, optional: true
|
|
24
24
|
|
|
25
25
|
validates :adjustable, presence: true
|
|
26
26
|
validates :order, presence: true
|
|
@@ -56,20 +56,31 @@ module Spree
|
|
|
56
56
|
extend DisplayMoney
|
|
57
57
|
money_methods :amount
|
|
58
58
|
|
|
59
|
+
# Returns Adjustments of completed Orders.
|
|
60
|
+
#
|
|
61
|
+
# @param excluded_orders [Array<Spree::Order>] Orders to exclude from query
|
|
62
|
+
# @return [ActiveRecord::Relation] Scoped Adjustments
|
|
63
|
+
def self.in_completed_orders(excluded_orders: [])
|
|
64
|
+
joins(:order).
|
|
65
|
+
merge(Spree::Order.complete).
|
|
66
|
+
where.not(spree_orders: { id: excluded_orders }).
|
|
67
|
+
distinct
|
|
68
|
+
end
|
|
69
|
+
|
|
59
70
|
def finalize!
|
|
60
|
-
|
|
71
|
+
update!(finalized: true)
|
|
61
72
|
end
|
|
62
73
|
|
|
63
74
|
def unfinalize!
|
|
64
|
-
|
|
75
|
+
update!(finalized: false)
|
|
65
76
|
end
|
|
66
77
|
|
|
67
78
|
def finalize
|
|
68
|
-
|
|
79
|
+
update(finalized: true)
|
|
69
80
|
end
|
|
70
81
|
|
|
71
82
|
def unfinalize
|
|
72
|
-
|
|
83
|
+
update(finalized: false)
|
|
73
84
|
end
|
|
74
85
|
|
|
75
86
|
def currency
|
data/app/models/spree/asset.rb
CHANGED
data/app/models/spree/base.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Spree
|
|
|
12
12
|
# as object we always get line items, as calculable we have Coupon, ShippingMethod
|
|
13
13
|
def compute(object)
|
|
14
14
|
if object.is_a?(Array)
|
|
15
|
-
base = object.map { |
|
|
15
|
+
base = object.map { |element| element.respond_to?(:amount) ? element.amount : BigDecimal(element.to_s) }.sum
|
|
16
16
|
else
|
|
17
17
|
base = object.respond_to?(:amount) ? object.amount : BigDecimal(object.to_s)
|
|
18
18
|
end
|
|
@@ -18,9 +18,9 @@ module Spree
|
|
|
18
18
|
def compute_from_quantity(quantity)
|
|
19
19
|
sum = 0
|
|
20
20
|
max = preferred_max_items.to_i
|
|
21
|
-
quantity.times do |
|
|
21
|
+
quantity.times do |index|
|
|
22
22
|
# check max value to avoid divide by 0 errors
|
|
23
|
-
if (max == 0 &&
|
|
23
|
+
if (max == 0 && index == 0) || (max > 0) && (index % max == 0)
|
|
24
24
|
sum += preferred_first_item.to_f
|
|
25
25
|
else
|
|
26
26
|
sum += preferred_additional_item.to_f
|
|
@@ -11,8 +11,8 @@ module Spree
|
|
|
11
11
|
before_validation do
|
|
12
12
|
# Convert tier values to decimals. Strings don't do us much good.
|
|
13
13
|
if preferred_tiers.is_a?(Hash)
|
|
14
|
-
self.preferred_tiers = preferred_tiers.map do |
|
|
15
|
-
[cast_to_d(
|
|
14
|
+
self.preferred_tiers = preferred_tiers.map do |key, value|
|
|
15
|
+
[cast_to_d(key.to_s), cast_to_d(value.to_s)]
|
|
16
16
|
end.to_h
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -20,8 +20,8 @@ module Spree
|
|
|
20
20
|
validate :preferred_tiers_content
|
|
21
21
|
|
|
22
22
|
def compute(object)
|
|
23
|
-
_base, amount = preferred_tiers.sort.reverse.detect do |
|
|
24
|
-
object.amount >=
|
|
23
|
+
_base, amount = preferred_tiers.sort.reverse.detect do |value, _|
|
|
24
|
+
object.amount >= value
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
if preferred_currency.casecmp(object.currency).zero?
|
|
@@ -41,7 +41,7 @@ module Spree
|
|
|
41
41
|
|
|
42
42
|
def preferred_tiers_content
|
|
43
43
|
if preferred_tiers.is_a? Hash
|
|
44
|
-
unless preferred_tiers.keys.all?{ |
|
|
44
|
+
unless preferred_tiers.keys.all?{ |key| key.is_a?(Numeric) && key > 0 }
|
|
45
45
|
errors.add(:base, :keys_should_be_positive_number)
|
|
46
46
|
end
|
|
47
47
|
else
|
|
@@ -11,8 +11,8 @@ module Spree
|
|
|
11
11
|
before_validation do
|
|
12
12
|
# Convert tier values to decimals. Strings don't do us much good.
|
|
13
13
|
if preferred_tiers.is_a?(Hash)
|
|
14
|
-
self.preferred_tiers = preferred_tiers.map do |
|
|
15
|
-
[cast_to_d(
|
|
14
|
+
self.preferred_tiers = preferred_tiers.map do |key, value|
|
|
15
|
+
[cast_to_d(key.to_s), cast_to_d(value.to_s)]
|
|
16
16
|
end.to_h
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -26,8 +26,8 @@ module Spree
|
|
|
26
26
|
def compute(object)
|
|
27
27
|
order = object.is_a?(Order) ? object : object.order
|
|
28
28
|
|
|
29
|
-
_base, percent = preferred_tiers.sort.reverse.detect do |
|
|
30
|
-
order.item_total >=
|
|
29
|
+
_base, percent = preferred_tiers.sort.reverse.detect do |value, _|
|
|
30
|
+
order.item_total >= value
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
if preferred_currency.casecmp(order.currency).zero?
|
|
@@ -48,10 +48,10 @@ module Spree
|
|
|
48
48
|
|
|
49
49
|
def preferred_tiers_content
|
|
50
50
|
if preferred_tiers.is_a? Hash
|
|
51
|
-
unless preferred_tiers.keys.all?{ |
|
|
51
|
+
unless preferred_tiers.keys.all?{ |key| key.is_a?(Numeric) && key > 0 }
|
|
52
52
|
errors.add(:base, :keys_should_be_positive_number)
|
|
53
53
|
end
|
|
54
|
-
unless preferred_tiers.values.all?{ |
|
|
54
|
+
unless preferred_tiers.values.all?{ |key| key.is_a?(Numeric) && key >= 0 && key <= 100 }
|
|
55
55
|
errors.add(:base, :values_should_be_percent)
|
|
56
56
|
end
|
|
57
57
|
else
|
data/app/models/spree/carton.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Spree::Carton < Spree::Base
|
|
4
|
-
belongs_to :address, class_name: 'Spree::Address'
|
|
5
|
-
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :cartons
|
|
6
|
-
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :cartons
|
|
4
|
+
belongs_to :address, class_name: 'Spree::Address', optional: true
|
|
5
|
+
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :cartons, optional: true
|
|
6
|
+
belongs_to :shipping_method, -> { with_discarded }, class_name: 'Spree::ShippingMethod', inverse_of: :cartons, optional: true
|
|
7
7
|
|
|
8
8
|
has_many :inventory_units, class_name: "Spree::InventoryUnit", inverse_of: :carton, dependent: :nullify
|
|
9
9
|
has_many :orders, -> { distinct }, through: :inventory_units
|
|
@@ -4,8 +4,8 @@ module Spree
|
|
|
4
4
|
class Classification < Spree::Base
|
|
5
5
|
self.table_name = 'spree_products_taxons'
|
|
6
6
|
acts_as_list scope: :taxon
|
|
7
|
-
belongs_to :product, class_name: "Spree::Product", inverse_of: :classifications, touch: true
|
|
8
|
-
belongs_to :taxon, class_name: "Spree::Taxon", inverse_of: :classifications, touch: true
|
|
7
|
+
belongs_to :product, class_name: "Spree::Product", inverse_of: :classifications, touch: true, optional: true
|
|
8
|
+
belongs_to :taxon, class_name: "Spree::Taxon", inverse_of: :classifications, touch: true, optional: true
|
|
9
9
|
|
|
10
10
|
# For https://github.com/spree/spree/issues/3494
|
|
11
11
|
validates_uniqueness_of :taxon_id, scope: :product_id, message: :already_linked
|
|
@@ -4,8 +4,8 @@ module Spree
|
|
|
4
4
|
# The default `source` of a `Spree::Payment`.
|
|
5
5
|
#
|
|
6
6
|
class CreditCard < Spree::PaymentSource
|
|
7
|
-
belongs_to :user, class_name: Spree::UserClassHandle.new, foreign_key: 'user_id'
|
|
8
|
-
belongs_to :address
|
|
7
|
+
belongs_to :user, class_name: Spree::UserClassHandle.new, foreign_key: 'user_id', optional: true
|
|
8
|
+
belongs_to :address, optional: true
|
|
9
9
|
|
|
10
10
|
before_save :set_last_digits
|
|
11
11
|
|
|
@@ -47,13 +47,13 @@ module Spree
|
|
|
47
47
|
}.freeze
|
|
48
48
|
|
|
49
49
|
def default
|
|
50
|
-
Spree::Deprecation.warn("CreditCard
|
|
50
|
+
Spree::Deprecation.warn("CreditCard#default is deprecated. Please use user.wallet.default_wallet_payment_source instead.", caller)
|
|
51
51
|
return false if user.nil?
|
|
52
52
|
user.wallet.default_wallet_payment_source.try!(:payment_source) == self
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def default=(set_as_default)
|
|
56
|
-
Spree::Deprecation.warn("CreditCard
|
|
56
|
+
Spree::Deprecation.warn("CreditCard#default= is deprecated. Please use user.wallet.default_wallet_payment_source= instead.", caller)
|
|
57
57
|
if user.nil?
|
|
58
58
|
raise "Cannot set 'default' on a credit card without a user"
|
|
59
59
|
elsif set_as_default # setting this card as default
|
|
@@ -7,7 +7,7 @@ module Spree::Image::PaperclipAttachment
|
|
|
7
7
|
validate :no_attachment_errors
|
|
8
8
|
|
|
9
9
|
has_attached_file :attachment,
|
|
10
|
-
styles: { mini: '48x48>', small: '
|
|
10
|
+
styles: { mini: '48x48>', small: '400x400>', product: '680x680>', large: '1200x1200>' },
|
|
11
11
|
default_style: :product,
|
|
12
12
|
default_url: 'noimage/:style.png',
|
|
13
13
|
url: '/spree/products/:id/:style/:basename.:extension',
|
|
@@ -8,10 +8,10 @@ module Spree
|
|
|
8
8
|
POST_SHIPMENT_STATES = %w(returned)
|
|
9
9
|
CANCELABLE_STATES = ['on_hand', 'backordered', 'shipped']
|
|
10
10
|
|
|
11
|
-
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant", inverse_of: :inventory_units
|
|
12
|
-
belongs_to :shipment, class_name: "Spree::Shipment", touch: true, inverse_of: :inventory_units
|
|
13
|
-
belongs_to :carton, class_name: "Spree::Carton", inverse_of: :inventory_units
|
|
14
|
-
belongs_to :line_item, class_name: "Spree::LineItem", inverse_of: :inventory_units
|
|
11
|
+
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant", inverse_of: :inventory_units, optional: true
|
|
12
|
+
belongs_to :shipment, class_name: "Spree::Shipment", touch: true, inverse_of: :inventory_units, optional: true
|
|
13
|
+
belongs_to :carton, class_name: "Spree::Carton", inverse_of: :inventory_units, optional: true
|
|
14
|
+
belongs_to :line_item, class_name: "Spree::LineItem", inverse_of: :inventory_units, optional: true
|
|
15
15
|
|
|
16
16
|
has_many :return_items, inverse_of: :inventory_unit, dependent: :destroy
|
|
17
17
|
has_one :original_return_item, class_name: "Spree::ReturnItem", foreign_key: :exchange_inventory_unit_id, dependent: :destroy
|
|
@@ -58,25 +58,7 @@ module Spree
|
|
|
58
58
|
|
|
59
59
|
scope :shippable, -> { on_hand }
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
state_machine initial: :on_hand do
|
|
63
|
-
event :fill_backorder do
|
|
64
|
-
transition to: :on_hand, from: :backordered
|
|
65
|
-
end
|
|
66
|
-
after_transition on: :fill_backorder, do: :fulfill_order
|
|
67
|
-
|
|
68
|
-
event :ship do
|
|
69
|
-
transition to: :shipped, if: :allow_ship?
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
event :return do
|
|
73
|
-
transition to: :returned, from: :shipped
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
event :cancel do
|
|
77
|
-
transition to: :canceled, from: CANCELABLE_STATES.map(&:to_sym)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
61
|
+
include ::Spree::Config.state_machines.inventory_unit
|
|
80
62
|
|
|
81
63
|
# Updates the given inventory units to not be pending.
|
|
82
64
|
#
|
|
@@ -12,9 +12,9 @@ module Spree
|
|
|
12
12
|
class LineItem < Spree::Base
|
|
13
13
|
class CurrencyMismatch < StandardError; end
|
|
14
14
|
|
|
15
|
-
belongs_to :order, class_name: "Spree::Order", inverse_of: :line_items, touch: true
|
|
16
|
-
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant", inverse_of: :line_items
|
|
17
|
-
belongs_to :tax_category, class_name: "Spree::TaxCategory"
|
|
15
|
+
belongs_to :order, class_name: "Spree::Order", inverse_of: :line_items, touch: true, optional: true
|
|
16
|
+
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant", inverse_of: :line_items, optional: true
|
|
17
|
+
belongs_to :tax_category, class_name: "Spree::TaxCategory", optional: true
|
|
18
18
|
|
|
19
19
|
has_one :product, through: :variant
|
|
20
20
|
|
|
@@ -72,7 +72,7 @@ module Spree
|
|
|
72
72
|
# @return [BigDecimal] the amount of this item, taking into consideration
|
|
73
73
|
# all non-tax adjustments.
|
|
74
74
|
def total_before_tax
|
|
75
|
-
amount + adjustments.select { |
|
|
75
|
+
amount + adjustments.select { |value| !value.tax? && value.eligible? }.sum(&:amount)
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
# @return [BigDecimal] the amount of this line item before VAT tax
|