Archive for July, 2009

July 31 2009

New Localizations: Dutch and Finnishby railsdog

We're please to announce two more localizations: Dutch and Finnish. The Dutch localization was contributed by Onno Schuit. The Finnish translation was generously contributed by Valafar. We are always on the lookout for new translations. If you are interested in contributing a patch, please read the guide on how to contribute.

July 30 2009

Updating Searchlogicby paulcc

Spree core now uses Searchlogic version 2.1.13 (unless a new version appears whilst I am writing). This has meant a few changes to how search and pagination are set up, but also allowed a few details of Spree to be improved at the same time. Extension developers will benefit too - the new gem is much more flexible, and easy to use. Marcin (Swistak) suggested that it might even go a fair way to providing the functionality we wanted in product groups, and I think he has a good point.

So, what's new? Searchlogic has been completely rewritten in version 2, and uses a different approach to version 1. It now focuses more on key functionality and less on reinventing the wheel, e.g. control of pagination has passed back to the pagination gems. As a result, the code has gone fromĀ  ~2300 loc to ~420 loc. However, several useful bits of functionality have been added. For more information, see the github project and the rdoc documentation.

I think there's two sides to this new version. Firstly, it provides a wide set of named scopes which you can use alongside existing ones. These are all dynamically generated, and able to follow model structure - including all associations, and to apply a range of tests to the fields identified. Here's some examples from the documentation:

  • Within a model, filtering by various tests on fields:
  • Using associations (note the change of naming convention):
  • Scopes for ordering:
  • List modifiers, eg test on a list of values for any or all hits - this is very useful (and more efficient than doing it yourself)
    User.email_like_any(["joe", "bill"])

Secondly, there's the search aspect. This allows searches to be defined on top of some base scope, and customized in various ways. The search option names follow the same pattern as the named scopes above, and can be chained together or set separately. For example:

search = => "bjohnson", :age_less_than => 30) 
search.age_gt = 20

Gotcha #1: it isn't possible in this version to over-ride the a search in the base scope by supplying options to the search, eg. check out the following example. It could be a bug.

scope = Product.ascend_by_master_price
search ="descend_by_master_price")

As for a chain of named scopes, you can get results out of a search with all, first, etc - or use some pagination library like will_paginate to handle limited fetches. See app/controllers/admin/product_controller.rb for an example of this in use.

Form handling is also much easier. There's no need to include 'admin' in the submit path (it is detected automatically), and no need for fields_for to access associated records - you just need to adjust the field names to follow the new naming convention, eg for product search, you can search for variants_sku_contains to look for a substring in the sku field of any of the product's variants. Particularly note how the check boxes have been brought within the searchlogic framework: the concepts represented by the check boxes map directly to one of the new-format searchlogic queries, so naming the box after the relevant condition is all you need to do.

Finally, if you are migrating from an earlier version, you need to run rake spree:upgrade and check that the will_paginate gem is listed in config/environment.rb, and also ensure that config/initializers/searchlogic.rb has been removed.

July 29 2009

New Spree Stores (July 2009)by railsdog

SlouchbackFour brand new Spree sites have launched this month. was built in just a few days and makes use of Amazon Flexible Payments Service as one of its interesting innovations. The site is also a little bit a head of the Spree core development since it has discounts and variant images (both of which are planned features for the next release.) was also launched this month. The creator of this project was new to Spree but was able to build this site in under a week. Interesting side note, the site is hosted on Webbynode

The Location VIP Montreal store launched this week. It lists cars for sale as well as rent. Spree can also be easily used for a small online craft business as seen in the newly launched Beca Designs shop.

July 27 2009

Improved Layout Customizationby railsdog

The edge version of Spree has new features aimed at reducing the need to override the default Spree layout template. The title, stylesheets, and logo now can all be customized without creating your own copy of the layout. These handy new features were contributed by Eliot Sykes along with the following writeup.

New Title Methods

There are some new methods for manipulating the page title: the title and set_title helper methods in Spree::BaseController.

Use set_title to set a page title either from a controller method, or a view template. You can also override the default_title and title methods in Spree::BaseController for further control.

The title method is used in application.html.erb of the new release, however if you are upgrading and want to take advantage, use this in between your <title> tags of your layout template:

<%= title %>

And to set the title in a view template:

<% set_title 'My custom title' %>

Customize Default Stylesheets

Spree::Config[:stylesheets] is a new config option for customizing the stylesheets used by the default application layout.

