Generate a csv file

Tweet, share & co

tweet fb share g+ share

Tags


Description

using this code, you can generate a csv file with product data

Code

$file_path = “/your_custom_dir_path/sample.csv”;
//file path of the CSV file in which the data to be saved
$mage_csv = new Varien_File_Csv(); 
//product ids whose data to be written
$products_ids = array(1,2,3); 
//get products model
$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;
}
//write to csv file
$mage_csv->saveData($file_path, $products_row);

Comments