Class: Spree::Current
- Inherits:
-
ActiveSupport::CurrentAttributes
- Object
- ActiveSupport::CurrentAttributes
- Spree::Current
- Defined in:
- app/models/spree/current.rb
Overview
Thread-safe, per-request attributes for the current store context.
All attributes are automatically reset between requests by Rails. Fallback chains ensure sensible defaults when attributes are not explicitly set.
Instance Method Summary collapse
-
#currency ⇒ String
Returns the current currency.
-
#default_tax_zone ⇒ Spree::Zone?
Returns the default tax zone (memoized per request).
-
#global_pricing_context ⇒ Spree::Pricing::Context
Returns the current global pricing context, built from store, currency, zone, and market.
-
#locale ⇒ String
Returns the current locale.
-
#market ⇒ Spree::Market?
Returns the current market, falling back to the store’s default market.
-
#price_lists ⇒ ActiveRecord::Relation<Spree::PriceList>
Returns the current price lists for the global pricing context.
-
#store ⇒ Spree::Store
Returns the current store, falling back to the default store.
-
#zone ⇒ Spree::Zone?
Returns the current tax zone.
Instance Method Details
#currency ⇒ String
Returns the current currency. Fallback: market currency -> store default currency.
26 27 28 |
# File 'app/models/spree/current.rb', line 26 def currency super || market&.currency || store&.default_currency end |
#default_tax_zone ⇒ Spree::Zone?
Returns the default tax zone (memoized per request).
46 47 48 49 50 51 52 |
# File 'app/models/spree/current.rb', line 46 def default_tax_zone result = super return result if result || @default_tax_zone_loaded @default_tax_zone_loaded = true self.default_tax_zone = Spree::Zone.find_by(default_tax: true) end |
#global_pricing_context ⇒ Spree::Pricing::Context
Returns the current global pricing context, built from store, currency, zone, and market.
65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/spree/current.rb', line 65 def global_pricing_context super || begin self.global_pricing_context = Spree::Pricing::Context.new( currency: currency, store: store, zone: zone, market: market ) end end |
#locale ⇒ String
Returns the current locale. Fallback: market default locale -> store default locale.
33 34 35 |
# File 'app/models/spree/current.rb', line 33 def locale super || market&.default_locale || store&.default_locale end |
#market ⇒ Spree::Market?
Returns the current market, falling back to the store’s default market.
19 20 21 |
# File 'app/models/spree/current.rb', line 19 def market super || store&.default_market end |
#price_lists ⇒ ActiveRecord::Relation<Spree::PriceList>
Returns the current price lists for the global pricing context.
56 57 58 59 60 61 |
# File 'app/models/spree/current.rb', line 56 def price_lists super || begin context = global_pricing_context self.price_lists = Spree::PriceList.for_context(context) end end |
#store ⇒ Spree::Store
Returns the current store, falling back to the default store.
13 14 15 |
# File 'app/models/spree/current.rb', line 13 def store super || Spree::Store.default end |
#zone ⇒ Spree::Zone?
Returns the current tax zone. Fallback: market’s tax zone (from default country) -> global default tax zone.
40 41 42 |
# File 'app/models/spree/current.rb', line 40 def zone super || market&.tax_zone || default_tax_zone end |