doug48
4/18/2017 - 1:28 PM

magento shell script csv product export

magento shell script csv product export

<?php

require_once 'abstract.php';

class Space48_Shell_Sizeinfo extends Mage_Shell_Abstract
{
    private $headers = array('SKU', 'Name', 'Size and Info');

    /**
     * Run script
     *
     */
    public function run()
    {
        $fp = fopen('/var/www/vhosts/coxandcox.co.uk/production/htdocs/var/sizeinfo.csv', 'w');
        fputcsv($fp,$this->headers);
        foreach($this->getProductCollection() as $product){
            $row = array();
            $row[] = $product->getSku();
            $row[] = $product->getName();
            $row[] = $product->getSizeInfo();
            fputcsv($fp,$row);
        }

        fclose($fp);




    }

    private function getProductCollection()
    {
        /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
        $collection = Mage::getModel('catalog/product')->getCollection();

        return $collection->addAttributeToSelect(array('sku','name','size_info'));
    }
}

$test = new Space48_Shell_Sizeinfo();
$test->run();