Module: Spree::Admin::TaxonsHelper

Included in:
TaxonsController
Defined in:
app/helpers/spree/admin/taxons_helper.rb

Instance Method Summary collapse

Instance Method Details

#taxon_sort_options_for_selectObject



17
18
19
20
21
22
23
24
# File 'app/helpers/spree/admin/taxons_helper.rb', line 17

def taxon_sort_options_for_select
  @taxon_sort_options_for_select ||= Spree::Taxon::SORT_ORDERS.map do |sort_order|
    [
      Spree.t("products_sort_options.#{sort_order.underscore}"),
      sort_order
    ]
  end
end

#taxons_options_json_array(with_automatic: false) ⇒ Object



13
14
15
# File 'app/helpers/spree/admin/taxons_helper.rb', line 13

def taxons_options_json_array(with_automatic: false)
  taxons_scope(with_automatic: with_automatic).pluck(:id, :pretty_name).map { |id, pretty_name| { id: id, name: pretty_name } }.as_json
end

#taxons_scope(with_automatic: false) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/helpers/spree/admin/taxons_helper.rb', line 4

def taxons_scope(with_automatic: false)
  @memoized_taxons_scope ||= {}
  @memoized_taxons_scope[with_automatic] ||= begin
    scope = current_store.taxons.accessible_by(current_ability).where.not(parent_id: nil)
    scope = scope.where(automatic: false) unless with_automatic
    scope
  end
end