Skip to content

Instantly share code, notes, and snippets.

@bhattisatish
Forked from teeparham/yoursite_extension.rb
Created January 15, 2012 00:59
Show Gist options
  • Save bhattisatish/1613671 to your computer and use it in GitHub Desktop.
Save bhattisatish/1613671 to your computer and use it in GitHub Desktop.
Adding new fields to Spree Variant's additional_fields
# Samples for formatting additional Product fields in Spree Admin
# SelectField: adds a select box with values 1..20
# WideField: adds a standard text box, but with a specified size
# HugeField: adds a text area with a specified number of columns
# OptionField: adds an option field
# CheckField: adds a checkbox field.
Variant.additional_fields += [
{ :name => 'SelectField',
:only => [:product],
:use => 'select',
:value => Proc.new{ (1..20).collect{|i| [i,i]} }
},
{ :name => 'WideField',
:only => [:product],
:options => { :size => '180'}
},
{ :name => 'HugeField',
:only => [:product],
:use => 'text_area',
:options => { :cols => '100'}
},
{ :name => 'OptionField',
:only => [:product],
:use => 'select',
:value => Proc.new {OptionType.all.collect {|o| [ o.name, o.name ] }}
},
{ :name => 'Featured',
:only => [:product],
:use => 'check_box',
:checked_value => "1",
:unchecked_value => "0"
}
]
# These the above lines in your extension activate method.
Product.class_eval do
named_scope :featured, { :conditions => "products.featured = '1'" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment