ylliX - Online Advertising Network

Magento FACT Finder export

Preparing such export is quite easy, so let’s begin with adding new button in products listing:

in app/code/core/Mage/Adminhtml/Block/Catalog/Product.php in _prepareLayout() function add such code:

$this->_addButton('export_fact', array(
    'label'   => Mage::helper('catalog')->__('FACT-Finder'),
    'onclick' => "setLocation('{$this->getUrl('*/*/exportfact')}')",
    'class'   => 'add'
));

then in app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php add new function:

public function exportfactAction()
{
    $productCollection = Mage::getModel('catalog/product')->getCollection();

    $csv = '"ProductID";"ProductName";"Description";"Price"'."\n";

    foreach ($productCollection as $item)
    {
        $data = $item->getData();

        $product = Mage::getModel('catalog/product')->load($data['entity_id']);

        $csv.= '"'.sprintf("%09d", $product->getId()).'";"'.$product->getName().'";"'. strip_tags($product->getShortDescription() ).'";"'.sprintf("%.2f", $product->getPrice()).'"'."\n";
    }
    $this->_prepareDownloadResponse('fact.csv', $csv);
}

and thats all. You will get new button with export ability.

Leave a Reply