We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Just wondering what people out there are doing to store their FoxyCart transactions. I can log the XML feed, but I’m wondering if I also need to parse it out and store all the transactions... some of it depends on the client of course, but what are other people doing for this?
      • 29635
      • 361 Posts
      It kind of depends on what you need it for, but I typically pull out the transaction ID, customer ID or email address, transaction date, and whatever else is needed for searching or sorting on a per-site basis.

      Typically you may need to pull transactions by date or by user, so if you pull out those fields it’s easy enough to grab the XML in the SQL query and just parse the XML when you need to display things.

      That’s my approach, at least. Storing all the data completely would require either a NoSQL database (we use Couch and Mongo) or at least 8 separate tables if you want to go fully relational, but that’s probably overkill for most of what you’re going to want.
        Need MODx Ecommerce? Try FoxyCart!
      • 8 tables for fully normalized use? Ha... yeah, that’s overkill for us now, but we can always refer back to the XML.

        How about ways to get FoxyCart to add items to the user’s cookie so if they close their browser and come back in a couple days their cart is still full? (I think this revolves around transferring FoxyCart’s 3rd party cookies from mydomain.foxycart.com to mydomain.com so that browsers won’t reject them). Or how about ways to upsell gift-wrapping and expedited shipping to the checkout form?
          • 29635
          • 361 Posts
          Those would be questions for the FoxyCart forum. Good questions though.

          And yeah, there’s no need for fully normalized. So long as you pull out enough to be able to find and filter your transactions, you have the XML and that’s easy enough to work with once you have it.
            Need MODx Ecommerce? Try FoxyCart!
          • Yeah, I’m hitting up the FoxyCart forums too.

            I think Perl spoiled me when it comes to the ease of traversing XML. The PHP libraries seem pretty clunky by comparison... which XML parser do you use?
              • 29635
              • 361 Posts
              SimpleXML, built into PHP 5. It’s not necessarily pretty, and there’s a weird little wonky bit related to getting data out of CDATA tags, but on the whole it’s fairly easy to work with. I haven’t come across a host that can’t do PHP5 in a long long time so I don’t think there’s any reason to avoid PHP5 specific functionality. Maybe that’s just me though.
                Need MODx Ecommerce? Try FoxyCart!
                • 32674
                • 101 Posts
                If you’re familiar with the node concept of xml, you can also use xpath query language to pull data pretty painlessly and quickly from xml files. You can learn enough xpath in coupla hours to do 90% of the basic stuff you’ll want parsing xml files. It looks complex, and some of it can be, but the basic queries from root node are very easy to understand and use.

                If you post up a sample foxy xml file, im sure I or someone can help ya with the xpath queries to grab the data youre after...

                there’s lots of tuts out there on xpath too: http://www.google.com/#q=xpath+tutorial
                • Wow, this is the first time I’ve heard of the xpath query language, even though it’s W3C recommended since 1999. Presumably there is some PHP library that lets you issue xpath queries? Ooop... answered my own question: http://php.net/manual/en/simplexmlelement.xpath.php

                  SimpleXML with PHP 5 is tolerable, but man... the PHP libraries just aren’t as mature as the Perl libraries. If I had to do this again, I would seriously consider putting the FoxyCart XML parser into a dedicated Perl script instead of trying to pull it off with PHP... but then again, I did my time as a Perl dev. Nothing against PHP, but it’s not quite out of its teenage years, and admittedly, most of the time, my sites are fine with that, but there times when I need something more robust.
                    • 32674
                    • 101 Posts
                    I think if you use xpath on the data feed, you can totally avoid the cdata wonky-ness by using the LIBXML_NOCDATA parameter to remove all cdata tags before you parse, then xpath basically works as normal.


                    Assuming a truncated example foxy datafeed file of:
                    <foxydata>
                        <transactions>
                            <transaction>
                                <id><![CDATA[3247]]></id>
                                <store_id><![CDATA[9]]></store_id>
                                <transaction_date><![CDATA[2009-10-19 12:51:18]]></transaction_date>
                                <processor_response><![CDATA[Authorize.net Transaction ID:2150746594]]></processor_response>
                                <processor_response_details>
                                    <merchantReferenceCode><![CDATA[3797]]></merchantReferenceCode>
                                    <requestToken><![CDATA[Azj//wFEsrZ+43+52sqEe7OAAigjD]]></requestToken>
                                    <ccAuthReply__cvCode><![CDATA[M]]></ccAuthReply__cvCode>
                                    <ccAuthReply__authorizationCode><![CDATA[193189]]></ccAuthReply__authorizationCode>
                                    <ccAuthReply__authorizedDateTime><![CDATA[2010-04-21T04:37:29Z]]></ccAuthReply__authorizedDateTime>
                                    <ccAuthReply__avsCode><![CDATA[Y]]></ccAuthReply__avsCode>
                                    <ccAuthReply__reconciliationID><![CDATA[]]></ccAuthReply__reconciliationID>
                                </processor_response_details>
                                <customer_id><![CDATA[116]]></customer_id>
                                <is_anonymous><![CDATA[0]]></is_anonymous>
                                <customer_first_name><![CDATA[John]]></customer_first_name>
                                <customer_last_name><![CDATA[Doe]]></customer_last_name>
                                <customer_company><![CDATA[ACME Inc.]]></customer_company>
                                <customer_address1><![CDATA[555 Mulberry Dr.]]></customer_address1>
                                <customer_address2><![CDATA[#200]]></customer_address2>
                                <customer_city><![CDATA[Pleasantville]]></customer_city>
                                <!-- lots more foxy fields, info and transactions and junk snipped here -->
                            </transaction>
                        </transactions>
                    </foxydata>



                    Then running this code (note the ’LIBXML_NOCDATA’ last param)....:
                    $xml = simplexml_load_file('foxydatafeed.xml', NULL, LIBXML_NOCDATA);
                    $parsed_transactions = $xml->xpath("/foxydata/transactions/transaction"):
                    echo var_dump($parsed_transactions);
                    


                    .....will get you this in the $parsed_transactions var, all from a simple xpath query: ’/foxydata/transactions/transaction’:
                    array(1) { 
                      [0]= >  object(SimpleXMLElement)#2 (14) { 
                             ["id"]=>  string(4) "3247" 
                             ["store_id"]=>  string(1) "9" 
                             ["transaction_date"]=>  string(19) "2009-10-19 12:51:18" 
                             ["processor_response"]=>  string(39) "Authorize.net Transaction ID:2150746594"
                             ["processor_response_details"]=>  object(SimpleXMLElement)#3 (7) { 
                                    ["merchantReferenceCode"]=>  string(4) "3797" 
                                    ["requestToken"]=>  string(29) "Azj//wFEsrZ+43+52sqEe7OAAigjD" 
                                    ["ccAuthReply__cvCode"]=>  string(1) "M" 
                                    ["ccAuthReply__authorizationCode"]=>  string(6) "193189" 
                                    ["ccAuthReply__authorizedDateTime"]=>  string(20) "2010-04-21T04:37:29Z"
                                    ["ccAuthReply__avsCode"]=>  string(1) "Y" 
                                    ["ccAuthReply__reconciliationID"]=>  object(SimpleXMLElement)#5 (1) {[0]=>  string(0) "" }} 
                              ["customer_id"]=>  string(3) "116" 
                              ["is_anonymous"]=>  string(1) "0" 
                              ["customer_first_name"]=>  string(4) "John" 
                              ["customer_last_name"]=>  string(3) "Doe" 
                              ["customer_company"]=>  string(9) "ACME Inc." 
                              ["customer_address1"]=>  string(16) "555 Mulberry Dr." 
                              ["customer_address2"]=>  string(4) "#200" 
                              ["customer_city"]=>  string(13) "Pleasantville" 
                              ["comment"]=>  object(SimpleXMLElement)#4 (0) { }}} 
                    


                    Now your xml doc is broken down into separated transactions --by this simple xpath:"/foxydata/transactions/transaction"-- and all your fields for each transaction are also separated and parsed into array vars, and ready to do wutevah with.... smiley

                    ....stuff them into quickbooks. Save to db. Save to human readable flat files. Print them out, let your dog eat them. Send them to the IRS. Send them to your ex so she sees how rich you’ve become and can add them to your alimony payments, etc. rolleyes