Post by fancydressidea » Fri Sep 14, 2012 1:19 am

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


Posts

Joined
Thu Oct 21, 2010 9:56 pm

Post by Avvici » Wed Oct 03, 2012 5:45 am

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);

        } 

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by multistore » Tue Oct 23, 2012 4:03 pm

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);

        } 
Locks nice! :-)
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

Newbie

Posts

Joined
Mon Oct 22, 2012 8:23 pm

Post by robbas » Wed Mar 27, 2013 6:39 pm

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

Online Media Development

http://www.vuuredesign.nl/


New member

Posts

Joined
Fri Jul 27, 2012 6:35 pm
Location - Amsterdam

Post by roche2013 » Fri Sep 06, 2013 4:51 am

Hello i tried the explanation (sorry for bad 3rd language) but the export folder is empty, can u show me the order.php?

Newbie

Posts

Joined
Fri Sep 06, 2013 4:08 am

Post by Avvici » Wed Sep 11, 2013 12:54 am

roche2013 wrote:Hello i tried the explanation (sorry for bad 3rd language) but the export folder is empty, can u show me the order.php?
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.com

Joe

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by thinksync » Thu Sep 12, 2013 8:17 pm

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

Newbie

Posts

Joined
Fri Jul 26, 2013 5:05 am
Who is online

Users browsing this forum: No registered users and 14 guests