Module: Spree::StoreDataSources
- Extended by:
- ActiveSupport::Concern
- Included in:
- Store
- Defined in:
- app/models/concerns/spree/store_data_sources.rb
Overview
Where a store gets its prices and stock levels from.
The preference stores the provider's registry key rather than a class
name, because the same string is written to
spree_line_items.price_source — an order has to be able to say where its
price came from years later, and a class name is not a stable thing to keep
in a data column.
An unregistered key resolves to Internal rather than raising: a provider gem being uninstalled must not take checkout down with it, and the merchant sees the setting fall back in the admin.
Constant Summary collapse
- INTERNAL_KEY =
'internal'.freeze
Instance Method Summary collapse
-
#internal_inventory? ⇒ Boolean
True when stock levels come from Spree's own records.
-
#internal_pricing? ⇒ Boolean
True when prices come from Spree's own catalog.
-
#inventory_failure_policy ⇒ String
'fallback' or 'strict'.
- #inventory_provider_instance ⇒ Spree::InventoryProvider::Base
-
#pricing_failure_policy ⇒ String
'fallback' or 'strict'.
-
#pricing_provider_instance ⇒ Spree::PricingProvider::Base
Deliberately not memoized.
Instance Method Details
#internal_inventory? ⇒ Boolean
Returns true when stock levels come from Spree's own records.
50 51 52 |
# File 'app/models/concerns/spree/store_data_sources.rb', line 50 def internal_inventory? inventory_provider_instance.is_a?(Spree::InventoryProvider::Internal) end |
#internal_pricing? ⇒ Boolean
Returns true when prices come from Spree's own catalog.
45 46 47 |
# File 'app/models/concerns/spree/store_data_sources.rb', line 45 def internal_pricing? pricing_provider_instance.is_a?(Spree::PricingProvider::Internal) end |
#inventory_failure_policy ⇒ String
Returns 'fallback' or 'strict'.
61 62 63 64 |
# File 'app/models/concerns/spree/store_data_sources.rb', line 61 def inventory_failure_policy preferred_inventory_provider_failure_policy.presence || Spree::ProviderFailurePolicy::DEFAULT_INVENTORY_POLICY end |
#inventory_provider_instance ⇒ Spree::InventoryProvider::Base
38 39 40 41 42 |
# File 'app/models/concerns/spree/store_data_sources.rb', line 38 def inventory_provider_instance resolve_provider( Spree.inventory_providers, preferred_inventory_provider, Spree::InventoryProvider::Internal ).new end |
#pricing_failure_policy ⇒ String
Returns 'fallback' or 'strict'.
55 56 57 58 |
# File 'app/models/concerns/spree/store_data_sources.rb', line 55 def pricing_failure_policy preferred_pricing_provider_failure_policy.presence || Spree::ProviderFailurePolicy::DEFAULT_PRICING_POLICY end |
#pricing_provider_instance ⇒ Spree::PricingProvider::Base
Deliberately not memoized. A store object outlives a preference change —
a merchant switching provider in the admin, a job holding a store for
hours — and a cached instance would keep answering from the old setting.
Construction is a registry lookup and an argless new.
31 32 33 34 35 |
# File 'app/models/concerns/spree/store_data_sources.rb', line 31 def pricing_provider_instance resolve_provider( Spree.pricing_providers, preferred_pricing_provider, Spree::PricingProvider::Internal ).new end |