include_once './app/Mage.php';
Mage::app();
$skuFile="./var/export/skuUpdate.csv"; // The name and location of your CSV file
$skuEntry=array();
$updateHandle=fopen($skuFile, 'r');
if($updateHandle) { // If the file is found
while($skuEntry=fgetcsv($updateHandle, 1000, ",")) {
$oldSku=$skuEntry[0]; // Store the old SKU as a variable to find it in Magento's database
$newSku=$skuEntry[1]; // Store the new SKU as a variable to overwrite the old one
echo "<br>Updating ".$oldSku." to ".$newSku." - "; // Display progress messages
try {
$get_item = Mage::getModel('catalog/product')->loadByAttribute('sku', $oldSku); // Find the item in Magento's database
if ($get_item) {
$get_item->setSku($newSku)->save(); // Save the new SKU
echo "successful"; // Show success message
} else {
echo "item not found"; // Show failure message
}
} catch (Exception $e) {
echo "Cannot retrieve products from Magento: ".$e->getMessage()."<br>";
return;
}
}
}
fclose($updateHandle);