0

I need to export the following from all my products.

Sku Name Description

I have tried to use the dataflow profiles, it just has not worked for me at all. We are running at 100k products and I think its too big for that option, I have found this script though which exports sku and category_id

<?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");
fputcsv( $fp, $csvHeader,",");
foreach ($products as $product){
$sku = $product->getSku();
$categoryIds = implode('|', $product->getCategoryIds());//change the category separator if needed
fputcsv($fp, array($sku, $categoryIds), ",");
}
fclose($fp);
?>

Something like this would be ideal, but I have no idea how to modify it to export different things...

Can someone talk me through it?

1

Just add:

$products->addAttributeToSelect('name');
$products->addAttributeToSelect('description');

and then you can get them with:

$name = $product->getName();
$description = $product->getDescription();
| improve this answer | |

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.