Sha256: 40c6ad7b779fbe5b6de4da42b61ab19dde5d196b20812422ff0b3762c110bd2f

Contents?: true

Size: 1.81 KB

Versions: 30

Compression:

Stored size: 1.81 KB

Contents

class ProductGroup < ActiveRecord::Base

  include Permalink::Builder

  validates :name, presence: true

  has_many :product_group_conditions, dependent: :destroy, extend: ProductGroupSearch::Extension

  has_many :navigations, dependent:  :destroy

  has_many :link_groups, through:    :navigations

  accepts_nested_attributes_for :product_group_conditions, allow_destroy: true

  # determines if the given product exists in the product group
  def contains?(product)
    products.include?(product)
  end

  def self.fields
    c = []
    c << { "id" => 'name', "name" => 'Name', "field_type" => 'text' }
    c << { "id" => 'price', "name" => 'Price', "field_type" => 'number' }

    CustomField.all.map do | field |
      c << field.attributes.slice("id", "name", "field_type")
    end

    c
  end

  def self.operators
    {
      text:   [{ name: 'Contains',    value: 'contains' },
               { name: 'Starts With', value: 'starts'},
               { name: 'Ends With',   value:'ends'}],

      number: [{ name: 'Equal', value: 'eq' },
               { name: 'Greater Than', value: 'gt' },
               { name: 'Grater Than Equal To', value:'gteq' },
               { name: 'Less Than', value: 'lt' },
               { name: 'Less Than Equal To', value: 'lteq'}],

      date:   [{ name: 'On', value: 'eq' },
               { name: 'After', value: 'gt' },
               { name: 'On or After', value:'gteq' },
               { name: 'Before', value: 'lt' },
               { name: 'On or Before', value: 'lteq'}],
    }
  end

  def products
    product_group_conditions.search
  end

  def summarize
    product_group_conditions.map(&:summary).join('  and ')
  end

   # list of all product groups containing input product
  def self.contains_product(product)
    all.select { | product_group | product_group.contains?(product) }
  end

end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
nimbleshop_core-0.0.23 app/models/product_group.rb
nimbleshop_core-0.0.21 app/models/product_group.rb
nimbleshop_core-0.0.20 app/models/product_group.rb
nimbleshop_core-0.0.19 app/models/product_group.rb
nimbleshop_core-0.0.17 app/models/product_group.rb
nimbleshop_core-0.0.16 app/models/product_group.rb
nimbleshop_core-0.0.15 app/models/product_group.rb
nimbleshop_core-0.0.14 app/models/product_group.rb
nimbleshop_core-0.0.14.rc2 app/models/product_group.rb
nimbleshop_core-0.0.14.rc1 app/models/product_group.rb
nimbleshop_core-0.0.13 app/models/product_group.rb
nimbleshop_core-0.0.12 app/models/product_group.rb
nimbleshop_core-0.0.11 app/models/product_group.rb
nimbleshop_core-0.0.10 app/models/product_group.rb
nimbleshop_core-0.0.9 app/models/product_group.rb
nimbleshop_core-0.0.8 app/models/product_group.rb
nimbleshop_core-0.0.7 app/models/product_group.rb
nimbleshop_core-0.0.5 app/models/product_group.rb
nimbleshop_core-0.0.4.beta1 app/models/product_group.rb
nimbleshop_core-0.0.4 app/models/product_group.rb