Class: Spree::Market
- Inherits:
-
Object
- Object
- Spree::Market
- Includes:
- SingleStoreResource
- Defined in:
- app/models/spree/market.rb
Class Method Summary collapse
-
.default_for_store(store) ⇒ Spree::Market?
Returns the default market for a store, or falls back to the first by position.
-
.for_country(country, store:) ⇒ Spree::Market?
Find the market that contains the given country for a store.
Instance Method Summary collapse
-
#can_be_deleted? ⇒ Boolean
Returns true when the market is safe to delete.
-
#default_country ⇒ Spree::Country?
Returns the first country by name from this market’s countries.
-
#supported_locales_list ⇒ Array<String>
Returns supported locales as an array, always including default_locale.
-
#tax_zone ⇒ Spree::Zone?
Returns the tax zone matching this market’s default country.
Class Method Details
.default_for_store(store) ⇒ Spree::Market?
Returns the default market for a store, or falls back to the first by position
56 57 58 59 60 |
# File 'app/models/spree/market.rb', line 56 def self.default_for_store(store) return nil unless store store.markets.default.first || store.markets.order(:position).first end |
.for_country(country, store:) ⇒ Spree::Market?
Find the market that contains the given country for a store
43 44 45 46 47 48 49 50 |
# File 'app/models/spree/market.rb', line 43 def self.for_country(country, store:) return nil unless country && store joins(:market_countries) .where(store_id: store.id) .where(spree_market_countries: { country_id: country.id }) .take end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
Returns true when the market is safe to delete. A market cannot be deleted if it is the default market or the only market in the store, since Spree::Current.currency would have no fallback.
89 90 91 |
# File 'app/models/spree/market.rb', line 89 def can_be_deleted? !default? && !last_in_store? end |
#default_country ⇒ Spree::Country?
Returns the first country by name from this market’s countries
65 66 67 |
# File 'app/models/spree/market.rb', line 65 def default_country countries.order(:name).first end |
#supported_locales_list ⇒ Array<String>
Returns supported locales as an array, always including default_locale
80 81 82 |
# File 'app/models/spree/market.rb', line 80 def supported_locales_list @supported_locales_list ||= (supported_locales.to_s.split(',').map(&:strip) << default_locale).compact.uniq.sort end |
#tax_zone ⇒ Spree::Zone?
Returns the tax zone matching this market’s default country. Used by Spree::Current to determine the browsing tax zone before a customer enters an address.
73 74 75 |
# File 'app/models/spree/market.rb', line 73 def tax_zone @tax_zone ||= Spree::Zone.match(default_country) end |