Archive for December, 2008

Improved Support For Adding Fields From Your Extensions

December 18 2008 by railsdog

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', :o nly => [:variant], :format => "%.2f"},
        {:name => 'Height', :o nly => [:product], :format => "%.2f"},
        {:name => 'Width', :o nly => [:product, :variant], :format => "%.2f", :populate => [:line_items]}
      ]

For more information on this new feature please visit the wiki

Goodbye attachment_fu … Hello paperclip

December 4 2008 by railsdog

Spree now uses paperclip to manage its image attachments. Up until this point we had been using the venerable attachment_fu. We were pleased enough with attachment_fu until we discovered that someone had forked Spree in Github and created a patch to use paperclip.

Well we did a little digging and found an interesting blog post. Attachment_fu relies on the mini_magick gem which the Thought Bot folks suspect causes memory issues. When we looked at it we saw the opportunity for one less gem dependency and a slightly cleaner implementation.

Bobby Santiago (bullrico) was kind enough to supply the excellent patch. He’s also made it easy to tweak so that you can upload all sorts of generic assets (not just images.)

Fair warning, the new migrations will totally reorganize your image records and move things around on your filesystem. Product images will be moved from public/images/products to public/assets/products. We’ve tested the migration the best we can but you never know what we might have missed. If you have a lot of real world assets you should back up your filesystem and database before attempting the migration.

New SEO friendly Taxonomy URLs

December 3 2008 by railsdog

Spree now features new SEO friendly URLs for browsing taxnomonies, this feature builds on top of the existing products SEO / permalink functionality to allow browsing products based on their location in a taxonomy. This is helpful for tracking how a user browsed to a particular product (ie. breadcrumbs), considering that products can have more that one taxon associated with it.

So now you can browse taxons using URLs like:

   /t/categories/clothing/
   /t/categories/clothing/shirts/t-shirts/

You can also view products with URLs like:

   /t/categories/clothing/shirts/t-shirts/p/apache-baseball-jersey
   /t/brands/apache/p/apache-baseball-jersey

A new helper method called seo_url(taxon, product) is available in the ProductsHelper to give you the correct URL using a taxon and/or product. You can call the method two ways:

  1. For taxon’s you just need to pass a taxon object:

    seo_url(@tshirt-taxon) #=> /t/categories/clothing/shirts/t-shirts/

  2. For a combined taxon and product URL you pass in both objects:

    seo_url(@apache-taxon, @apache-tshirt) #=> /t/brands/apache/p/apache-baseball-jersey

    seo_url(@clothing-taxon, @apache-tshirt) #=> /t/categories/clothing/p/apache-baseball-jersey

All taxon related customer facing views have been updated to utilize these new URLs / methods.

Spree 0.5.1 Released

December 2 2008 by railsdog

Spree 0.5.1 is a patch release for the previous 0.5.0 version. The primary improvement in this release is that Spree now supports any Rails 2.1.x version (not just Rails 2.1.2). This should help make it easier to deploy Spree on shared hosts or other environments where the programmer may be required to use a specific Rails version. We’ve also fixed the spree command in the gem so that it will now work on systems that have Rails 2.2.2 installed.

Spree does not yet support Rails 2.2.2. This just makes it possible for Spree to coexist on a system with the Rails 2.2.2 gems installed for use in other applications. The other fixes in this release are some minor deprecation issues. If you are not currently experiencing any issues with the 0.5.0 release there is no need to upgrade. The new release just makes it a little bit easier to get a new Spree instance up and running.