Module: Spree::Api::V3::ChannelResolution
- Extended by:
- ActiveSupport::Concern
- Included in:
- Store::BaseController, Store::ResourceController
- Defined in:
- app/controllers/concerns/spree/api/v3/channel_resolution.rb
Overview
Resolves the active Spree::Channel for an API request and writes it
into Spree::Current.channel so models, scopes, and serializers can
read channel context without threading it through method args.
Resolution order:
- The authenticated publishable key's channel binding
(+Spree::ApiKey#channel+) — server-assigned, cannot be overridden;
a
X-Spree-Channelheader naming a different channel is a 422 X-Spree-Channelheader value matched againstchannels.code— or, if it looks like a prefixed ID (+ch_…+), againstchannels.id— scoped to the current storecurrent_store.default_channel
The concern is a no-op if no channel matches — callers fall back to +Spree::Current.channel+'s store-default behavior.
IMPORTANT: key-bound resolution requires authenticate_api_key! to run
BEFORE set_current_channel — both Store API branches order their
callbacks accordingly (prepended in Store::BaseController, inherited
ahead of the include in Store::ResourceController).
Constant Summary collapse
- CHANNEL_HEADER =
'X-Spree-Channel'.freeze