Skip to content

Spree Specific Loader Syntax

tom statter edited this page Jan 22, 2015 · 3 revisions

Spree Specific Loader Syntax

The Spree extra syntactic sugar, enables definition of nested Taxon trees, Option Types and complex Variants, Product Properties with optional display values, and bulk upload of Images.

OptionTypes & Variants

To define a Variant first at least one 'Option Type' must be associated with the Product, example types would be "Size" or 'Colour' or 'Pack size'

A Variant is then defined by creating an OptionValue for that OptionType. example values for type "Size" would be 'small', 'medium', 'large'

So for the loader, 'Option Types' columns can contain the OptionType to associate with the Product, plus a selection of appropriate OptionValues to go with that Type.

Simple Variants - single options

This example demonstrates how to create Variants from a single OptionType from within a single column/row, using an embedded syntax. we could supply 2 OptionTypes (called size & colour), with a selection of values (such as small, medium, large etc)

'Option Types'
size:small,medium,large|colour:red,white

If no such size or colour OptionType exists then a new one is created with the supplied name.

Next the OptionValues are also parsed, again if no such OptionValue exists, e.g small, then a new one is created with the supplied name.

Lastly a Variant is created on each OptionValue, with price and availaable dates being copied from Master.

SO in this example we end up with 5 Variants, small,medium,large,red,white

N.B Currently a unique SKU is created by incrementally adding an index to the master's sku.

Remember you could get same effect, specifying all 5 in separate, multiple columns if you prefer e.g.

'Option Types'|'Option Types'|'Option Types'|'Option Types'|'Option Types'
size:small      size:medium      size:large   colour:red       colour:white

Complex Variants - Multiple Option Types

To create a Variant with both size and colour use the delimiter ';' to indicate a composite variant required.

'|' still delimits Variants and ',' delimits values for a specific OptionType

Some examples

mime_type:jpeg;print_type:colour => One variant with 2 option types + values

mime_type:jpeg,PDF;print_type:colour,black_white => 2 variants with 2 option types + 2 values

mime_type:jpeg,PDF;print_type:colour => 2 variants with 2 option types + still with 2 values

Note how on the last one the colour values is applied to both. When there is a mismatch in the number of values for each option type, we apply the smaller one (colour) to all the other.

Hence the last one is equivalent to :

mime_type:jpeg;print_type:colour | mime_type:PDF;print_type:colour

For more examples and example CSV see spec/spree_loader_spec.rb :

spec it "should create Variants with MULTIPLE option types from single column"

TODO - Enable a hash of attributes to be supplied in association columns to enable more control over creation of associated objects.

Properties

The properties to associate with this product. Properties are for small snippets of text, shared across many products, and are for display purposes only.

An optional display value can be supplied to supplement the displayed text.

As for all associations can contain multiple name/value sets in default form :

Property:display_value|Property:display_value

Example - No values : manufacturer|standard

Example - Display values : manufacturer:somebody else plc|standard:ISOBlah21

Tip: Multiple instances of a has_many association can be created via either multiple columns named after the association, or within a single column, by separating each instance with |

Taxons

By specifying a **Taxons **column, you dynamically create Taxons, assign them to a Product, and even create the nested tree structure by using >

For example, to create 3 Taxons, where Paintings is parent to Nature, and Nature parent to Landscape

Paintings>Nature>Landscape

You can of course also combine them with| .. so to create 2 Taxon Trees and assign the Product to them, your Taxon column would look like

Paintings>Nature>Landscape | Medium>Oils

Variants

By specifying a **Variants **or **OptionTypes **column, you dynamically create Variants, either simple one option Variants or combined into fairly complex arrangement of multiple Options

You can combine multiple OptionTypes into single Variants using ;

colour:blue;size:small | colour:red;size:medium | colour:green;size:small 

Creates 3 Variants with 2 OptionTypes each i.e Blue&Small, or Medium&Red and Small&Green

And very terse, share a single option value with multiple values of another OptionType

colour: red, green, blue, orange; size: small  => Creates 4 Variants, all with size small but individual colours

Clone this wiki locally