save product data in csv magento


<?php
//thanks to : http://blog.decryptweb.com/csv-file-magento/
    include $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';
    Mage::app('default');
    echo "<br />Started";
    $file_path = 'C:\\xampp\htdocs\your store/sample.csv'; //file path of the CSV file in which the data to be saved

    $mage_csv = new Varien_File_Csv(); //mage CSV
    $products_ids = array(1,2,3); //product ids whose data to be written
    $products_model = Mage::getModel('catalog/product'); //get products model
    $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;
    }
        echo '<pre>';
        print_r($products_row);
        echo '</pre>';
     //write to csv file
    //$mage_csv->saveData($file_path, $products_row); //note $products_row will be two dimensional array
    echo "<br />Completed";
?>

Share on Facebook




About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools