Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Urgent Create xml file from sales order
 
macker999
Jr. Member
 
Total Posts:  26
Joined:  2009-05-06
 

Hi

I need to create an xml file from the order data on successfull completion of an order. Can anybody help me with this or point me in the right direction in relation to what core files i can modify or abstract the order data from?
I need to modify the function that completes the order so it creates the xml file and emails it but I have no idea where to find this

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Roope
Jr. Member
 
Total Posts:  1
Joined:  2009-06-17
 

I’m also very interested to get some info how to get started with this…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Do you want to actually write a file to your server or do you want to create one dynamically?

I know in MS SQL you can output your Stored Procedure as XML. I am sure you can accomplish the same thing with mySQL, this would give you dynamic XML files.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Zenlin
Member
 
Avatar
Total Posts:  51
Joined:  2008-10-02
Chicago, Il
 

As Brent said, MySQL does have that ability.

http://dev.mysql.com/doc/refman/5.1/en/mysql-command-options.html#option_mysql_xml

 
Magento Community Magento Community
Magento Community
Magento Community
 
macker999
Jr. Member
 
Total Posts:  26
Joined:  2009-05-06
 

Thanks Brent / Zenlin.

Yes i would need to write the file to the server and also i would need to write code as
1. The xml fiel has to be in a specific format (ebis basda)
2: I would need to validate the xml file against a dtd/schema.

So when a user (using the purchase payment method) completes a successful order i would need to write the xml file and then email this file to a designated email address as an attachment before the user is sent to the order complete page.

Any help at all would be greatly appreciated. I am not sure what core files are responsible for the purchase order payment methos. So if i knew then i could write some custom code to write the xml file and email it.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Macker999,

What you can do (anyone can feel free to correct me anytime) is to create module and a method you would call at the end of your transaction (When ever you decide that would occur. You can have it after they pay or after you approve the order. That part doesn’t really matter.

The call would stream the data from the database into an XML file and attached to an email. You can still do this dynamically, unless you want to keep all the XML file, but keep in mind they are already there in the database anyway!

Personally I would write all my own calls to the database and have the module do all the work on its own, it should be to much to complete this. Again, more advanced Magento programmers will have better ideas on how to interface with the database.

 
Magento Community Magento Community
Magento Community
Magento Community
 
macker999
Jr. Member
 
Total Posts:  26
Joined:  2009-05-06
 

Thanks Brent

So i could create a custom checkout module that extends the Purchase order checkout module and add methods for creating and emailing the xml file like in this wiki http://www.magentocommerce.com/wiki/how-to/create-payment-method-module?

Also i came across this article http://inchoo.net/ecommerce/magento/custom-checkout-cart-how-to-send-email-after-successful-checkout/

I would like to add this code to see it working but not sure which file to add it to. Would it be the app/code/core/mage/sales/model/order.php and if so what method would I add it to?

Thanks for your help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

I would stay away from adding anything to your code core. When you do an upgrade there is a good chance that the file you updated will disappear.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

I’m going to give a piece of hard earned advice.  Don’t screw with the checkout flow.  When you start adding code to the stages of checkout, you introduce the possibility of fatal errors preventing a customer from checking out.

You are much better using a Magento cron job and adding an extra status to indicate the order has been exported.  It’s a simple process and practically fool proof.  If the export fails for some reason, the order will be in the ‘Processing’ status and not your new status (like ‘Exported’).  I have written 3 warehouse integration modules using this method and it’s much safer than doing it during the checkout process. 

So, unless you have an absolute 100% need to have real time emailing of order XML data, just use a cron job that runs every 10 minutes and exports any new orders.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

Lee,

What is the downside of retrieving data after the fact? For example, if there checkout is complete and you simple do a select on the data he wants? To be safe he could trigger his XML export from the sent Email.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Brent,

Not sure about what you are asking.  But, but integrationg with 3rd parties during the checkout, you open yourself up to failed checkouts. 

Real world example, A client was taking payments for for 2.5 days on a site and right after payment was taken, a typo in the event listener XML config was causing Magento to throw a fatal error.  This means they charged CCs and then never recorded orders.  That was a nightmare.

Better solution is to process the orders via a cron job that has no relation to the customer.  Then, if you have a failure, it’s just the cron job and you can fix it and have the export process run again.

Lee

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top