Sha256: 019e31658427e0f522444a251e9488d87ddc7c9766d6832bd817267440e68ada

Contents?: true

Size: 1.44 KB

Versions: 80

Compression:

Stored size: 1.44 KB

Contents

module Spree
  class ProductScope < ActiveRecord::Base
    before_validation(:on => :create) do
      # Add default empty arguments so scope validates and errors aren't caused when previewing it
      if name && args = self.class.arguments_for_scope_name(name)
        self.arguments ||= ['']*args.length
      end
    end

    def self.all_scopes
      {
        # Scopes for selecting products based on taxon
        :taxon => {
          :taxons_name_eq => [:taxon_name],
          :in_taxons => [:taxon_names],
        },
        # product selection based on name, or search
        :search => {
          :in_name => [:words],
          :in_name_or_keywords => [:words],
          :in_name_or_description => [:words],
          :with_ids => [:ids]
        },
        # Scopes for selecting products based on option types and properties
        :values => {
          :with => [:value],
          :with_property => [:property],
          :with_property_value => [:property, :value],
          :with_option => [:option],
          :with_option_value => [:option, :value],
        },
        # product selection based upon master price
        :price => {
          :price_between => [:low, :high],
          :master_price_lte => [:amount],
          :master_price_gte => [:amount],
        },
      }
    end

    def self.arguments_for_scope_name(name)
      if group = all_scopes.detect { |k,v| v[name.to_sym] }
        group[1][name.to_sym]
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 2 rubygems

Version Path
spree_core-2.1.7 app/models/spree/product_scope/scopes.rb
spree_core-2.0.11 app/models/spree/product_scope/scopes.rb
spree_core-2.0.10 app/models/spree/product_scope/scopes.rb
spree_core-2.1.6 app/models/spree/product_scope/scopes.rb
spree_core-2.2.1 app/models/spree/product_scope/scopes.rb
spree_core-2.2.0 app/models/spree/product_scope/scopes.rb
spree_core-2.1.5 app/models/spree/product_scope/scopes.rb
spree_core-2.0.9 app/models/spree/product_scope/scopes.rb
spree_core-1.3.5 app/models/spree/product_scope/scopes.rb
spree_core-2.1.4 app/models/spree/product_scope/scopes.rb
spree_core-2.0.8 app/models/spree/product_scope/scopes.rb
spree_core-2.1.3 app/models/spree/product_scope/scopes.rb
spree_core-2.0.7 app/models/spree/product_scope/scopes.rb
spree_core-2.1.2 app/models/spree/product_scope/scopes.rb
spree_core-2.0.6 app/models/spree/product_scope/scopes.rb
spree_core-1.3.4 app/models/spree/product_scope/scopes.rb
spree_core-2.1.1 app/models/spree/product_scope/scopes.rb
spree_core-2.0.5 app/models/spree/product_scope/scopes.rb
spree_core-2.1.0 app/models/spree/product_scope/scopes.rb
spree_core-2.0.4 app/models/spree/product_scope/scopes.rb