Last active
July 28, 2017 10:12
-
-
Save neilbradley/16b360f5a92b6382e11263d86fbb20cf to your computer and use it in GitHub Desktop.
export Magento Orders as XMLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('app/Mage.php'); //Path to Magento | |
umask(0); | |
Mage::app(); | |
// Run you code here | |
$orderCollection = Mage::getModel('sales/order')->getCollection(); | |
$fromDateStart = '2017-01-01'; | |
$toDateEnd = '2017-07-24'; | |
$fromDate = date('Y-m-d H:i:s', strtotime($fromDateStart)); | |
$toDate = date('Y-m-d H:i:s', strtotime($toDateEnd)); | |
$orderCollection->addAttributeToFilter('status', array('in' => array('new'))) | |
->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate)); | |
$orders = $orderCollection->getItems(); | |
$dom = new DOMDocument('1.0', 'UTF-8'); | |
$header = $dom->createElement("header"); | |
foreach ($orders as $order) { | |
$array = $order->toArray(); | |
$xml = new SimpleXMLElement('<OrderRequest/>'); | |
//necessary to flip keys/values for conversion | |
$array = array_flip($array); | |
array_walk_recursive($array, array($xml, 'addChild')); | |
//Output the XML for debugging | |
//print $xml->asXML(); | |
//Output orders to XML file (1 file per order) for debugging/possible as backup too | |
$exportDir = '/var/www/vhosts/site/var/export/orders/'; | |
file_put_contents( | |
$exportDir.$order->getIncrementId().'.xml', | |
$xml->asXML() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment