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
-
#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
55 56 57 58 59 |
# File 'app/models/spree/market.rb', line 55 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
42 43 44 45 46 47 48 49 |
# File 'app/models/spree/market.rb', line 42 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
#default_country ⇒ Spree::Country?
Returns the first country by name from this market’s countries
64 65 66 |
# File 'app/models/spree/market.rb', line 64 def default_country countries.order(:name).first end |
#supported_locales_list ⇒ Array<String>
Returns supported locales as an array, always including default_locale
79 80 81 |
# File 'app/models/spree/market.rb', line 79 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.
72 73 74 |
# File 'app/models/spree/market.rb', line 72 def tax_zone @tax_zone ||= Spree::Zone.match(default_country) end |