Change 'SKU' as bulk using Magmi or other
Question
I have those kind of SKU products
ABC-001-NM
ABC-002-NM
ABC-003-NM
And I want to change the SKU like that
ABC-001
ABC-002
ABC-003
I have a lot of products so I need to change as bulk way
I don't want to change database directly
and looking for using Magmi or other fast way
Solution
Try this (you should make a backup just in case, or dump the values and comment the ->save()
) :
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
if(class_exists('Mage'))
{
$products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('sku')
->addAttributeToFilter('sku', array('like', '%-NM%'));
if(count($products) > 0)
{
foreach($products as $product)
{
$product->setSku(str_replace('-NM', '', $product->getSku()));
try{
$product->save();
} catch(Exception $e){
echo $e->getMessage();
}
}
}
}
Note : You have to palce this file at the Magento's root folder. Otherwise, change the way you call app/Mage.php
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange