Module: Spree::Core::ControllerHelpers::Store

Extended by:
ActiveSupport::Concern
Included in:
BaseController
Defined in:
lib/spree/core/controller_helpers/store.rb

Instance Method Summary collapse

Instance Method Details

#current_price_optionsObject

Return a Hash of things that influence the prices displayed in your shop.

By default, the only thing that influences prices that is the current order’s tax_zone (to facilitate differing prices depending on VAT rate for digital products in Europe, see github.com/spree/spree/pull/6295 and github.com/spree/spree/pull/6662).

If your prices depend on something else, overwrite this method and add more key/value pairs to the Hash it returns.

Be careful though to also patch the following parts of Spree accordingly:

  • ‘Spree::VatPriceCalculation#gross_amount`

  • ‘Spree::LineItem#update_price`

  • ‘Spree::Stock::Estimator#taxation_options_for`

  • Subclass the ‘DefaultTax` calculator



54
55
56
57
58
# File 'lib/spree/core/controller_helpers/store.rb', line 54

def current_price_options
  {
    tax_zone: current_tax_zone
  }
end

#current_storeObject



16
17
18
# File 'lib/spree/core/controller_helpers/store.rb', line 16

def current_store
  @current_store ||= current_store_finder.new(url: request.env['SERVER_NAME']).execute
end

#ensure_current_store(object) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/spree/core/controller_helpers/store.rb', line 24

def ensure_current_store(object)
  return if object.nil?

  if object.has_attribute?(:store_id)
    if object.store.present? && object.store != current_store
      raise Spree.t('errors.messages.store_is_already_set')
    else
      object.store = current_store
    end
  elsif object.class.method_defined?(:stores) && object.stores.exclude?(current_store)
    object.stores << current_store
  end
end

#store_localeObject



20
21
22
# File 'lib/spree/core/controller_helpers/store.rb', line 20

def store_locale
  @store_locale ||= current_store.default_locale
end