-
-
Save bhattisatish/1613671 to your computer and use it in GitHub Desktop.
Adding new fields to Spree Variant's additional_fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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