Exporting USPS Orders From X-Cart to Endicia
I mentioned in the last edition of the WebbyOnline Newsletter that I was giving Endicia a try. Endicia is a service with an accompying program called Dazzle that allows quick usage of the United States Portal Service. It can be used for preparing your business mailings, but I am interested in using it to automate USPS orders placed on my ecommerce store over on PCMech. In the past, we used Stamps.com. Stamps.com is pretty good, but doesn’t offer as much for the money as Endicia. I had cancelled Stamps.com due to our switch to UPS, however we found before too long that the higher cost of UPS scared some customers off. So, now, we make USPS appear first as the shipping option but allow the customer to pay the extra cost of UPS if they want the tracking information. Now that our volume of USPS shipments has gone back up, we’re in need of an automated method of handling shipments.
So, having Dazzle installed on the local computer, we want a quick way to export USPS orders from X-Cart (the store software we use) and import them into Dazzle. Luckily, Dazzle supports printing postage labels directly from an XML file. You need to have the premium service with Endicia to use this service along with Dazzle Designer. You can find the PDF document here that describes the XML fields needed to make this work. With that as your reference, let me give you a big head start here on getting this done for your X-Cart store:
- Here is the source PHP code for the export. Note that I had to make this code a little more generic than the one I am using because I use my own database abstraction layer, etc. However, this is the logic I am using.
- In the source code, you may want to modify the $shipfromlocal variable. I used this because I have some products in my store which are not shipped from my office but are shipped from a supplier in California. I obviously don’t want to export those because we don’t ship them. If you ship everything in your store, then you can comment out that variable. If you do, make sure you modify the queries that use it otherwise you will get an SQL error.
- Also in the source code, you can modify the $customdesc variable. These are the item descriptions used on US Customs forms. Since I did not want these to be the same as the actual product names, I used this array to define names which are more vague for the purposes of customs.
- Finalize your PHP file and upload into your X-Cart admin directory.
- Next, log into your X-Cart store and go to the orders.tpl template in the “main” folder of your active skin. In that template, you can add a button next to the order search buttons that will directly call this new PHP file. When you are done, you can click that button and you’ll get an XML export of any new USPS shipments.
This script essentially looks for any orders with USPS specified as the shipping method where the order is in “Processed” status. You may need to modify this to suit your needs, but I couldn’t find anything that did this. Hopefully this can give you a head start.
To use it in Dazzle, you would go to File > Print From > External File. Select the XML file. Dazzle will immediately import the XML file, verify all the addresses, and begin printing postage labels. You will, of course, want to make sure you have any templates set up before doing this. Dazzle just begins printing.
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.





Hi, the link for the php code is broken. Would you be able to restore the link for Exporting USPS Orders From X-Cart to Endicia.