This tutorial explains how to set associated products magento 1 programmatically. The program imports products with five different attributes (length, size, material, color and weightspec) and set associated products programmatically.
Click here to download the sample CSV. The products are imported from the sample CSV file. There are some products with one, other with two and three attributes.
This tutorial explains how to import magento 2 products programmatically. This tutorial shows how to initialise the import script, read data from CSV, import magento 2 products, set main and default image programmatically.