Recently, I was struggling with some Shopify products that had more than 100 variant combinations. Shopify has a product variant limitation of 100 per product, whereas products themselves are unlimited. To get around the limitation I wrote a little Node script that creates a unique Shopify product for every variant and links the SKU’s dynamically to option selectors in the product pages.
You can find the script here:
https://github.com/jestersimpps/shopify-node-excel-product-import.git
The script generates HTML for option boxes and javascript combination arrays. This content is then stored in the description body of the products using the Shopify-node API. I had to simulate randomly timed API posts since somehow I was getting errors on API POST bursts. (I’ll revise the code after some more experiments) The script creates two types of products in Shopify: ‘variants’ and ‘products’. This allows you to set custom search filters in the admin and keep the variants separate from the actual products. One product can now have unlimited ‘variants’ (which are actually Shopify products). They are linked in the variant array that is injected in the product descriptions:
How to get going:
1. Prepare the Excel file
- Add product rows in the products tab
- Add the urls to the product images (Shopify will download the images from the urls and add them to your products)
- Add product options in the options tab
- Add the option identifiers in the option column on the product page
- Generate all product variants using the VBA script in the variants page.
- When adding new products/options, new variants appear in yellow
- Add correct pricing to the variants
2. Using the xls2shop script
1. Add your Shopify credentials
2. Actions:
Removing all products:
Uploading product variants from Excel:
3. Add the following javascipt to the product pages in Shopify:
This will take care of passing the SKU of the product variant that was selected to the cart. The product description that contains the variant data is injected in the product page. It contains a selector array and a variants array. The variants array contains all the possible combinations of the selectors with the corresponding product-variant SKU.
The add to cart script can be triggered as such:
Dynamic pricing upon selection change is done by setting an element id to price
: