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:

  1. The authenticated publishable key's channel binding (+Spree::ApiKey#channel+) — server-assigned, cannot be overridden; a X-Spree-Channel header naming a different channel is a 422
  2. X-Spree-Channel header value matched against channels.code — or, if it looks like a prefixed ID (+ch_…+), against channels.id — scoped to the current store
  3. current_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