dev-master
9999999-dev http://www.ambimax.deMagento module that lets you export all product as array to be modified and arranged during export
The Requires
by Tobias Schifftner
Magento module that lets you export all product as array to be modified and arranged during export
Magento module that lets you export all product as array to be modified and arranged during export and saved to csv or any other format, (*1)
Copy src/* to your root folder or use composer.json:, (*2)
"require": { "ambimax/magento-module-ambimax-arrayexport": "~1.0" }
Create an Model file in app/code/comminity/My/Module/Model/Export.php, (*3)
class My_Module_Model_Export { /** @var Mage_ImportExport_Model_Export_Adapter_Csv */ protected $_writeAdapter; /** @var bool */ protected $_headerColsSet = false; /** * Init to export all products * * @param Varien_Event_Observer $observer */ public function initExport() { $file = Mage::getBaseDir('var').DS.'export'.DS.'exportfile.csv'; $this->_writeAdapter = new Mage_ImportExport_Model_Export_Adapter_Csv($file); $data = array( "entity" => 'catalog_product', "file_format" => 'csv', "export_filter" => array(), "skip_attr" => array(), ); /** @var Ambimax_ArrayExport_Model_Export $export */ $export = Mage::getModel('ambimax_arrayexport/export'); $export->setData($data); $export->export(); } /** * Writes every product to $_writeAdapter * * @param Varien_Event_Observer $observer */ public function writeRow(Varien_Event_Observer $observer) { // Set header cols if( ! $this->_headerColsSet) { $this->_writeAdapter->setHeaderCols($observer->getHeaderCols()); $this->_headerColsSet = true; } // $data contains store codes with product data $data = $observer->getProductData(); $row = $data['default']; // do something with all the data // write to csv $this->_writeAdapter->writeRow($row); } }
Create an Observer file in app/code/community/My/Module/Model/Observer.php, (*4)
This file is required so we use a Singleton at all times, otherwise the writeAdapter will not be set, (*5)
class My_Module_Model_Observer { /** * Init to export all products * * @param Varien_Event_Observer $observer */ public function initCompleteProductExport(Varien_Event_Observer $observer) { Mage::getSingleton('my_module/export')->initExport(); } /** * Write row to file * * @param Varien_Event_Observer $observer */ public function writeRow(Varien_Event_Observer $observer) { Mage::getSingleton('my_module/export')->writeRow($observer); } }
This event is supposed to handle the formation of your data and send it to your write adapter, (*6)
<events> <ambimax_arrayexport_product_row> <observers> <start_export> <class>my_module/observer</class> <method>writeRow</method> </start_export> </observers> </ambimax_arrayexport_product_row> </events>
<crontab> <jobs> <my_module_product_export> <schedule><cron_expr>0 0 * * *</cron_expr></schedule> <run> <model>my_module/observer::initExport</model> </run> </my_module_product_export> </jobs> </crontab>
MIT License, (*7)
Magento module that lets you export all product as array to be modified and arranged during export