Can i ask has anyone fould a way to export orders to an xml file. We are looking for a solution so we can export orders into a different offline system
Paul
Paul
This can easily be done with PHP's XML library. You can export all the order details to an XML file and place the file on your server in it's own folder. The shipping people can then access that folder and download it to their system.
The code will be placed in: catalog/model/checkout/order.php
NOTE: THIS CODE WILL NEED TO BE EDITED FOR YOUR OWN VERSION. This is code I did on a 1.5.1.3. It is however accurate and does work:
The code will be placed in: catalog/model/checkout/order.php
NOTE: THIS CODE WILL NEED TO BE EDITED FOR YOUR OWN VERSION. This is code I did on a 1.5.1.3. It is however accurate and does work:
Code: Select all
//BEGIN XML DATA EXPORT HERE
$date=date($language->get('date_format_short'), strtotime($order_info['date_added']));
//Initial variables for shipping
$xml = new XMLWriter;
$xml->openMemory();
$xml->setIndentString(' ');
$xml->setIndent(true);
$xml->startDocument();
$xml->startElement('PURx_REGULAR_Order');
//Write Static Elements
$xml->writeAttribute('version', '1');
$xml->writeAttribute('encoding', 'utf-8');
$xml->writeAttribute('xmlns', 'http://xspf.org/ns/0/');
$xml->writeElement('OrderDate', $date);
$xml->writeElement('OrderID', $order_id);
$xml->writeElement('OrderTotal', $result['text']);
$xml->writeElement('FirstName', $order_info['firstname']);
$xml->writeElement('LastName', $order_info['lastname']);
$xml->writeElement('Email', $order_info['email']);
$xml->writeElement('Phone', $order_info['telephone']);
$xml->writeElement('Shipping-Address1', $order_info['shipping_address_1']);
$xml->writeElement('Shipping-Address2', $order_info['shipping_address_2']);
$xml->writeElement('Shipping-City', $order_info['shipping_city']);
$xml->writeElement('Shipping-State', $order_info['shipping_zone']);
$xml->writeElement('Shipping-Zipcode', $order_info['shipping_postcode']);
$xml->writeElement('Shipping-Country', $order_info['shipping_country']);
//Set up array for items in the order
foreach ($order_product_query->rows as $product) {
$xml->startElement('item');
$xml->writeElement('orderid',$order_id);
$xml->writeElement('name', $product['name']);
$xml->writeElement('model', $product['model']);
$xml->writeElement('quantity', $product['quantity']);
$xml->writeElement('unitprice',$xmlprice);
$xml->endElement();
}
$xml->endElement();
$xml->endDocument();
$doc = $xml->flush();
file_put_contents('/home/purx/public_html/dataXMLORD/Order'.'_'.$order_id.'.'.'xml', $doc);
}
Locks nice! :-)avvici wrote:This can easily be done with PHP's XML library. You can export all the order details to an XML file and place the file on your server in it's own folder. The shipping people can then access that folder and download it to their system.
The code will be placed in: catalog/model/checkout/order.php
NOTE: THIS CODE WILL NEED TO BE EDITED FOR YOUR OWN VERSION. This is code I did on a 1.5.1.3. It is however accurate and does work:Code: Select all
//BEGIN XML DATA EXPORT HERE $date=date($language->get('date_format_short'), strtotime($order_info['date_added'])); //Initial variables for shipping $xml = new XMLWriter; $xml->openMemory(); $xml->setIndentString(' '); $xml->setIndent(true); $xml->startDocument(); $xml->startElement('PURx_REGULAR_Order'); //Write Static Elements $xml->writeAttribute('version', '1'); $xml->writeAttribute('encoding', 'utf-8'); $xml->writeAttribute('xmlns', 'http://xspf.org/ns/0/'); $xml->writeElement('OrderDate', $date); $xml->writeElement('OrderID', $order_id); $xml->writeElement('OrderTotal', $result['text']); $xml->writeElement('FirstName', $order_info['firstname']); $xml->writeElement('LastName', $order_info['lastname']); $xml->writeElement('Email', $order_info['email']); $xml->writeElement('Phone', $order_info['telephone']); $xml->writeElement('Shipping-Address1', $order_info['shipping_address_1']); $xml->writeElement('Shipping-Address2', $order_info['shipping_address_2']); $xml->writeElement('Shipping-City', $order_info['shipping_city']); $xml->writeElement('Shipping-State', $order_info['shipping_zone']); $xml->writeElement('Shipping-Zipcode', $order_info['shipping_postcode']); $xml->writeElement('Shipping-Country', $order_info['shipping_country']); //Set up array for items in the order foreach ($order_product_query->rows as $product) { $xml->startElement('item'); $xml->writeElement('orderid',$order_id); $xml->writeElement('name', $product['name']); $xml->writeElement('model', $product['model']); $xml->writeElement('quantity', $product['quantity']); $xml->writeElement('unitprice',$xmlprice); $xml->endElement(); } $xml->endElement(); $xml->endDocument(); $doc = $xml->flush(); file_put_contents('/home/purx/public_html/dataXMLORD/Order'.'_'.$order_id.'.'.'xml', $doc); }
I´m using version 1.5.3.1... What changes do I need to do to make it work? :-)
I changed my "file_put_contents" and added the folder but the file is not created in the folder.
Sorry for my ignorance :-/
// J
Dear Avvici,
Could you give me a indication where you have or had that piece of script running, in wich function? I cant really produce any errors with your code and i also placed in multiple regions in order.php but with no luck.
There is alot of documentation on the internet but i couldnt find one that really felt like a good source perhaps a suggestion?
Also, is it possible that maybe my results are beeing blocked by restrictions serverwise ?
Thx in Advance
Could you give me a indication where you have or had that piece of script running, in wich function? I cant really produce any errors with your code and i also placed in multiple regions in order.php but with no luck.
There is alot of documentation on the internet but i couldnt find one that really felt like a good source perhaps a suggestion?
Also, is it possible that maybe my results are beeing blocked by restrictions serverwise ?
Thx in Advance
Online Media Development
http://www.vuuredesign.nl/
This script is running on this website http://www.purxhealth.com, and runs well. I would be happy to help you get yours running but you have to email me at joe@opencartvqmods.comroche2013 wrote:Hello i tried the explanation (sorry for bad 3rd language) but the export folder is empty, can u show me the order.php?
Joe
Hi Avvici,
Do you think it'd also be possible to build an XML feed with customer data using this technique?
You've already seen the site I'm working on (the MijoShop one this last week where we've added the recurring payments mod), our goal is to feed this data into a mapping extension to show how geographically diverse my client's customers are.
Is that do-able, do you think?
Regards,
Kelsey
Do you think it'd also be possible to build an XML feed with customer data using this technique?
You've already seen the site I'm working on (the MijoShop one this last week where we've added the recurring payments mod), our goal is to feed this data into a mapping extension to show how geographically diverse my client's customers are.
Is that do-able, do you think?
Regards,
Kelsey
Who is online
Users browsing this forum: No registered users and 14 guests