Product
records track unique products within your store. These differ from Variants, which track the unique variations of a product. For instance, a product that’s a T-shirt would have variants denoting its different colors and sizes. Together, Products and Variants describe what is for sale.
Attribute | Description | Translatable |
---|---|---|
name | Short name for the product | Yes |
description | The most elegant, poetic turn of phrase for describing your product’s benefits and features | Yes |
slug | SEO slug based on the product name that is placed into the URL for the product. We use a library called friendly_id to generate them | Yes |
status | The status of the product. Can be draft , active , archived . Defaults to draft . | No |
available_on | The first date the product becomes available for sale online in your shop | No |
discontinue_on | Date when the product will become unavailable for sale online in your shop | No |
deleted_at | The date the product is marked as deleted. We don’t remove products entirely, only soft deleting them using a library called | No |
meta_title | Optional title used for search engines instead of name | Yes |
meta_description | A description targeted at search engines for search engine optimization (SEO) | Yes |
meta_keywords | Several words and short phrases separated by commas, also targeted at search engines | Yes |
size
, with that option type’s values being something such as Small
, Medium
and Large
.
Another typical option type could be a color
, such as Red
, Green
, or Blue
.
A product can be assigned many option types, but must be assigned at least one if you wish to create variants for that product
name
and presentation
fields for option types are translatable as of version 4.6.Variant
records track the individual variants of a Product
. Variants are of two types: master variants and normal variants.
Variant records can track some individual properties regarding a variant, such as height, width, depth, and cost price. These properties are unique to each variant, and so are different from Product Properties, which apply to all variants of that product.
Attribute | Description | Example Value |
---|---|---|
sku | Unique identifier for each variant | 123TSHRT-M-G |
barcode | Barcode code | “ |
barcode | A unique code that represents a variant, often used for scanning purposes. | 123456789 |
weight | The weight of the variant | 2 |
height | The height of the variant | 150 |
width | The width of the variant | 150 |
depth | The depth of the variant | 100 |
is_master | Indicates if the variant is a master variant | false |
track_inventory | Indicates if the inventory is tracked for this variant | true |
cost_price | The cost price of the variant | 5.00 |
cost_currency | The currency of the cost price | USD |
discontinue_on | Date when the variant will become unavailable for sale | 2023-12-31 18:00 |
after_initialize
callback of the Spree::Product
model in a ensure_master method.SKU | Size | Color |
---|---|---|
SKU-S-R | Small | Red |
SKU-S-G | Small | Green |
SKU-M-R | Medium | Red |
SKU-M-G | Medium | Green |
SKU-L-R | Large | Red |
SKU-L-G | Large | Green |
variant_images
on the product:
images
on the variant:
position
attribute, which is an integer. By default, images are ordered from left to right.
Property
should not be confused with an OptionType
, which is used when defining Variants for a product.
You can retrieve the value for a property on a Product
object by calling the property
method on it and passing through that property’s name:
set_property
method:
Property
instance with this name will be created on the fly.
value
fields are translatable.Price
objects track a price for a particular currency and variant combination. For instance, a Variant may be available for $15 (15 USD
) and €7 (7 Euro
).
Price
object contains 3 important attributes:
Attribute | Description | Example Value |
---|---|---|
amount | The current selling price of the variant in the specified currency. | 99.90 |
compare_at_amount | The recommended retail price of the variant in the specified currency. This can be used to display crossed out prices in the storefront. | 129.90 |
currency | The ISO code for the currency in which the amount and compare_at_amount are denominated. | USD |
prices
to get a list of related Price
objects:
prices
to get a list of related Price
objects:
Getting amount (number)
Getting amount (string)
Displaying price with currency symbol
OptionType
and Property
combinations amongst many different products. They work as a product template to speed up the creation of new products.
For instance, if you’re creating a lot of clothing products, you may wish to maintain the “Size” and “Color” option types, as well as a “Fitting Type” property.
Taxonomy
– a hierarchical list which is made up of individual Taxons. Each taxonomy relates to one Taxon
, which is its root node.Taxon
– a single child node which exists at a given point within a Taxonomy
. Each Taxon
can contain many (or no) sub / child taxons. Store administrators can define as many Taxonomies as required, and link a product to multiple Taxons from each Taxonomy.position
attribute.
lft
and rgt
columns in the spree_taxons
table represent the locations within the hierarchy of the item. This logic is handled by the awesome nested set gem.Classification
. This model exists so that when a product is deleted, all of the links from that product to its taxons are deleted automatically. A similar action takes place when a taxon is deleted; all of the links to products are deleted automatically.
spree.nested_taxons_path
helper method to generate full taxon URLs, which will use the taxon’s permalink, eg./t/categories/clothes/dresses
.name
and description
fields are translatable.