I want to export product from magento in xml file. I don't know how to write a xml file using magento lib. Please assist me for this.
-
1pradeepkumarrcs.blogspot.in/2011/12/… or use rss feed of magento– Amit Bera ♦Commented Oct 21, 2014 at 2:37
-
you can download & install Magento 1.x extension for Product XML feed for Google Merchant Center: github.com/rahuldadhich/productxmlfeed– Rahul DadhichCommented Nov 4, 2017 at 11:57
Add a comment
|
1 Answer
You don't need to write the xml using the magento lib.
Just make it a simple string.
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');
//add filters if needed.
//$collection->addAttributeToFilter('status', 1); //for example.
$padd = ' '; //4 spaces for identation
$eol = "\n"; //end of line
$xml = '<?xml version="1.0"?>'.$eol;
$xml .= '<products>'.$eol;
foreach ($collection as $product) {
$xml .= $padd.'<product>'.$eol;
$xml .= str_repeat($padd, 2).'<name>'.$product->getName().'</name>'.$eol;
$xml .= str_repeat($padd, 2).'<description><![CDATA['.$product->getName().']]></description>'.$eol;
$xml .= str_repeat($padd, 2).'<price><![CDATA['.$product->getFinalPrice().']]></price>'.$eol;
//add here all the attributes you need to export
$xml .= $padd.'</product>'.$eol;
}
$xml .= '</products>'.$eol;
//Do something with $xml - save it in a file or echo it.