Updating a database after customer completes purchase

MindSculptMindSculpt Member
in Help edited February 2012
Im in test mode and currently integrating FoxyCart into my website. I have successfully implemented the SSO/API flow and am working with the subscription data feed.

I need to be able to immediately access the value of one of the checkout form input fields upon a completed purchase so I can update my database. Here is the input whose value I need:
<input id="my_value" name="Value<?php echo get_verification('Value', '--OPEN--', 'my_code'); ?>" type="text" maxlength="5" autocomplete="off" placeholder="Type a value" value ="" />

I need to be able to get this value (which is typed in by the user) after checkout has completed so that I can immediately update values in my database. I can't rely on the user clicking the 'continue to store' link on the receipt page in case they close out the window, because even though they think the transaction is finished, I haven't yet updated my database to show that they completed the transaction.

So basically, I need a way to update my database immediately upon a successful transaction, using the foxycart id and the value of that custom field. Can I do this via the subscription data feed PHP script? If so, how can I access the input value mentioned above from this point?
Tagged:
Comments
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    You'll want to do this with the transaction datafeed: http://wiki.foxycart.com/v/0.7.2/transaction_xml_datafeed - it gets run right after the transaction is completed and passes all those values in.
  • @sparkweb I followed that wiki page and it led me to the php subscription data feed example on the wiki, which is what I am currently experimenting with. Is that the right script?
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Well, not exactly. The transaction datafeed gets run on every successful purchase. The subscription datafeed is something that is sent once a day with your current and past due subscriptions so you can perform actions based on those. I think in this case you really want to use the transaction datafeed to process your data.
  • @sparkweb Ok, so how do I consume the transaction data feed? Is there a php example script? Also, there's only one field in the admin to add a data feed URL...how can I successfully use both?
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    At the bottom of the page I referenced earlier there is some sample code. If you have subscriptions that info will be sent to the datafeed url as well. But remember that each time a subscription is run, it gets treated like a regular transaction and sent to the datafeed.
  • @sparkweb That link only shows the XML data feed, not a php example of how to consume it...unless I'm missing something?
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Sorry about that, I thought I remembered there being code there. Guess not. I threw together some code that I use in the FoxyShop datafeed template and made it fairly generic. This should get you started and presets all the variables you'll need: http://pastebin.com/fsfF0rdf
  • MindSculptMindSculpt Member
    edited February 2012
    @sparkweb Awesome, that's super helpful. So if I change the datafeed URL in the foxy admin to point to this new file, how can I integrate the subscription feed php from here:

    http://wiki.foxycart.com/integration/subscription_datafeed

    Thoughts?
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Just connect the two scripts. Something like:
    } elseif (isset($_POST["FoxySubscriptionData"])) {
    
  • MindSculptMindSculpt Member
    edited February 2012
    @sparkweb Ok, I've got the datafeed working, but I'm having trouble actually accessing the product option values from the code you gave me. So here's the transaction loop from your datafeed example:
    //For Each Transaction Detail
    	foreach($transaction->transaction_details->transaction_detail as $transaction_detail) {
    		$product_name = (string)$transaction_detail->product_name;
    		$product_code = (string)$transaction_detail->product_code;
    		$product_quantity = (int)$transaction_detail->product_quantity;
    		$product_price = (double)$transaction_detail->product_price;
    		$product_shipto = (double)$transaction_detail->shipto;
    		$category_code = (string)$transaction_detail->category_code;
    		$product_delivery_type = (string)$transaction_detail->product_delivery_type;
    		$sub_token_url = (string)$transaction_detail->sub_token_url;
    		$subscription_frequency = (string)$transaction_detail->subscription_frequency;
    		$subscription_startdate = (string)$transaction_detail->subscription_startdate;
    		$subscription_nextdate = (string)$transaction_detail->subscription_nextdate;
    		$subscription_enddate = (string)$transaction_detail->subscription_enddate;
    			
    	//These are the options for the product
    	$transaction_detail_options = array();
    	foreach($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
    		$product_option_name = $transaction_detail_option->product_option_name;
    		$product_option_value = (string)$transaction_detail_option->product_option_value; //
    		$price_mod = (double)$transaction_detail_option->price_mod;
    		$weight_mod = (double)$transaction_detail_option->weight_mod;
    	}
    			
    	//If you have custom code to run for each product, put it here:
    
    }
    

    What's the correct php syntax to grab the values from that 2nd foreach loop, specifically the product_option_value node?
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Well, since it's a secondary loop, if you wanted to find the value of "optionx" you would do something like this:
    $optionx = "";
    foreach($transaction_detail->transaction_detail_options->transaction_detail_option as $transaction_detail_option) {
    		$product_option_name = $transaction_detail_option->product_option_name;
    		$product_option_value = (string)$transaction_detail_option->product_option_value; //
    		$price_mod = (double)$transaction_detail_option->price_mod;
    		$weight_mod = (double)$transaction_detail_option->weight_mod;
    
    		if ($product_option_name == "optionx") $optionx = $product_option_value;
    	}
    
  • lukeluke FoxyCart Team
    There are quite a few datafeed integration examples here as well: http://wiki.foxycart.com/integration/start
  • @luke. Yep, I saw those but I needed a bit of help to figure out some more specifics for my custom integration.
Sign In or Register to comment.