Skip to content

Instantly share code, notes, and snippets.

@0-Sony
Last active August 12, 2016 13:02
Show Gist options
  • Save 0-Sony/fa5850a7fbb19e5193c1 to your computer and use it in GitHub Desktop.
Save 0-Sony/fa5850a7fbb19e5193c1 to your computer and use it in GitHub Desktop.
Change Name Category programmaticaly
<?php
/** Location : Namespace/module/data/namespace_module_setup/install-0.1.0.php
try {
$storeId = 4 // your target store;
/**
* Set the right Store
*/
Mage::app()->setCurrentStore($storeId);
$_helperCategory = Mage::helper('catalog/category');
/**
* Retrieves the categorie of the current store
*/
$cats = $_helperCategory->getStoreCategories();
/**
* Switch to the Admin Store to save
*/
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$categoryModel = Mage::getModel('catalog/category');
foreach ($cats as $cat) {
/** retrieves your category by what you want */
if ($cat->getName() == 'Old Custom Name') {
$categoryModel->setStoreId(0);
$categoryModel->load($cat->getId());
$categoryModel->setName('My New Custom Name')->save();
}
}
} catch (Exception $e) {
// Silence is golden
Mage::logException($e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment