A Spree extension that provides the ability to import products from an xlsx file to any ecommerce application irrespective of the business they cater. Including the association between the models.
-
Add this extension to your Gemfile with this line:
gem 'spree_import_products'
-
Install the gem using Bundler
bundle install
-
Copy & run migrations
bundle exec rails g spree_import_products:install
-
Restart your server
If your server was running, restart it so that it can find the assets properly.
Product_import_demo.mp4
Spree's syntactic sugar, allows us to add associated model for products like Taxon trees, Option Types Variants, Product Properties and bulk upload of images.
To define variants in spree, first we need to have option types linked to a product.
Ex:- Color, Size, Material
To create a variant we have option values againt option types.
Ex:- For type Color we have Red,Blue,Green as option values.
This example demonstrates how to create Variants from a single OptionType from within a single column, using an embedded syntax.
'Option Types'
size:small|size:medium|Size:Large
So in the above example we will end up with 3 variants('|') which will be as follows:
Variant 1: size:small
Variant 2: size:medium
Variant 3: size:large
To create a Variant with both size and colour use the delimiter ';' to indicate a composite variant required.
'|' still delimits Variants for a specific OptionType
EX:-
'Option Types'
size:small;colour:blue|size:medium;colour:green|size:large;colour:red
If no such size or colour OptionType exists then a new one is created with the supplied name.
So in the above example we will end up with 3 variants('|') which are as follows:
Variant 1: size:small, colour:blue
Variant 2: size:medium, colour:green
Variant 3: size:large, colour:red
Properties are snippets of text, which tell us more about the product.
As for all associations can contain multiple name/value sets in default form :
Property:display_value|Property:display_value
For EX:-
brand:Bluebash|technology:ROR
So in the above example we will end up with two properties which are as follows:
Property 1: brand:Bluebash
Property 2: technology:ROR
Multiple instances of a has_many association can be created via separating each instance with | in a single column.
To understand the taxon creation from a single column, we first need to understand the delimeters we would be using which are as follows
'>' To create nested taxons
'|' To create multiple taxons
For example, to create 3 Taxons, where "Company" is parent to "Software Development", and "Software Development" parent to Languages
Company>Software development>Languages
And if we want to create two taxon trees we will seperate the second taxon tree with "Pipe Symbol"('|'), and your taxon column will look like:
Company>software development>Languages | Company>Mobile App development>Framework
CountOnHand and Image column should have same number of values as we have in variant's column, seperated by pipe symbol('|)
Ex: If we have 3 variants, then the CountOnHand and Image column will have values like:
Variant(column) - size:small;colour:blue|size:medium;colour:green|size:large;colour:red
CountOnHand(column) - 1|4|6
Image(column) - link1|link2|link3
Whenever we import_product, the taxcategory and shippingcategory name will be appended with the store name. For ex: TaxCategory(column) - 'US-VAT' ShippingCategory(column) - 'Delicate'
Lets say your store name is Store1, then your assigned taxcategory and ShippingCategpry after product import will be US-VAT_Store1 and Delicate_Store1 respectively.
First bundle your dependencies, then run rake
. rake
will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using rake test_app
.
bundle update
bundle exec rake
When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:
require 'spree_import_products/factories'
bundle exec gem bump -p -t
bundle exec gem release
For more options please see gem-release README
If you'd like to contribute, please take a look at the instructions for installing dependencies and crafting a good pull request.
Copyright (c) 2022 [name of extension creator], released under the New BSD License