I have to admit, as many years as I've used FoxyCart, I've never interfaced much with the datafeed (if at all). I'm getting a little tripped up.
The only use or function I have for the datafeed at this time is to have my PHP script (after successful ordering and payment) log our database with some data indicating that a special "code" has been used/redeemed, and cannot be used again. From that standpoint, it's a simple MySQL update query, but I'm not sure I'm using the datafeed right.
Other than the query I need to run in my PHP script (the datafeed URL), do I need to do anything else other than to echo "foxy" out to the page? Maybe that's all, and I'm over-thinking this.
If there's something odd with FoxyCart making an ajaxy type of call or something that would make this session variable non-applicable, please let me know. I may be complicating this unnecessarily.
I'll just mention here that whenever I'm developing using the datafeed there's a lot of back and forth, echoing, checking the FoxyCart error log, etc. I've built a developer tool in Order Desk to pull the XML for a transaction, mimic the datafeed post, and display the results in one step. Makes developing apps with the datafeed a lot easier. Check it out if you like at http://foxytools.com/orderdesk/
It's possible that maybe a thankyou.php page to send people to after ordering could do the handling too. We really just need to clean up some session stuff in PHP after the order's done. What I'm not sure about yet is whether or not FoxyCart's call to my feed PHP file is going to allow me to session_start() and access the variable in the session. In theory, it should...since $_SESSION is server side, but I've just never done this with FC before.
You could set a timeout on your system variables in the db and just let them expire after 8 hours or something.
It's possible that you might be able to make an AJAX call from the thank you page that cleaned up your session. The thank you page is not HTTPS so I think that might be okay.
The other more crazy option is set the session's ID as a hidden checkout custom field that you could use to map back to the session on the datafeed end. You could parse the datafeed, pull out the session ID and then do your processing from there.
Just a few ideas for ya.
We also have some example datafeed scripts on our integrations page (http://wiki.foxycart.com/integration) if that helps at all.
Maybe...then again, maybe not. The $_SESSION[] data I'm trying to access after purchasing is stored via PHP before they enter the cart. What I'm aiming to do is "change" part of that session after the order has taken place.
If I make the AJAX call from the receipt page, and have it call back to a PHP script on our server, will that PHP script be able to access the same $_SESSION previously setup with the user's information via session_start()? Right now, the data ID stored in the session is the only reference to a special "deal" code that we have, as we do not wish to pass this to the cart.
I really want to be able to do clean up things, like "hey, user ordered...retire this special promo code". Things of that nature. I don't think I need a data feed for this, but wanted to check here with the community.
Am I thinking about this totally wrong?
I'm at a loss now, because that session variable is how we're storing and keeping track of the user's progress in our script. So far, I've not found a way to access that information from within FoxyCart.
What would work, however, is if I could somehow pass the string to FoxyCart before entering checkout. Then, maybe having our AJAX call pass that through as part of a $_REQUEST string to the PHP script. Then I'd be able to retire the code properly.
Is there an easy way to get this passed to FC behind the scenes during the checkout process? If not, my next bet may be to try a browser cookie, but I'd prefer not to.
I really think, though, the last option I presented before (using the session ID in a datafeed) would be the best and most reliable.
So in the script on your site, store the PHP session ID and the user's data in your database. Then every time a user adds something to the cart include a hidden input:
Then in the datafeed endoint, loop through the order's custom fields until you find the sessionid one, then run your processes. Here's a datafeed script that exposes all the variables and makes it easy to grab just what you need: http://wiki.foxycart.com/v/0.7.2/transaction_xml_datafeed#example_parsing_code
I think the image tag option only works for forms, correct? Should I be doing it differently for the query string (hashed) method of linking an item to the cart?
Also, while testing, does it matter if I'm still working with MAMP locally? IE., "mystore.localhost:8888" for my hostname for the data feed (until live). That may help speed up the process a little.
The FoxyCart datafeed can't be sent to your local system, it needs to be sent to a script that is actually online. That said though, you can manually pass the datafeed to a local endpoint to trigger it that way.
I'm using your sample data feed, but for some reason I can't seem to isolate the promo code. When I use FoxyTools to fetch XML for a transaction, I can hard code that XML in my script and find the variable with the below code.
However, if I use the "Send XML" feature from within the tools area, it says "Your feed is working great!", but that variable isn't being found anymore (even though it's the exact same XML data).
So, in other words, hard-coded XML works, but FoxyCart-fed XML doesn't work...but structurally they're identical (I literally copied and pasted). Any ideas?
What the heck am I doing wrong?
When code does crazy stuff like this that's the troubleshooting process I go through, start basic and see where it breaks. Using die('something'); all over the place will help you pinpoint exactly where it isn't working.
Been at this for about 2 hours with everything you suggested and I'm striking out. I guess I was just wondering if the data gets served up differently (formatted or whatever) via AJAX vs. the local $xml.
The first die() works (but is all garbled) and shows up in the response box in Order Desk, but the second die() doesn't work, as it returns nothing to the response box in Order Desk.