I used a third party service to transfer products from woocommerce to magento, but many of the products don't have SKUs.
I attempted to do this using a CSV file containing a column of IDs and a column of SKUS. Help me make this happen.
<?php
umask(0);
if (($handle = fopen("skus.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_id = $data[0];
$newsku = $data[1];
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);
if($product) {
echo 'working';
$product->setSku($newsku);
$product->save();
echo $product->getName() . ' SKU updated';
echo "\n";
}
}
}
?>