How to bulk modify SKUs

  • Create a CSV File with Before and After SKUs In the first column, list your current SKUs and in the second column list the new SKUs.

Make sure this file is saved as a CSV file in the UTF-8 or ANSI encoding. You might run into problems with this if you create the file using Excel.

  • Put the CSV File on Your Server Upload the CSV file to the var/export directory on your Magento server so that it’s path is /var/export/skudata.csv.
  • Create the PHP Script On your server, in your Magento installation directory (the one where you see the app, var, skin, media, js and other directories), create a new file, save it, and name it updateskus.php.

=> updateskus.php :

<?php

include_once './app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$updates_file="./var/export/skudata.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 ".$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 "Sku updat successfully";
            } else {
                echo "Product Item not found";
            }
        } catch (Exception $e) {
            echo "Product can't getting from Magento: ".$e->getMessage()."<br>";
            return;
        }
    }
}
fclose($updates_handle);
?>
  • Run the Script To run the script simply use your internet browser and navigate to http://yoursite.com/updateskus.php. If you have a multi-site setup use the master or primary site as set by your hosting provider.

When you run this script, You will get message about succuessfully sku updates.

Hope, It may be helpful for you.

Tags:

Magento 1.9