Here is how you use it:
- Go to the product you want to set up. (Do not add any additional variants. They will all be created automatically from the first one).
- Set the initial SKU, suggested price and price on the default variant. (do not change any of the dropdowns).
- right click on the SKU textbox and choose "inspect". (This will make sure you are in the correct inspector because this is using iFrames).
- select the "console" tab in the web developer tools and paste the following code.
- Hit enter and wait a few seconds. Everything should auto generate.
(Edit the custom code module below to get full code)
//figure out variant count based on permutations of the variant dropdowns
var totalVariantCount = 1;
for (i = 0; i < $(".propertyList select").length; i++) {
totalVariantCount = totalVariantCount * $("option", $(".propertyList select")[i]).length
}
//create all of the variants automatically
for (i = 0; i < totalVariantCount - 1; i++) {
addVariantOfType();
}
//copy intial variants price and suggested pricing
$(".price").each(function () {
$(this).val($(".price").eq(0).val());
});
$(".suggestedPrice").each(function () {
$(this).val($(".suggestedPrice").eq(0).val());
});
//auto increment SKUs by 1
$(".sKU").each(function (index) {
$(this).val($(".sKU").eq(0).val() + index);
});
//setup all the permutations and select all of the dropowns automatically accordingly
var allArgs = [];
for (i = 0; i < $(".propertyList:first .variantName").length; i++) {
var currentSelectVals = [];
for (v = 0; v < $("option", $(".propertyList:first .variantName").eq(i)).length; v++) {
currentSelectVals.push($("option", $(".propertyList:first .variantName").eq(i)).eq(v).val());
}
allArgs.push(currentSelectVals);
}
var totalPermutations = cartesian(allArgs);
for (var p = 0; p < totalPermutations.length; p++) {
$("#productVariant li:eq("+p+") select").eq(0).val(totalPermutations[p][0])
$("#productVariant li:eq("+p+") select").eq(1).val(totalPermutations[p][1])
$("#productVariant li:eq("+p+") select").eq(2).val(totalPermutations[p][2])
}
function cartesian(arg) {
var r = [], max = arg.length - 1;
function helper(arr, i) {
for (var j = 0, l = arg[i].length; j < l; j++) {
var a = arr.slice(0); // clone arr
a.push(arg[i][j]);
if (i == max)
r.push(a);
else
helper(a, i + 1);
}
}
helper([], 0);
return r;
}