Module: Spree::Channel::Gating

Extended by:
ActiveSupport::Concern
Included in:
Spree::Channel
Defined in:
app/models/spree/channel/gating.rb

Overview

Storefront access gating for a channel. Decides what an anonymous (not-logged-in) visitor may see and whether an order may be placed without an account. Both controls fall back to the owning Store when the channel preference is unset, mirroring OrderRouting::HasStrategyPreference.

Constant Summary collapse

STOREFRONT_ACCESS =

Posture controlling catalog/price visibility for anonymous visitors:

  • public products + prices visible to anyone
  • prices_hidden products browsable, prices null for guests
  • login_required catalog reads rejected for guests
%w[public prices_hidden login_required].freeze

Instance Method Summary collapse

Instance Method Details

#resolved_guest_checkoutBoolean

Returns whether guest checkout is allowed: the channel preference, or the store fallback when the channel value is unset.

Returns:

  • (Boolean)

    whether guest checkout is allowed: the channel preference, or the store fallback when the channel value is unset.



36
37
38
39
40
41
# File 'app/models/spree/channel/gating.rb', line 36

def resolved_guest_checkout
  value = preferred_guest_checkout
  return value unless value.nil?

  store.nil? ? true : store.preferred_guest_checkout
end

#resolved_storefront_accessString

Returns the effective access posture: the channel preference, or the store fallback when unset, defaulting to public.

Returns:

  • (String)

    the effective access posture: the channel preference, or the store fallback when unset, defaulting to public.



28
29
30
31
32
# File 'app/models/spree/channel/gating.rb', line 28

def resolved_storefront_access
  preferred_storefront_access.presence ||
    store&.preferred_storefront_access.presence ||
    'public'
end

#storefront_login_required?Boolean

Returns true when guests must authenticate before browsing.

Returns:

  • (Boolean)

    true when guests must authenticate before browsing.



49
50
51
# File 'app/models/spree/channel/gating.rb', line 49

def 
  resolved_storefront_access == 'login_required'
end

#storefront_prices_hidden?Boolean

Returns true when guests must not see prices on this channel.

Returns:

  • (Boolean)

    true when guests must not see prices on this channel.



44
45
46
# File 'app/models/spree/channel/gating.rb', line 44

def storefront_prices_hidden?
  resolved_storefront_access == 'prices_hidden'
end