Class: Spree::Store
- Inherits:
-
Base
- Object
- ApplicationRecord
- Base
- Spree::Store
show all
- Includes:
- Spree::Security::Stores, TranslatableResource, Webhooks::HasWebhooks
- Defined in:
- app/models/spree/store.rb
Constant Summary
collapse
- TRANSLATABLE_FIELDS =
%i[name meta_description meta_keywords seo_title facebook
twitter instagram customer_support_email description
address contact_phone new_order_notifications_email].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope
#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference
Instance Attribute Details
#skip_validate_not_last ⇒ Object
Returns the value of attribute skip_validate_not_last.
31
32
33
|
# File 'app/models/spree/store.rb', line 31
def skip_validate_not_last
@skip_validate_not_last
end
|
Class Method Details
.available_locales ⇒ Object
135
136
137
138
139
|
# File 'app/models/spree/store.rb', line 135
def self.available_locales
Rails.cache.fetch('stores_available_locales') do
Spree::Store.all.map(&:supported_locales_list).flatten.uniq
end
end
|
.current(url = nil) ⇒ Object
114
115
116
117
118
119
120
|
# File 'app/models/spree/store.rb', line 114
def self.current(url = nil)
Spree::Deprecation.warn(<<-DEPRECATION, caller)
`Spree::Store.current` is deprecated and will be removed in Spree 5.0
Please use `Spree::Stores::FindCurrent.new(url: "https://example.com").execute` instead
DEPRECATION
Stores::FindCurrent.new(url: url).execute
end
|
.default ⇒ Object
FIXME: we need to drop ‘or_initialize` in v5 this behaviour is very buggy and unpredictable
124
125
126
127
128
129
130
131
132
133
|
# File 'app/models/spree/store.rb', line 124
def self.default
Rails.cache.fetch('default_store') do
if where(default: true).any?
where(default: true).first
else
new(default: true)
end
end
end
|
Instance Method Details
#can_be_deleted? ⇒ Boolean
208
209
210
|
# File 'app/models/spree/store.rb', line 208
def can_be_deleted?
self.class.where.not(id: id).any?
end
|
#checkout_zone_or_default ⇒ Object
196
197
198
199
200
|
# File 'app/models/spree/store.rb', line 196
def checkout_zone_or_default
Spree::Deprecation.warn('Store#checkout_zone_or_default is deprecated and will be removed in Spree 5')
@checkout_zone_or_default ||= checkout_zone || Spree::Zone.default_checkout_zone
end
|
#countries_available_for_checkout ⇒ Object
188
189
190
|
# File 'app/models/spree/store.rb', line 188
def countries_available_for_checkout
@countries_available_for_checkout ||= checkout_zone.try(:country_list) || Spree::Country.all
end
|
141
142
143
144
145
|
# File 'app/models/spree/store.rb', line 141
def (location)
= .find_by(location: location, locale: default_locale) || .find_by(location: location)
.root if .present?
end
|
#favicon ⇒ Object
202
203
204
205
206
|
# File 'app/models/spree/store.rb', line 202
def favicon
return unless favicon_image&.attachment&.attached?
favicon_image.attachment.variant(resize_to_limit: [32, 32])
end
|
178
179
180
181
182
183
184
185
186
|
# File 'app/models/spree/store.rb', line 178
def formatted_url
return if url.blank?
@formatted_url ||= if url.match(/http:\/\/|https:\/\//)
url
else
Rails.env.development? || Rails.env.test? ? "http://#{url}" : "https://#{url}"
end
end
|
#homepage(requested_locale) ⇒ Object
153
154
155
156
157
|
# File 'app/models/spree/store.rb', line 153
def homepage(requested_locale)
cms_pages.by_locale(requested_locale).find_by(type: 'Spree::Cms::Pages::Homepage') ||
cms_pages.by_locale(default_locale).find_by(type: 'Spree::Cms::Pages::Homepage') ||
cms_pages.find_by(type: 'Spree::Cms::Pages::Homepage')
end
|
159
160
161
162
163
164
165
166
167
|
# File 'app/models/spree/store.rb', line 159
def seo_meta_description
if meta_description.present?
meta_description
elsif seo_title.present?
seo_title
else
name
end
end
|
#states_available_for_checkout(country) ⇒ Object
192
193
194
|
# File 'app/models/spree/store.rb', line 192
def states_available_for_checkout(country)
checkout_zone.try(:state_list_for, country) || country.states
end
|
#supported_currencies_list ⇒ Object
147
148
149
150
151
|
# File 'app/models/spree/store.rb', line 147
def supported_currencies_list
@supported_currencies_list ||= (read_attribute(:supported_currencies).to_s.split(',') << default_currency).sort.map(&:to_s).map do |code|
::Money::Currency.find(code.strip)
end.uniq.compact
end
|
#supported_locales_list ⇒ Object
169
170
171
172
|
# File 'app/models/spree/store.rb', line 169
def supported_locales_list
@supported_locales_list ||= (read_attribute(:supported_locales).to_s.split(',') << default_locale).compact.uniq.sort
end
|
#unique_name ⇒ Object
174
175
176
|
# File 'app/models/spree/store.rb', line 174
def unique_name
@unique_name ||= "#{name} (#{code})"
end
|