Zones
Overview
The zone concept is used by Spree to assist in various calculations and reports. Zones serve as a mechanism for grouping geographic areas together into a single entity. Zones are used by the core system (for tax calculation) but they are also available to custom extensions that may require them.
Elements
A zone consists of one or more members. All of a zone’s members must be the same type. The three zone member types are country, state and zone.
Building a Zone
- Click on the “Configuration” tab in the admin menu.
- Click the “Zone” link.
- Click “New Zone”
- Enter a name for the zone (ex. “Nordic Countries”)
- Enter a description for the zone (ex. “The five countries that comprise Northern Europe”)
- Chose the type of zone (ie. the type of zone members you wish to add.)
- Enter the name of the zone member you wish to add (ex. “Norway”)
- The field uses a “suggest” feature which will narrow down your choices as you go.
- If you are adding state/province members they must already exist before trying to add them to the zone (Spree comes with only a limited number of states in its database.)
- You must choose a valid entry from the list of presented choices (invalid entries will be discarded.)
- Click “Add Country”|”Add State”|”Add Zone” to add additional members.
- Click “Create” to save the new zone.
Updating an Existing Zone
Updating zones works in a manner similar to creation. There are few minor differences to be aware of.
- It is possible to change an existing zone’s type (you will need to add new members of course.)
- Any zone member that is removed from the list will be deleted once you click “Update.”
Zone Types
Country
A zone can consist of one or more countries. An example of a zone you might wish to create would be “Nordic Countries.” It would consist of five zone member countries: Denmark, Finland, Iceland, Norway and Sweden.
State
A zone can also consist of one or more states. If you wish to include all of the states then it makes sense to just use a country based zone instead. The states must exist in the database before attempting to add them to the zone. New states can be added by the “Configuration” tab and then clicking “States.”
Zone
A zone can also consist of other zones. The only requirement here is that zone members are all zones. It does not matter what type of zone each zone member is – only that they are all zones. Using the zone type allows you to achieve fine grained control of your zones. For instance, if you needed a “foo” zone that included the United States, France, Germany but excluded New York state you could achieve this by creating three zones.
- Zone 1: USA (minus NY)
- Zone Type: State
- Members : Alabama, Alaska, Arizona …. Wyoming (all 49 states except New York)
- Zone 2: FR + DE
- Zone Type: Country
- Members : France, Germany
- Zone 3: Foo Zone
- Zone Type: Zone
- Members : USA (minus NY), FR + DE
Future Direction
There are some interesting implications with zones as far as reporting goes. Now that Rails 2.1 is supported we can do some cool things with named scope. In the near future it should be possible to do things like:
Customer.in_zone(zone).all Customer.recently_logged.spend_more_than_10000_eur.in_zone(zone)