solidus_core 2.11.15 → 3.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree.js.erb +0 -51
- 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 +11 -11
- data/app/models/concerns/spree/active_storage_adapter.rb +0 -2
- 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/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +0 -37
- data/app/models/concerns/spree/user_methods.rb +2 -11
- data/app/models/spree/ability.rb +0 -37
- data/app/models/spree/address/name.rb +2 -20
- data/app/models/spree/address.rb +8 -187
- data/app/models/spree/adjustment.rb +0 -28
- data/app/models/spree/base.rb +12 -48
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -11
- data/app/models/spree/country.rb +1 -6
- data/app/models/spree/credit_card.rb +0 -27
- data/app/models/spree/customer_return.rb +1 -4
- data/app/models/spree/image/active_storage_attachment.rb +2 -10
- data/app/models/spree/image/paperclip_attachment.rb +1 -1
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +2 -45
- data/app/models/spree/order.rb +4 -137
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_updater.rb +2 -11
- data/app/models/spree/payment/cancellation.rb +3 -22
- 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 +9 -13
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +4 -4
- data/app/models/spree/payment_method.rb +2 -106
- data/app/models/spree/product/scopes.rb +0 -27
- data/app/models/spree/product.rb +0 -39
- data/app/models/spree/promotion/actions/create_adjustment.rb +0 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/rules/taxon.rb +2 -15
- data/app/models/spree/promotion.rb +2 -6
- data/app/models/spree/promotion_action.rb +2 -12
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_code.rb +2 -2
- data/app/models/spree/promotion_rule.rb +0 -4
- data/app/models/spree/refund.rb +0 -52
- data/app/models/spree/reimbursement.rb +3 -41
- 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 +1 -4
- data/app/models/spree/return_item.rb +1 -19
- data/app/models/spree/shipment.rb +1 -54
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/state.rb +0 -4
- data/app/models/spree/stock/simple_coordinator.rb +1 -20
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +1 -7
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/tax_calculator/shipping_rate.rb +1 -12
- data/app/models/spree/tax_rate.rb +0 -27
- data/app/models/spree/taxon/active_storage_attachment.rb +0 -5
- data/app/models/spree/taxon/paperclip_attachment.rb +0 -5
- data/app/models/spree/taxon.rb +0 -11
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/variant.rb +2 -46
- data/config/locales/en.yml +0 -8
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/lib/generators/solidus/install/install_generator.rb +13 -2
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -39
- data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
- 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 +6 -73
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -14
- data/lib/spree/core/controller_helpers/order.rb +2 -22
- 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/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +0 -43
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +0 -40
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +0 -26
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +9 -8
- data/lib/spree/event/configuration.rb +0 -5
- data/lib/spree/event/subscriber.rb +0 -18
- data/lib/spree/event/subscriber_registry.rb +3 -1
- data/lib/spree/event.rb +0 -31
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permitted_attributes.rb +3 -60
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +6 -15
- data/lib/spree/testing_support/factories/order_factory.rb +0 -1
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/order_walkthrough.rb +0 -3
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/spree/testing_support.rb +1 -1
- data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +20 -15
- data/solidus_core.gemspec +1 -24
- metadata +7 -66
- 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/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/preferences/persistable.rb +0 -23
- data/lib/spree/promo/environment.rb +0 -12
- data/lib/spree/testing_support/bar_ability.rb +0 -19
- data/lib/spree/testing_support/fixtures/file.txt +0 -1
- 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_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/solidus/check_orders_with_invalid_email.rake +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35ced6fd29e1822a14a86b637243c871d373b2ead2d575e7737d0fa35907a48d
|
4
|
+
data.tar.gz: ab72677886bf4ce7c2ba48dbe711fe73aa5e1193d990fb4d7cd872035e247f33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b18d6067bfbe97ce226fd82fb9a48da5e16eadeef3ac3b758c7d159dc079aef8880396a2acb9c0e23f98953d331f8161ba3271f780c21de04c1f9e501b1136b
|
7
|
+
data.tar.gz: 5cc4ad46294a842daa2850e785d08dbfa4f01b28f5806449457fb498898c557866590ed7d332888d6c5fae72ae1ee81fbf3d4fa1ead5aa682af226debce6a890
|
@@ -22,21 +22,6 @@ Spree.pathFor = function(path) {
|
|
22
22
|
return locationOrigin + Spree.mountedAt() + path;
|
23
23
|
};
|
24
24
|
|
25
|
-
Spree.url = function(uri, query) {
|
26
|
-
if (console && console.warn) {
|
27
|
-
console.warn('Spree.url is deprecated, and will be removed from a future Solidus version.');
|
28
|
-
}
|
29
|
-
if (uri.path === undefined) {
|
30
|
-
uri = new Uri(uri);
|
31
|
-
}
|
32
|
-
if (query) {
|
33
|
-
$.each(query, function(key, value) {
|
34
|
-
return uri.addQueryParam(key, value);
|
35
|
-
});
|
36
|
-
}
|
37
|
-
return uri;
|
38
|
-
};
|
39
|
-
|
40
25
|
Spree.ajax = function(url, options) {
|
41
26
|
if (typeof url === "object") {
|
42
27
|
options = url;
|
@@ -51,42 +36,6 @@ Spree.ajax = function(url, options) {
|
|
51
36
|
return $.ajax(url, options);
|
52
37
|
};
|
53
38
|
|
54
|
-
/**
|
55
|
-
* @deprecated Spree.routes will be removed in a future release. Please use Spree.pathFor instead.
|
56
|
-
* See: https://github.com/solidusio/solidus/issues/3405
|
57
|
-
*/
|
58
|
-
Spree.routesDeprecationProxy = {
|
59
|
-
get: function(obj, prop) {
|
60
|
-
<% if Rails.env != "production" %>
|
61
|
-
console.log("Spree.routes is deprecated, please use pathFor instead. See: https://github.com/solidusio/solidus/issues/3405");
|
62
|
-
<% end %>
|
63
|
-
|
64
|
-
return obj[prop]
|
65
|
-
},
|
66
|
-
|
67
|
-
set: function(obj, prop, value) {
|
68
|
-
<% if Rails.env != "production" %>
|
69
|
-
console.log("Spree.routes is deprecated, please use pathFor instead. See: https://github.com/solidusio/solidus/issues/3405");
|
70
|
-
<% end %>
|
71
|
-
|
72
|
-
obj[prop] = value
|
73
|
-
return value;
|
74
|
-
}
|
75
|
-
};
|
76
|
-
|
77
|
-
var frontend_routes = {
|
78
|
-
states_search: Spree.pathFor('api/states'),
|
79
|
-
apply_coupon_code: function(order_id) {
|
80
|
-
return Spree.pathFor("api/orders/" + order_id + "/coupon_codes");
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
if(typeof Proxy == "function") {
|
85
|
-
Spree.routes = new Proxy(frontend_routes, Spree.routesDeprecationProxy);
|
86
|
-
} else {
|
87
|
-
Spree.routes = frontend_routes
|
88
|
-
}
|
89
|
-
|
90
39
|
Spree.getJSON = function(url, data, success) {
|
91
40
|
if (typeof data === 'function') {
|
92
41
|
success = data;
|
@@ -8,16 +8,5 @@ module Spree
|
|
8
8
|
def store_menu?
|
9
9
|
%w{thank_you}.exclude? params[:action]
|
10
10
|
end
|
11
|
-
|
12
|
-
def cache_key_for_taxons
|
13
|
-
Spree::Deprecation.warn <<-WARN.strip_heredoc
|
14
|
-
cache_key_for_taxons is deprecated. Rails >= 5 has built-in support for collection cache keys.
|
15
|
-
Instead in your view use:
|
16
|
-
cache [I18n.locale, @taxons] do
|
17
|
-
WARN
|
18
|
-
max_updated_at = @taxons.maximum(:updated_at).to_i
|
19
|
-
parts = [@taxon.try(:id), max_updated_at].compact.join("-")
|
20
|
-
"#{I18n.locale}/taxons/#{parts}"
|
21
|
-
end
|
22
11
|
end
|
23
12
|
end
|
@@ -11,11 +11,7 @@ module Spree
|
|
11
11
|
# @option options resend [Boolean] indicates whether the email is a 'resend' (e.g.
|
12
12
|
# triggered by the admin "resend" button)
|
13
13
|
# @return [Mail::Message]
|
14
|
-
|
15
|
-
# Note: The signature of this method has changed. The new (non-deprecated)
|
16
|
-
# signature is:
|
17
|
-
# def shipped_email(carton:, order:, resend: false)
|
18
|
-
def shipped_email(options, _deprecated_options = {})
|
14
|
+
def shipped_email(options)
|
19
15
|
@order = options.fetch(:order)
|
20
16
|
@carton = options.fetch(:carton)
|
21
17
|
@manifest = @carton.manifest_for_order(@order)
|
@@ -9,9 +9,11 @@ module Spree
|
|
9
9
|
class Attachment
|
10
10
|
delegate_missing_to :@attachment
|
11
11
|
|
12
|
+
DEFAULT_SIZE = '100%'
|
13
|
+
|
12
14
|
def initialize(attachment, styles: {})
|
13
15
|
@attachment = attachment
|
14
|
-
@styles =
|
16
|
+
@styles = styles
|
15
17
|
end
|
16
18
|
|
17
19
|
def exists?
|
@@ -19,18 +21,20 @@ module Spree
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def filename
|
22
|
-
blob
|
24
|
+
blob.filename.to_s
|
23
25
|
end
|
24
26
|
|
25
27
|
def url(style = nil)
|
26
|
-
variant(style)
|
28
|
+
variant(style).url
|
27
29
|
end
|
28
30
|
|
29
31
|
def variant(style = nil)
|
30
|
-
size = style_to_size(style)
|
32
|
+
size = style_to_size(style&.to_sym)
|
31
33
|
@attachment.variant(
|
32
|
-
|
33
|
-
strip: true
|
34
|
+
resize: size,
|
35
|
+
strip: true,
|
36
|
+
'auto-orient': true,
|
37
|
+
colorspace: 'sRGB',
|
34
38
|
).processed
|
35
39
|
end
|
36
40
|
|
@@ -57,12 +61,8 @@ module Spree
|
|
57
61
|
@attachment.metadata
|
58
62
|
end
|
59
63
|
|
60
|
-
def normalize_styles(styles)
|
61
|
-
styles.transform_values { |v| v.split('x') }
|
62
|
-
end
|
63
|
-
|
64
64
|
def style_to_size(style)
|
65
|
-
@styles.fetch(style
|
65
|
+
@styles.fetch(style) { DEFAULT_SIZE }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -2,21 +2,6 @@
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
module AdjustmentSource
|
5
|
-
def deals_with_adjustments_for_deleted_source
|
6
|
-
Spree::Deprecation.warn "AdjustmentSource#deals_with_adjustments_for_deleted_source is deprecated. Please use AdjustmentSource#remove_adjustments_from_incomplete_orders instead."
|
7
|
-
|
8
|
-
remove_adjustments_from_incomplete_orders
|
9
|
-
|
10
|
-
# The following is deprecated. As source_type without a source_id isn't
|
11
|
-
# much better than a source_id that doesn't exist. In Solidus itself the
|
12
|
-
# relevant classes use `acts_as_paranoid` so it is useful to keep the
|
13
|
-
# source_id around.
|
14
|
-
adjustments.
|
15
|
-
joins(:order).
|
16
|
-
merge(Spree::Order.complete).
|
17
|
-
update_all(source_id: nil, updated_at: Time.current)
|
18
|
-
end
|
19
|
-
|
20
5
|
def remove_adjustments_from_incomplete_orders
|
21
6
|
adjustments.
|
22
7
|
joins(:order).
|
@@ -10,24 +10,6 @@ module Spree
|
|
10
10
|
validates :calculator, presence: true
|
11
11
|
end
|
12
12
|
|
13
|
-
class_methods do
|
14
|
-
def calculators
|
15
|
-
Spree::Deprecation.warn("Calling .calculators is deprecated. Please access through Rails.application.config.spree.calculators")
|
16
|
-
|
17
|
-
spree_calculators.send model_name_without_spree_namespace
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def model_name_without_spree_namespace
|
23
|
-
to_s.tableize.tr('/', '_').sub('spree_', '')
|
24
|
-
end
|
25
|
-
|
26
|
-
def spree_calculators
|
27
|
-
Spree::Config.environment.calculators
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
13
|
def calculator_type
|
32
14
|
calculator.class.to_s if calculator
|
33
15
|
end
|
@@ -7,12 +7,10 @@ module Spree
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
included do
|
10
|
-
acts_as_paranoid
|
11
|
-
include Spree::ParanoiaDeprecations::InstanceMethods
|
12
|
-
extend Spree::ParanoiaDeprecations::ClassMethods
|
13
|
-
|
14
10
|
include Discard::Model
|
15
11
|
self.discard_column = :deleted_at
|
12
|
+
|
13
|
+
default_scope { kept }
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
@@ -39,34 +39,6 @@ module Spree
|
|
39
39
|
has_one :ship_address, through: :default_user_ship_address, source: :address
|
40
40
|
end
|
41
41
|
|
42
|
-
def default_address
|
43
|
-
Spree::Deprecation.warn "#default_address is deprecated. Please start using #ship_address."
|
44
|
-
ship_address
|
45
|
-
end
|
46
|
-
|
47
|
-
def default_user_address
|
48
|
-
Spree::Deprecation.warn "#default_user_address is deprecated. Please start using #default_user_ship_address."
|
49
|
-
default_user_ship_address
|
50
|
-
end
|
51
|
-
|
52
|
-
def default_address=(address)
|
53
|
-
Spree::Deprecation.warn(
|
54
|
-
"#default_address= does not take Spree::Config.automatic_default_address into account and is deprecated. " \
|
55
|
-
"Please use #ship_address=."
|
56
|
-
)
|
57
|
-
|
58
|
-
self.ship_address = address if address
|
59
|
-
end
|
60
|
-
|
61
|
-
def default_address_attributes=(attributes)
|
62
|
-
# see "Nested Attributes Examples" section of http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for
|
63
|
-
# this #{fieldname}_attributes= method works with fields_for in the views
|
64
|
-
# even without declaring accepts_nested_attributes_for
|
65
|
-
Spree::Deprecation.warn "#default_address_attributes= is deprecated. Please use #ship_address_attributes=."
|
66
|
-
|
67
|
-
self.default_address = Spree::Address.immutable_merge(ship_address, attributes)
|
68
|
-
end
|
69
|
-
|
70
42
|
# saves address in address book
|
71
43
|
# sets address to the default if automatic_default_address is set to true
|
72
44
|
# if address is nil, does nothing and returns nil
|
@@ -157,15 +129,6 @@ module Spree
|
|
157
129
|
user_address.address
|
158
130
|
end
|
159
131
|
|
160
|
-
def mark_default_address(address)
|
161
|
-
Spree::Deprecation.warn(
|
162
|
-
"#mark_default_address is deprecated and it sets the ship_address only. " \
|
163
|
-
"Please use #mark_default_ship_address."
|
164
|
-
)
|
165
|
-
|
166
|
-
mark_default_ship_address(address)
|
167
|
-
end
|
168
|
-
|
169
132
|
def mark_default_ship_address(address)
|
170
133
|
user_addresses.mark_default(user_addresses.find_by(address: address))
|
171
134
|
end
|
@@ -7,7 +7,6 @@ module Spree
|
|
7
7
|
include Spree::UserApiAuthentication
|
8
8
|
include Spree::UserReporting
|
9
9
|
include Spree::UserAddressBook
|
10
|
-
include Spree::UserPaymentSource
|
11
10
|
|
12
11
|
included do
|
13
12
|
extend Spree::DisplayMoney
|
@@ -24,9 +23,6 @@ module Spree
|
|
24
23
|
has_many :store_credits, -> { includes(:credit_type) }, foreign_key: "user_id", class_name: "Spree::StoreCredit"
|
25
24
|
has_many :store_credit_events, through: :store_credits
|
26
25
|
|
27
|
-
money_methods :total_available_store_credit
|
28
|
-
deprecate display_total_available_store_credit: :display_available_store_credit_total, deprecator: Spree::Deprecation
|
29
|
-
|
30
26
|
has_many :credit_cards, class_name: "Spree::CreditCard", foreign_key: :user_id
|
31
27
|
has_many :wallet_payment_sources, foreign_key: 'user_id', class_name: 'Spree::WalletPaymentSource', inverse_of: :user
|
32
28
|
|
@@ -34,9 +30,9 @@ module Spree
|
|
34
30
|
|
35
31
|
include Spree::RansackableAttributes unless included_modules.include?(Spree::RansackableAttributes)
|
36
32
|
|
37
|
-
ransack_alias :
|
33
|
+
ransack_alias :name, :addresses_name
|
38
34
|
self.whitelisted_ransackable_associations = %w[addresses spree_roles]
|
39
|
-
self.whitelisted_ransackable_attributes = %w[
|
35
|
+
self.whitelisted_ransackable_attributes = %w[name id email created_at]
|
40
36
|
end
|
41
37
|
|
42
38
|
def wallet
|
@@ -68,11 +64,6 @@ module Spree
|
|
68
64
|
last_order unless last_order.try!(:completed?)
|
69
65
|
end
|
70
66
|
|
71
|
-
def total_available_store_credit
|
72
|
-
store_credits.reload.to_a.sum(&:amount_remaining)
|
73
|
-
end
|
74
|
-
deprecate total_available_store_credit: :available_store_credit_total, deprecator: Spree::Deprecation
|
75
|
-
|
76
67
|
def available_store_credit_total(currency:)
|
77
68
|
store_credits.to_a.
|
78
69
|
select { |credit| credit.currency == currency }.
|
data/app/models/spree/ability.rb
CHANGED
@@ -14,13 +14,6 @@ module Spree
|
|
14
14
|
|
15
15
|
attr_reader :user
|
16
16
|
|
17
|
-
CUSTOM_ALIASES_MAP = {
|
18
|
-
delete: :destroy,
|
19
|
-
display: :read,
|
20
|
-
new_action: :create,
|
21
|
-
read: :show
|
22
|
-
}.freeze
|
23
|
-
|
24
17
|
# Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to
|
25
18
|
# modify the default +Ability+ of an application. The +ability+ argument must be a class that includes
|
26
19
|
# the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class
|
@@ -40,38 +33,8 @@ module Spree
|
|
40
33
|
register_extension_abilities
|
41
34
|
end
|
42
35
|
|
43
|
-
def can?(action, *args)
|
44
|
-
super(normalize_action(action), *args)
|
45
|
-
end
|
46
|
-
|
47
|
-
def model_adapter(model_class, action)
|
48
|
-
super(model_class, normalize_action(action))
|
49
|
-
end
|
50
|
-
|
51
36
|
private
|
52
37
|
|
53
|
-
def normalize_action(action)
|
54
|
-
return action unless Spree::Config.use_custom_cancancan_actions
|
55
|
-
|
56
|
-
normalized_action = CUSTOM_ALIASES_MAP.fetch(action, action)
|
57
|
-
|
58
|
-
if action == :read
|
59
|
-
Spree::Deprecation.warn <<~WARN, caller(3)
|
60
|
-
The behavior of CanCanCan `:read` action alias will be changing in Solidus 3.0.
|
61
|
-
The current alias is: `:show, :to => :read`,
|
62
|
-
the new alias will be compliant with CanCanCan's default: `index, :show, :to => :read`
|
63
|
-
WARN
|
64
|
-
elsif CUSTOM_ALIASES_MAP.key? action
|
65
|
-
Spree::Deprecation.warn <<~WARN, caller(3)
|
66
|
-
Calling CanCanCan alias action #{action.inspect} is deprecated.
|
67
|
-
In Solidus 3.0 non-standard CanCanCan action aliases will be replaced with default ones,
|
68
|
-
please replace with #{normalized_action.inspect}.
|
69
|
-
WARN
|
70
|
-
end
|
71
|
-
|
72
|
-
normalized_action
|
73
|
-
end
|
74
|
-
|
75
38
|
# Before, this was the only way to extend this ability. Permission sets have been added since.
|
76
39
|
# It is recommended to use them instead for extension purposes if possible.
|
77
40
|
def register_extension_abilities
|
@@ -2,29 +2,11 @@
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
class Address
|
5
|
-
# Provides a value object to help
|
6
|
-
#
|
5
|
+
# Provides a value object to help splitting and joining
|
6
|
+
# name fields
|
7
7
|
class Name
|
8
8
|
attr_reader :first_name, :last_name, :value
|
9
9
|
|
10
|
-
# Creates an instance of Spree::Address::Name parsing input attributes.
|
11
|
-
# @param attributes [Hash] an hash possibly containing name-related
|
12
|
-
# attributes (name, firstname, lastname, first_name, last_name)
|
13
|
-
# @return [Spree::Address::Name] the object created
|
14
|
-
def self.from_attributes(attributes)
|
15
|
-
params = attributes.with_indifferent_access
|
16
|
-
|
17
|
-
if params[:name].present?
|
18
|
-
Spree::Address::Name.new(params[:name])
|
19
|
-
elsif params[:firstname].present?
|
20
|
-
Spree::Address::Name.new(params[:firstname], params[:lastname])
|
21
|
-
elsif params[:first_name].present?
|
22
|
-
Spree::Address::Name.new(params[:first_name], params[:last_name])
|
23
|
-
else
|
24
|
-
Spree::Address::Name.new
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
10
|
def initialize(*components)
|
29
11
|
@value = components.join(' ').strip
|
30
12
|
initialize_name_components(components)
|
data/app/models/spree/address.rb
CHANGED
@@ -14,45 +14,24 @@ module Spree
|
|
14
14
|
belongs_to :country, class_name: "Spree::Country", optional: true
|
15
15
|
belongs_to :state, class_name: "Spree::State", optional: true
|
16
16
|
|
17
|
-
validates :address1, :city, :country_id, presence: true
|
17
|
+
validates :address1, :city, :country_id, :name, presence: true
|
18
18
|
validates :zipcode, presence: true, if: :require_zipcode?
|
19
19
|
validates :phone, presence: true, if: :require_phone?
|
20
20
|
|
21
|
-
validate :validate_name
|
22
|
-
|
23
21
|
validate do
|
24
|
-
|
25
|
-
begin
|
26
|
-
@silence_state_deprecations = true
|
27
|
-
state_validate
|
28
|
-
validate_state_matches_country
|
29
|
-
ensure
|
30
|
-
@silence_state_deprecations = false
|
31
|
-
end
|
32
|
-
else
|
33
|
-
self.class.state_validator_class.new(self).perform
|
34
|
-
end
|
22
|
+
self.class.state_validator_class.new(self).perform
|
35
23
|
end
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
DB_ONLY_ATTRS = %w(id updated_at created_at)
|
42
|
-
TAXATION_ATTRS = %w(state_id country_id zipcode)
|
43
|
-
LEGACY_NAME_ATTRS = %w(firstname lastname full_name)
|
25
|
+
self.ignored_columns = %w(firstname lastname)
|
26
|
+
DB_ONLY_ATTRS = %w(id updated_at created_at).freeze
|
27
|
+
TAXATION_ATTRS = %w(state_id country_id zipcode).freeze
|
44
28
|
|
45
|
-
self.whitelisted_ransackable_attributes = %w[
|
29
|
+
self.whitelisted_ransackable_attributes = %w[name]
|
46
30
|
|
47
31
|
scope :with_values, ->(attributes) do
|
48
32
|
where(value_attributes(attributes))
|
49
33
|
end
|
50
34
|
|
51
|
-
Spree::Deprecation.deprecate_methods(
|
52
|
-
Spree::Address,
|
53
|
-
LEGACY_NAME_ATTRS.product([:name]).to_h
|
54
|
-
)
|
55
|
-
|
56
35
|
# @return [Address] an address with default attributes
|
57
36
|
def self.build_default(*args, &block)
|
58
37
|
where(country: Spree::Country.default).build(*args, &block)
|
@@ -84,24 +63,7 @@ module Spree
|
|
84
63
|
# @return [Hash] hash of attributes contributing to value equality with optional merge
|
85
64
|
def self.value_attributes(base_attributes, merge_attributes = {})
|
86
65
|
base = base_attributes.stringify_keys.merge(merge_attributes.stringify_keys)
|
87
|
-
base.
|
88
|
-
|
89
|
-
name_from_attributes = Spree::Address::Name.from_attributes(base)
|
90
|
-
if base['firstname'].presence || base['first_name'].presence
|
91
|
-
base['firstname'] = name_from_attributes.first_name
|
92
|
-
end
|
93
|
-
if base['lastname'].presence || base['last_name'].presence
|
94
|
-
base['lastname'] = name_from_attributes.last_name
|
95
|
-
end
|
96
|
-
|
97
|
-
virtual_name = name_from_attributes.value
|
98
|
-
if base['name'].blank? && virtual_name.present?
|
99
|
-
base['name'] = virtual_name
|
100
|
-
end
|
101
|
-
|
102
|
-
excluded_attributes = DB_ONLY_ATTRS + %w(first_name last_name)
|
103
|
-
|
104
|
-
base.except(*excluded_attributes)
|
66
|
+
base.except(*DB_ONLY_ATTRS)
|
105
67
|
end
|
106
68
|
|
107
69
|
# @return [Hash] hash of attributes contributing to value equality
|
@@ -127,36 +89,7 @@ module Spree
|
|
127
89
|
# @return [Boolean] true if the two addresses have the same address fields
|
128
90
|
def ==(other_address)
|
129
91
|
return false unless other_address && other_address.respond_to?(:value_attributes)
|
130
|
-
|
131
|
-
value_attributes.except(*LEGACY_NAME_ATTRS) == other_address.value_attributes.except(*LEGACY_NAME_ATTRS)
|
132
|
-
else
|
133
|
-
value_attributes == other_address.value_attributes
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# @deprecated Do not use this. Use Address.== instead.
|
138
|
-
def same_as?(other_address)
|
139
|
-
Spree::Deprecation.warn("Address#same_as? is deprecated. It's equivalent to Address.==", caller)
|
140
|
-
self == other_address
|
141
|
-
end
|
142
|
-
|
143
|
-
# @deprecated Do not use this. Use Address.== instead.
|
144
|
-
def same_as(other_address)
|
145
|
-
Spree::Deprecation.warn("Address#same_as is deprecated. It's equivalent to Address.==", caller)
|
146
|
-
self == other_address
|
147
|
-
end
|
148
|
-
|
149
|
-
# @deprecated Do not use this
|
150
|
-
def empty?
|
151
|
-
Spree::Deprecation.warn("Address#empty? is deprecated.", caller)
|
152
|
-
attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_, value| value.nil? }
|
153
|
-
end
|
154
|
-
|
155
|
-
# This exists because the default Object#blank?, checks empty? if it is
|
156
|
-
# defined, and we have defined empty.
|
157
|
-
# This should be removed once empty? is removed
|
158
|
-
def blank?
|
159
|
-
false
|
92
|
+
value_attributes == other_address.value_attributes
|
160
93
|
end
|
161
94
|
|
162
95
|
# @return [Hash] an ActiveMerchant compatible address hash
|
@@ -203,117 +136,5 @@ module Spree
|
|
203
136
|
def country_iso
|
204
137
|
country && country.iso
|
205
138
|
end
|
206
|
-
|
207
|
-
before_save :set_name_from_firstname_and_lastname
|
208
|
-
|
209
|
-
def set_name_from_firstname_and_lastname
|
210
|
-
name_from_firstname_and_lastname = Spree::Address::Name.from_attributes(attributes.except(:name, 'name'))
|
211
|
-
|
212
|
-
if read_attribute(:name).blank? && name_from_firstname_and_lastname.present?
|
213
|
-
write_attribute(:name, name_from_firstname_and_lastname)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
# @return [String] the full name on this address
|
218
|
-
def name
|
219
|
-
self[:name] || begin
|
220
|
-
Spree::Address::Name.new(
|
221
|
-
read_attribute(:firstname),
|
222
|
-
read_attribute(:lastname)
|
223
|
-
).value
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
def name=(value)
|
228
|
-
return if value.nil?
|
229
|
-
|
230
|
-
write_attribute(:name, value)
|
231
|
-
name_from_value = Spree::Address::Name.new(value)
|
232
|
-
write_attribute(:firstname, name_from_value.first_name)
|
233
|
-
write_attribute(:lastname, name_from_value.last_name)
|
234
|
-
end
|
235
|
-
|
236
|
-
def as_json(options = {})
|
237
|
-
if Spree::Config.use_combined_first_and_last_name_in_address
|
238
|
-
super(options.merge(except: LEGACY_NAME_ATTRS)).tap do |hash|
|
239
|
-
hash['name'] = name
|
240
|
-
end
|
241
|
-
else
|
242
|
-
super
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
private
|
247
|
-
|
248
|
-
def validate_name
|
249
|
-
return if name.present?
|
250
|
-
|
251
|
-
name_attribute = if Spree::Config.use_combined_first_and_last_name_in_address
|
252
|
-
:name
|
253
|
-
else
|
254
|
-
:firstname
|
255
|
-
end
|
256
|
-
errors.add(name_attribute, :blank)
|
257
|
-
end
|
258
|
-
|
259
|
-
def state_validate
|
260
|
-
unless @silence_state_deprecations
|
261
|
-
Spree::Deprecation.warn \
|
262
|
-
"#{self.class}#state_validate private method has been deprecated" \
|
263
|
-
" and will be removed in Solidus v3." \
|
264
|
-
" Check https://github.com/solidusio/solidus/pull/3129 for more details.",
|
265
|
-
caller
|
266
|
-
end
|
267
|
-
|
268
|
-
# Skip state validation without country (also required)
|
269
|
-
# or when disabled by preference
|
270
|
-
return if country.blank? || !Spree::Config[:address_requires_state]
|
271
|
-
return unless country.states_required
|
272
|
-
|
273
|
-
# ensure associated state belongs to country
|
274
|
-
if state.present?
|
275
|
-
if state.country == country
|
276
|
-
self.state_name = nil # not required as we have a valid state and country combo
|
277
|
-
elsif state_name.present?
|
278
|
-
self.state = nil
|
279
|
-
else
|
280
|
-
errors.add(:state, :invalid)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
# ensure state_name belongs to country without states, or that it matches a predefined state name/abbr
|
285
|
-
if state_name.present?
|
286
|
-
if country.states.present?
|
287
|
-
states = country.states.with_name_or_abbr(state_name)
|
288
|
-
|
289
|
-
if states.size == 1
|
290
|
-
self.state = states.first
|
291
|
-
self.state_name = nil
|
292
|
-
else
|
293
|
-
errors.add(:state, :invalid)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
# ensure at least one state field is populated
|
299
|
-
errors.add :state, :blank if state.blank? && state_name.blank?
|
300
|
-
end
|
301
|
-
|
302
|
-
def validate_state_matches_country
|
303
|
-
unless @silence_state_deprecations
|
304
|
-
Spree::Deprecation.warn \
|
305
|
-
"#{self.class}#validate_state_matches_country private method has been deprecated" \
|
306
|
-
" and will be removed in Solidus v3." \
|
307
|
-
" Check https://github.com/solidusio/solidus/pull/3129 for more details.",
|
308
|
-
caller
|
309
|
-
end
|
310
|
-
|
311
|
-
return unless country
|
312
|
-
|
313
|
-
self.state = nil if country.states.empty?
|
314
|
-
if state && state.country != country
|
315
|
-
errors.add(:state, :does_not_match_country)
|
316
|
-
end
|
317
|
-
end
|
318
139
|
end
|
319
140
|
end
|