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
- #channel ⇒ Object
-
#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
#channel ⇒ Object
17 18 19 |
# File 'app/models/spree/current.rb', line 17 def channel super || (self.channel = store&.default_channel) end |
#currency ⇒ String
Returns the current currency. Fallback: market currency -> store default currency.
30 31 32 |
# File 'app/models/spree/current.rb', line 30 def currency super || market&.currency || store&.default_currency end |
#default_tax_zone ⇒ Spree::Zone?
Returns the default tax zone (memoized per request).
50 51 52 53 54 55 56 |
# File 'app/models/spree/current.rb', line 50 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.
69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/spree/current.rb', line 69 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.
37 38 39 |
# File 'app/models/spree/current.rb', line 37 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.
23 24 25 |
# File 'app/models/spree/current.rb', line 23 def market super || store&.default_market end |
#price_lists ⇒ ActiveRecord::Relation<Spree::PriceList>
Returns the current price lists for the global pricing context.
60 61 62 63 64 65 |
# File 'app/models/spree/current.rb', line 60 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.
44 45 46 |
# File 'app/models/spree/current.rb', line 44 def zone super || market&.tax_zone || default_tax_zone end |