The value of Spree::Config[:stylesheets] is a comma-separated string of stylesheet names without the file extensions. See the customization tutorial for more information.

If you are upgrading, to take advantage of this use the new stylesheet_tags helper method.

Customized Logo

Spree::Config[:logo] is a new config option for customizing the logo image path. If you are upgrading, take advantage of this by using the new logo helper method.

July 20 2009

Webbynode Announces One-Click Spree Installby railsdog

picture-19Last week Webbynode announced that they have added Spree as a "one click install" option to their "ReadyStack." The ReadyStack is probably one of the more interesting features provided by this up and coming Rails hosting service. The Webbynode home page contains a great video explaining more about how the service works.

The Spree wiki has also been updated with a brief guide on Spree Installation With Webbynode. The installation process is actually relatively simple, the wiki is really more to give you an idea of what the process looks like.

Unfortuantely due to the overwhelming demand for Webbynode, they are temporarily sold out of new server instances. It looks like you will need to wait about a week before being able to try this service out. In the meantime, you can checkout a live instance of Spree running on the very modestly priced "256" plan. I don't have a lot of experience running Spree is such a low memory environment but it does seem to run well under modest load conditions.

July 20 2009

New on Edge: Charges and Creditsby railsdog

Spree now provides a new flexible system of charges and credits associated with orders. The orders table no longer has seperate columns for tax_total, ship_total, etc. This information is now captured more generically as a Charge. This allows a Spree application to add more then one tax or shipping charge per order as well as to support new types of charges that might be required. For instance, some products for sale (like cell phones) require a seperate activation fee.

Charges are added to the order in the Checkout model. Developers wishing to override the default behavior of Spree can now just override the update_charges method to provide their own additional logic. This snippet below shows how the Spree core adds tax related charges to an order.

  def update_charges
    # update tax (if applicable)
    tax_amount = order.calculate_tax
    if tax_amount > 0                           
      tax_charge = order.tax_charges.first
      tax_charge ||= => I18n.t(:tax))
      tax_charge.amount = tax_amount    

In addition to charges, credits are now supported. Credits are the mirror image of charges and they serve to reduce the cost of the order. The primary mechanism for adding a credit to an order is through the use of coupons. Its possible, however, that developers may wish to build their own custom logic for creating credits.

WARNING: There are significant changes to the database to support the new charge system. The migrations should update your legacy data and create the necessary tax and shipping charges for existing orders but you should backup your database before running.

July 08 2009

Spree 0.8.5 Releasedby railsdog

We've just done another patch release to Spree. This release actually contains no changes other then those that were supposed to have made it into the 0.8.4 release. Due to some "enthusiastic" git branch deletion I accidentally removed some of the changes needed for the release. So the 0.8.4 release did not really do anything other then increment the version number. This release contains the minor rake task upgrades that were supposed to be part of that release.

July 03 2009

Spree 0.8.4 Releasedby railsdog

The Spree team is proud to announce the official release of Spree 0.8.4. This is a minor patch release that takes care of a few pesky issues related to migrations and sample data. Specifically, the following issues have been fixed:

  • 494 - There are no default states for United states when you don't load sample data
  • 551 - Remove bootstrap restriction in production mode
  • 553 - Allow creation of default user through web interface
  • 550 - Seed data no longer populated correctly
  • 552 - Allow db:admin:create rake task to be run more then once

The most important change is that we have modified the migrations so that they are no longer loading so-called "seed" data (countries, states etc.) Keeping this seed data out of the migrations fixes a whole bunch of problems. You can still create everything from scratch with a single rake task

rake db:bootstrap

By popular demand, the bootstrap task is once again permissable in production mode. For safety reasons it will not drop the existing database in production mode (as it does automatically in development and test modes.)

You can also still build everything from scratch using individual rake tasks. In fact, we've created several new rake tasks so you can have fine grain control.

The following two rake tasks build an empty database with the required seed data.

rake db:migrate
rake db:seed

You can create an admin user (or an additional admin user if you already have one) using

rake db:admin:create

You can also load the sample data (assuming you don't already have it through bootstrap) using

rake db:sample
July 02 2009

New Localizations: Thai and Hebrewby railsdog

This week we have added two new localizations for Spree. Apirak Panatkool has provided the Thai localization, while ranmoshe has generously provided the Hebrew version. To find out more about Spree localization please read our documentation. We are always on the lookout for new translations. If you are interested in contributing a patch, please read the guide on how to contribute.