Last active
December 23, 2021 10:24
-
-
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
This file contains 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 | |
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')->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()."; | |
return; | |
} | |
} | |
} | |
fclose($updates_handle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment