<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Magento development &#187; export</title>
	<atom:link href="http://www.ecommerceoffice.com/tag/export/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ecommerceoffice.com</link>
	<description>Magento development, programming, modules and widgets directly from professionals</description>
	<lastBuildDate>Wed, 30 May 2012 11:35:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Magento Export products in custom XML [script]</title>
		<link>http://www.ecommerceoffice.com/magento-export-products-in-custom-xml-script/</link>
		<comments>http://www.ecommerceoffice.com/magento-export-products-in-custom-xml-script/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:54:44 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[downloadable]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[products code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/?p=941</guid>
		<description><![CDATA[If you have to export all or a part of your Magento products you can try this simple script which creates a products collection and writes a simple and custom XML file per product (but you can simply change it to write a single long XML file). Hope you enjoy it! &#60;?php // Magento XML [...]]]></description>
			<content:encoded><![CDATA[<p>If you have to <a href="http://www.ecommerceoffice.com/tag/export/" class="st_tag internal_tag" rel="tag" title="Posts tagged with export">export</a> all or a part of your <a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">Magento</a> products you can try this simple script which creates a products collection and writes a simple and custom XML file per product (but you can simply change it to write a single long XML file).</p>
<p>Hope you enjoy it!</p>
<pre>&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>
// Magento XML products exporter
// Version 0.1
// by Michele Marcucci
// http://www.michelem.org

require_once 'app/Mage.<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>';
umask( 0 );
Mage::app( "default" );
Mage::app()-&gt;setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$_magentoPath = "CHANGETHISTOYOURMAGENTOPATH ex: /var/virtual/magento"
$_urlPath = "";
$_imagePath = $_urlPath . "media";
$_logFileName = "export_products.log";
$_xmlPath = $_magentoPath . "/var/export";

Mage::log( "Export start", null, $_logFileName );

// Prepare collection
$_productCollection = Mage::getModel('catalog/product')-&gt;getCollection();
$_productCollection-&gt;addAttributeToSelect('*');

/* You can change and uncomment these lines below to filter your products collection */

// Filter by updated_at date, get only daily changes
//$_productCollection-&gt;addFieldToFilter('updated_at', array('from'=&gt;date("Y-m-d", time()-86400)));

// Filter by product type, get only downloadables
//$_productCollection-&gt;addFieldToFilter('type_id',  array('like'=&gt;'<a href="http://www.ecommerceoffice.com/tag/downloadable/" class="st_tag internal_tag" rel="tag" title="Posts tagged with downloadable">downloadable</a>'));

// Filter by sku get only products with sku like "EBOOK-%"
//$_productCollection-&gt;addFieldToFilter('sku',  array('like'=&gt;'EBOOK-%'));

// Limit output to 15 records
//$_productCollection-&gt;getSelect()-&gt;limit(15);

Mage::log( "Products to be exported: " . $_productCollection-&gt;count(), null, $_logFileName );

$i = 1;
foreach ( $_productCollection as $_product ) {

	// Prepare array of variables to grow XML file
    $v['sku'] = $_product-&gt;getSku();
    $v['product_name'] = $_product-&gt;getName();
	$v['type'] = $_product-&gt;getTypeId();
    $v['description'] = $_product-&gt;getDescription();
    $v['short_description'] = $_product-&gt;getShortDescription();
    $v['meta_title'] = $_product-&gt;getMetaTitle();
    $v['meta_description'] = $_product-&gt;getMetaDescription();
    $v['meta_keyword'] = $_product-&gt;getMetaKeyword();
    $v['created_at'] = $_product-&gt;getCreatedAt();
    $v['updated_at'] = $_product-&gt;getUpdatedAt();
    $v['url_path'] = $_urlPath . $_product-&gt;geturlpath();
    $v['image'] = $_imagePath . $_product-&gt;getImage();
    $v['image_label'] = $_product-&gt;getImageLabel();
  	$v['price'] = $_product-&gt;getPrice();
   	$v['special_price'] = $_product-&gt;getSpecialPrice();
    $v['weight'] = $_product-&gt;getWeight();

	// Get the Magento categories for the product
    $categoryIds = $_product-&gt;getCategoryIds();

	foreach($categoryIds as $categoryId) {
    	$<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a> = Mage::getModel('catalog/<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a>')-&gt;load($categoryId);
    	$v['categories'][$_product-&gt;getSku()][] = $<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a>-&gt;getName();
	}

    // If product is <a href="http://www.ecommerceoffice.com/tag/downloadable/" class="st_tag internal_tag" rel="tag" title="Posts tagged with downloadable">downloadable</a> get some informations about <a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> added
    if ( $_product-&gt;getTypeId() == "downloadable" ) {
    	$_<a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> = Mage::getModel('downloadable/product_type')-&gt;getLinks( $_product );
    	foreach ( $_<a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> as $_link )
    		$v['available_formats'][$_product-&gt;getSku()][] = $_link-&gt;getTitle();
    }

	// Prepare XML file to save
	$xmlFile = $_xmlPath . "/" . $_product-&gt;getSku() . ".xml";

	$doc = new DomDocument('1.0', 'UTF-8');
	$doc-&gt;preserveWhiteSpace = false;
	$doc-&gt;formatOutput = true;	

	$root = $doc-&gt;createElement('product');
	$root = $doc-&gt;appendChild($root);

	$occ = $doc-&gt;createElement('root');
	$occ = $root-&gt;appendChild($occ);

	foreach ( $v as $fieldName =&gt; $fieldValue ) {
		$child = $doc-&gt;createElement($fieldName);
    	$child = $occ-&gt;appendChild($child);

		if ( is_array($fieldValue) ) {
			$value = $doc-&gt;createTextNode(implode( "|", $fieldValue[$_product-&gt;getSku()] ));
			$value = $child-&gt;appendChild($value);
		} else {
			$value = $doc-&gt;createTextNode($fieldValue);
			$value = $child-&gt;appendChild($value);
		}

	}

	// Save each product as XML file
	$doc-&gt;save( $xmlFile );

	Mage::log( "File " . $i . ": " . $_product-&gt;getSku(), null, $_logFileName );

	$i++;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/magento-export-products-in-custom-xml-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
