Magento – Export products by category name instead of category id exportmagento-1.9 How can I export products by category name instead of category id? Best Answer <?php error_reporting(E_ALL | E_STRICT); define('MAGENTO_ROOT', getcwd()); $mageFilename = MAGENTO_ROOT . '/app/Mage.php'; require_once $mageFilename; Mage::setIsDeveloperMode(true); ini_set('display_errors', 1); Mage::app(); $products = Mage::getModel("catalog/product")->getCollection(); $products->addAttributeToSelect('category_name'); $products->addAttributeToFilter('status', 1);//optional for only enabled products $products->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search $fp = fopen('exports.csv', 'w'); $csvHeader = array("sku", "category_name"); fputcsv( $fp, $csvHeader,","); foreach ($products as $product){ $sku = $product->getSku(); $categoryIds = implode('|', $product->getCategoryIds());//change the category separator if needed $_category = Mage::getModel('catalog/category')->load($categoryIds); $categoryData = $_category->getName(); fputcsv($fp, array($sku, $categoryData), ","); } fclose($fp); Put these code in root file and then run in browser it will create a csv file with category name Related SolutionsHow to Export Products with Category Names in Magento The problem I see is that $product->getCategoryIds() returns an array, and you are using it later $Id to load the category. Also you can try this instead to load the categories for the store you want: $rootId = Mage::app()->getStore($storeId)->getRootCategoryId(); $categories = Mage::getModel('catalog/category') ->getCollection() ->addFieldToFilter('path', array('like'=> "1/$rootId/%")); $categories->count(); Related Topic
Best Answer
Put these code in root file and then run in browser it will create a csv file with category name