Bah! The lack of a mySQL or any other type of SQL structure for FoxyCart’s XML datafeed on this great interwebs has prompted me to post the one I created. Feel free to use it. Save some precious time.
This FoxyCart to mySQL db design should be viewed mainly as a solid start (I certainly modified it past this) and also as a good representation of FoxyCart’s version .8 XML datafeed in a usable database structure. If you found this by searching Google, then you know what you’re looking at and know what to do with it… if otherwise, just email me. I’m glad to help.
| – phpMyAdmin SQL Dump – version 2.11.9.3 – http://www.phpmyadmin.net – – Host: coreyfoster.com – Generation Time: Mar 01, 2009 at 07:25 PM – Server version: 5.0.67 – PHP Version: 5.2.6SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;– – Database: `foxycart` —- ———————————————————- – Table structure for table `custom_field` –CREATE TABLE IF NOT EXISTS `custom_field` ( `custom_field_id` int(11) NOT NULL auto_increment, `transaction_id` int(11) NOT NULL, `custom_field_name` varchar(200) NOT NULL, `custom_field_value` varchar(200) NOT NULL, PRIMARY KEY (`custom_field_id`), KEY `transaction_id` (`transaction_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;– – Dumping data for table `custom_field` —- ———————————————————- – Table structure for table `discount` –CREATE TABLE IF NOT EXISTS `discount` ( `discount_id` int(11) NOT NULL auto_increment, `transaction_id` int(11) NOT NULL, `discount_amount` float NOT NULL, PRIMARY KEY (`discount_id`), KEY `transaction_id` (`transaction_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;– – Dumping data for table `discount` – – ——————————————————– – CREATE TABLE IF NOT EXISTS `shipto_address` ( – – ——————————————————– – CREATE TABLE IF NOT EXISTS `shipto_custom_field` ( – – ——————————————————– – CREATE TABLE IF NOT EXISTS `shipto_tax` ( – – ——————————————————– – CREATE TABLE IF NOT EXISTS `tax` ( – – ——————————————————– – CREATE TABLE IF NOT EXISTS `transaction` ( – – ——————————————————– – CREATE TABLE IF NOT EXISTS `transaction_detail` ( – – ——————————————————– – CREATE TABLE IF NOT EXISTS `transaction_detail_option` ( – |
I promise to update this post soon with a PHP example of how to get the elusive data in FoxyCart’s XML feed into the SQL structure mentioned above. Right now… I need some shut-eye.
Ah – the promised update (using SimpleXML): (thanks for the reminder, Chris)
The following code is not complete as these feeds are used in different ways per the application. I pulled this code from part of my final implementation, so it’s likely some of it will not be applicable to everyone. So pick, choose and modify from the code below to achieve your goals. As always – please contact me if you run into any snags (I know I did) or if the example is not clear.
| <?
$key = “yourkeygoeshere”; if (isset($_POST["FoxyData"])) { $FoxyData_encrypted = urldecode($_POST["FoxyData"]); $enc = mb_detect_encoding($FoxyData_decrypted); if (!mysql_connect(‘servername’, ‘username’, ‘password’)) die(“no connection to MySQL”); $today = date(“Y-m-d H:i:s”); $xml = new SimpleXMLElement($FoxyData_decrypted); // Register a new feed event foreach ($xml->xpath(‘//transaction’) as $transaction) { // Add transaction data to db // Get tax data // Get custom data // Get deeper data (discount in this case) // Get transaction detail data by id. echo “foxy”; ?> |


5 Comments
Hey Corey,
Great site first of all. I am using foxycart and want to dump the XML data to mySQL. I found a php file that foxycart provides on their wiki and it dumps all of the data into a single table row. Here is that code.
mysql_query(“INSERT INTO foxy_orders (created_at,foxy_data) VALUES (NOW(),’”.mysql_escape_string($FoxyData_decrypted)”‘)”);
The entire XML file that you document in this post is all thrown into foxy_data. How do I separate all that info and put them into their own tables like you have.
Thanks for your time.
Chris
Hey hey, Chris. Thanks for the kind words about the site… wish I had more time to update it.
I have updated the post to (hopefully) help you out. In my final code, I ended up doing a lot of custom haxxoring to achieve some project-specific goals and I have tried to remove most of that extra stuff. Depending on how familiar you are with PHP, you should have little trouble duplicating and modifying my code to break up the XML from Foxy and organize it neatly into your mySQL structure. Happy coding! And hit me up if I can help out any more.
yes
Corey, this code is absolutely brilliant. i will definitely be telling others about how much you helped me. While browsing the foxycart forums, there are quite a few people that need help doing this exact thing. I will be sure to send them here.
Thank you very much for your help.
Right on – I’m glad I could help out.