0

Single product has multiple categories. Within CSV Export file only one category is listed. Does anyone know why only one category is exported?

I need an export that has all categories listed by single product. How can I achieve that?

Now:

sku,_store,_attribute_set,_type,_category,_root_category,_product_websites
5108,,Default,simple,"Beauty/Bad",Pflege,base
5109,,Default,simple,"Beauty/Bad",Pflege,base

What i need is something like this:

sku,_store,_attribute_set,_type,_category,_root_category,_product_websites
5108,Default,simple,"Beauty/Bad;"Beauty/Küche";"Beauty/Pflege",Pflege,base
5109,Default,simple,"Beauty/Bad;"Beauty/Küche";"Beauty/Pflege",Pflege,base
0

Please make a file at magento root folder and export all sku's and their all categories:

<?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_ids');
$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_ids",
    "category_name"
);
fputcsv($fp, $csvHeader, ",");
$cat_name  = array();
$cat_array = array();
$cat       = Mage::getModel('catalog/category');
foreach ($products as $product) {
    $sku         = $product->getSku();
    $categoryIds = implode('|', $product->getCategoryIds()); //change the category separator if needed
    $cat_name    = array();
    $cat_array   = $product->getCategoryIds();
    //print_r($cat_array);
    for ($k = 0; $k < count($cat_array); $k++) {
        $id = $cat_array[$k];
        $cat->load($id);
        $cat_name[] = $cat->getName();
    }
    $_cate_name = implode('|', $cat_name);
    fputcsv($fp, array(
        $sku,
        $categoryIds,
        $_cate_name
    ), ",");
}
fclose($fp);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.