Class: Spree::Pricing::PriceResolution

Inherits:
Object
  • Object
show all
Defined in:
lib/spree/core/pricing/price_resolution.rb

Overview

Picks the engine that answers a price, and stands between it and the rest of Spree.

This sits on the catalog read path — the Store API serializers price every row of every listing — so three things happen here rather than in each provider:

  • a provider that declines the context (+handles?+) never gets asked, so anonymous browsing stays on the local catalog even when a contract pricing system is connected;
  • an answer is cached for providers that declare a cache_ttl, keyed by the context;
  • a provider that raises is handled per the store's failure policy — strict re-raises as ProviderUnavailable so the caller decides, fallback quietly uses Spree's own price.

Defined Under Namespace

Classes: ProviderUnavailable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ PriceResolution

Returns a new instance of PriceResolution.



40
41
42
# File 'lib/spree/core/pricing/price_resolution.rb', line 40

def initialize(context)
  @context = context
end

Instance Attribute Details

#context ⇒ Object (readonly)

Returns the value of attribute context.



38
39
40
# File 'lib/spree/core/pricing/price_resolution.rb', line 38

def context
  @context
end

Class Method Details

.call(context) ⇒ Spree::Price?

Parameters:

Returns:



34
35
36
# File 'lib/spree/core/pricing/price_resolution.rb', line 34

def self.call(context)
  new(context).resolve
end

Instance Method Details

#resolve ⇒ Spree::Price?

Returns:



45
46
47
48
49
50
51
# File 'lib/spree/core/pricing/price_resolution.rb', line 45

def resolve
  return internal_price unless external_provider?

  provider_price
rescue StandardError => e
  handle_failure(e)
end