Last active
March 21, 2016 21:36
-
-
Save nflint/48fb038ea0f568112b6b to your computer and use it in GitHub Desktop.
Magento Sku Cleanup Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Thanks to: http://stackoverflow.com/questions/28350783/how-to-replace-the-sku-number-for-5000-products-in-magento | |
# Create a CSV File with column "old_sku" in the first column, and "new_sku"in the second column. | |
include_once './app/Mage.php'; | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$updates_file="sku-cleanup.csv"; | |
$sku_entry=array(); | |
$updates_handle=fopen($updates_file, 'r'); | |
if($updates_handle) { | |
while($sku_entry=fgetcsv($updates_handle, 1000, ",")) { | |
$old_sku=$sku_entry[0]; | |
$new_sku=$sku_entry[1]; | |
echo "<br>Updating ".$sku_entry[2].": ".$old_sku." to ".$new_sku." - "; | |
try { | |
$get_item = Mage::getModel('catalog/product')->loadByAttribute('sku', $old_sku); | |
if ($get_item) { | |
$get_item->setSku($new_sku)->save(); | |
echo "successful"; | |
} else { | |
echo "item not found"; | |
} | |
} catch (Exception $e) { | |
echo "Cannot retrieve products from Magento: ".$e->getMessage()."<br>"; | |
return; | |
} | |
} | |
} | |
fclose($updates_handle); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you add a name column it will allow you to monitor the process. You csv should look something like this: