Class: Spree::Market

Inherits:
Object
  • Object
show all
Includes:
SingleStoreResource
Defined in:
app/models/spree/market.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_for_store(store) ⇒ Spree::Market?

Returns the default market for a store, or falls back to the first by position

Parameters:

Returns:



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

Parameters:

Returns:



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_countrySpree::Country?

Returns the first country by name from this market’s countries

Returns:



64
65
66
# File 'app/models/spree/market.rb', line 64

def default_country
  countries.order(:name).first
end

#supported_locales_listArray<String>

Returns supported locales as an array, always including default_locale

Returns:

  • (Array<String>)


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_zoneSpree::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.

Returns:



72
73
74
# File 'app/models/spree/market.rb', line 72

def tax_zone
  @tax_zone ||= Spree::Zone.match(default_country)
end