Improved Support For Adding Fields From Your Extensions

Adding attributes to the Variant and Product models is now supported via the additional_fields class method in the Variant model. The additional_fields method exposes an array of hash objects that contain the configuration for all fields that have been added from all extensions (including core extensions). Each field added to this array automatically gets presented on the relevant add / edit admin interfaces, and this feature should help prevent the need to override these views.

From your extension class you can add to the variant and / or product models by adding a hash for each value, like:


    Variant.additional_fields += [
        {:name => 'Weight', :only => [:variant], :format => "%.2f"},
        {:name => 'Height', :only => [:product], :format => "%.2f"},
        {:name => 'Width', :only => [:product, :variant], :format => "%.2f", :populate => [:line_items]}
      ]

For more information on this new feature please visit the wiki

blog comments powered by Disqus

This project is maintained by a core team of developers and is freely available for commercial use under the terms of the New BSD License.

Spree, Spree Commerce and the Spree logo are all trademarks of Spree Commerce, Inc.