Sha256: f1a47d36f5a8ebb508a074d32e0e49e4fe064da9694ea49ee9c94d6af7a24213

Contents?: true

Size: 854 Bytes

Versions: 2

Compression:

Stored size: 854 Bytes

Contents

module Comable
  module ApplicationHelper
    def current_store
      @current_store || load_store
    end

    def current_customer
      @current_customer || load_customer
    end

    def current_order
      current_customer.incomplete_order
    end

    def name_with_honorific(name)
      I18n.t('comable.honorific', name: name)
    end

    def name_with_quantity(name, quantity)
      return name unless quantity
      return name if quantity <= 1
      [
        name,
        "x#{quantity}"
      ].join(' ')
    end

    private

    def load_store
      @current_store = Comable::Store.instance
    end

    def load_customer
      @current_customer = logged_in_customer
      @current_customer ||= Comable::Customer.new(cookies)
    end

    def logged_in_customer
      # Please override this method for logged in customer
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comable_core-0.2.1 app/helpers/comable/application_helper.rb
comable_core-0.2.0 app/helpers/comable/application_helper.rb