Module: Spree::Core::Scopes

Defined in:
lib/spree/core/scopes.rb

Overview

This module contains all custom scopes created for selecting products.

All usable scopes should be included in SCOPES constant, it represents all scopes that are selectable from user interface, extensions can extend and modify it, but should provide corresponding translations.

Format of constant is following:

{
  :namespace/grouping => {
    :name_of_the_scope => [:list, :of, :arguments]
  }
}

This values are used in translation file, to describe them in the interface.
So for each scope you define here you have to provide following entry in translation file
product_scopes:
  name_of_the_group:
    name: Translated name of the group
    description: Longer description of what this scope group does, inluding
      any possible help user may need
    scopes:
      name_of_the_scope:
        name: Short name of the scope
        description: What does this scope does exactly
        arguments:
          arg1: Description of argument
          arg2: Description of second Argument

Class Method Summary collapse

Class Method Details

.generate_translation(all_scopes) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/spree/core/scopes.rb', line 35

def generate_translation(all_scopes)
  result = {"groups" => {}, "scopes" => {}}
  all_scopes.dup.each_pair do |group_name, scopes|
    result["groups"][group_name.to_s] = {
      'name' => group_name.to_s.humanize,
      'description' => "Scopes for selecting products based on #{group_name.to_s}",
    }

    scopes.each_pair do |scope_name, targs|
      hashed_args = {}
      targs.each{|v| hashed_args[v.to_s] = v.to_s.humanize}

      result['scopes'][scope_name.to_s] = {
        'name' => scope_name.to_s.humanize,
        'description' => "",
        'args' => hashed_args.dup
      }
    end
  end
  result
end

.generate_translationsObject



57
58
59
60
61
62
# File 'lib/spree/core/scopes.rb', line 57

def generate_translations
  require 'ya2yaml'
  {
    'product_scopes' => generate_translation(Spree::ProductScope.all_scopes)
  }.ya2yaml
end