It can be done by using Varien_File_Csv class
Exp:
$file_path = '/your_dir_path/sample.csv';
$mage_csv = new Varien_File_Csv(); //mage CSV
$products_ids = array(1,2,3); //product ids or make array of any data
$products_model = Mage::getModel('catalog/product');
$products_row = array();
foreach ($products_ids as $pid)
{
$prod = $products_model->load($pid);
$data = array();
$data['sku'] = $prod->getSku();
$data['name'] = $prod->getName();
$data['price'] = $prod->getPrice();
$products_row[] = $data;
}
$mage_csv->saveData($file_path, $products_row);
Exp:
$file_path = '/your_dir_path/sample.csv';
$mage_csv = new Varien_File_Csv(); //mage CSV
$products_ids = array(1,2,3); //product ids or make array of any data
$products_model = Mage::getModel('catalog/product');
$products_row = array();
foreach ($products_ids as $pid)
{
$prod = $products_model->load($pid);
$data = array();
$data['sku'] = $prod->getSku();
$data['name'] = $prod->getName();
$data['price'] = $prod->getPrice();
$products_row[] = $data;
}
$mage_csv->saveData($file_path, $products_row);
Best tips to lean how to create CSV files. Thanks for sharing this. Am still a newbie on magento so this blog is helpful for me.
ReplyDeleteHi! Could you please suggest how to export a csv of invoices & order data
ReplyDelete