Skip to content

Instantly share code, notes, and snippets.

@keithgreer
Last active December 23, 2021 10:24
Show Gist options
  • Save keithgreer/ab32395f76dd4359d008fe8e06635955 to your computer and use it in GitHub Desktop.
Save keithgreer/ab32395f76dd4359d008fe8e06635955 to your computer and use it in GitHub Desktop.
Magento 1: Batch importer for Magento Product SKUs - https://keithgreer.dev/batch-importer-for-magento-product-skus
<?php
ini_set('error_reporting', E_ALL);
// Location of Mage.php relative to current script
include_once 'app/Mage.php';
Mage::app();
// Location of CSV relative to file system root
$updates_file="/magento/var/import/sku2sku.csv";
$sku_entry=array();
echo realpath(dirname(__FILE__));
$updates_handle=fopen($updates_file, 'r');
echo "1 ";
if($updates_handle) {
echo "2 ";
while($sku_entry=fgetcsv($updates_handle, 1000, ",")) {
$old_sku=$sku_entry[];
$new_sku=$sku_entry[1];
echo "Updating ".$old_sku." to ".$new_sku." - ";
try {
$get_item = Mage::getModel('catalog/product')-&gt;loadByAttribute('sku', $old_sku);
if ($get_item) {
$get_item-&gt;setSku($new_sku)-&gt;save();
echo "successful";
} else {
echo "item not found";
}
} catch (Exception $e) {
echo "Cannot retrieve products from Magento: ".$e-&gt;getMessage().";
return;
}
}
}
fclose($updates_handle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment