Class: Spree::Address
- Inherits:
-
Base
- Object
- ApplicationRecord
- Base
- Spree::Address
show all
- Defined in:
- app/models/spree/address.rb
Constant Summary
collapse
- EXCLUDED_KEYS_FOR_COMPARISION =
we’re not freezing this on purpose so developers can extend and manage those attributes depending of the logic of their applications
%w(id updated_at created_at)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
belongs_to_required_by_default, page, spree_base_scopes
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.build_default ⇒ Object
40
41
42
|
# File 'app/models/spree/address.rb', line 40
def self.build_default
new(country: Spree::Country.default)
end
|
.default(user = nil, kind = 'bill') ⇒ Object
44
45
46
47
48
49
50
|
# File 'app/models/spree/address.rb', line 44
def self.default(user = nil, kind = 'bill')
if user && user_address = user.public_send(:"#{kind}_address")
user_address.clone
else
build_default
end
end
|
Instance Method Details
#==(other) ⇒ Object
96
97
98
99
100
|
# File 'app/models/spree/address.rb', line 96
def ==(other)
return false unless other&.respond_to?(:value_attributes)
value_attributes == other.value_attributes
end
|
#active_merchant_hash ⇒ Object
Generates an ActiveMerchant compatible address hash
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/models/spree/address.rb', line 111
def active_merchant_hash
{
name: full_name,
address1: address1,
address2: address2,
city: city,
state: state_text,
zip: zipcode,
country: country.try(:iso),
phone: phone
}
end
|
#clone ⇒ Object
92
93
94
|
# File 'app/models/spree/address.rb', line 92
def clone
self.class.new(value_attributes)
end
|
#empty? ⇒ Boolean
106
107
108
|
# File 'app/models/spree/address.rb', line 106
def empty?
attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_, v| v.nil? }
end
|
#full_name ⇒ Object
60
61
62
|
# File 'app/models/spree/address.rb', line 60
def full_name
"#{firstname} #{lastname}".strip
end
|
#iso_name ⇒ Object
52
53
54
55
56
57
58
|
# File 'app/models/spree/address.rb', line 52
def iso_name
ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
Address#iso_name is deprecated and will be removed in Spree 4.0.
Please use Address#country_iso_name instead
DEPRECATION
country_iso_name
end
|
#require_phone? ⇒ Boolean
124
125
126
|
# File 'app/models/spree/address.rb', line 124
def require_phone?
Spree::Config[:address_requires_phone]
end
|
#require_zipcode? ⇒ Boolean
128
129
130
|
# File 'app/models/spree/address.rb', line 128
def require_zipcode?
country ? country.zipcode_required? : true
end
|
#same_as(other) ⇒ Object
80
81
82
83
84
85
86
|
# File 'app/models/spree/address.rb', line 80
def same_as(other)
ActiveSupport::Deprecation.warn(<<-EOS, caller)
Address#same_as is deprecated and will be removed in Spree 4.0. Please use Address#== instead"
EOS
self == other
end
|
#same_as?(other) ⇒ Boolean
72
73
74
75
76
77
78
|
# File 'app/models/spree/address.rb', line 72
def same_as?(other)
ActiveSupport::Deprecation.warn(<<-EOS, caller)
Address#same_as? is deprecated and will be removed in Spree 4.0. Please use Address#== instead"
EOS
self == other
end
|
#state_name_text ⇒ Object
68
69
70
|
# File 'app/models/spree/address.rb', line 68
def state_name_text
state_name.present? ? state_name : state&.name
end
|
#state_text ⇒ Object
64
65
66
|
# File 'app/models/spree/address.rb', line 64
def state_text
state.try(:abbr) || state.try(:name) || state_name
end
|
#to_s ⇒ Object
88
89
90
|
# File 'app/models/spree/address.rb', line 88
def to_s
"#{full_name}: #{address1}"
end
|
#value_attributes ⇒ Object