The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

xml datafeed issue

RickWRickW Member
in Bugs & Feature Requests edited October 2009
So, I tested my feeds using test.xmldatafeed.php and xml_to_simple_csv.php.
Everything works great. The problem is with a hidden field. It works with test.xml.... but when my switch over to a "test Gateway" and use the foxycart feed the hidden field doesn't come back.
So either I'm processing the xml feed incorrectly, which doesn't seem probable. Or I'm posting the hidden field to foxy cart wrong. Here is the code on both sides.

Post to FoxyCart

echo "<div class='register' style='overflow: auto; width: 670px; padding-left:25px; border: 3px solid #cccccc; height:60px; background-color: white ;'>";
echo " Terms";
echo "</div>";
echo"<input type='checkbox' name='h:Terms' value='Terms' /><span class='bodycopy'>I have read and agree to the terms and conditions set forth by</span><br><br>";
echo"<input type='hidden' name='h:login' value=$email/>";
echo"<input type='hidden' name='name' value='Credits'/>";
echo"<input type='hidden' name='price' value='2.00'/>";
echo"<input type='hidden' name='category' value='Credits'/>";echo"<select name='quantity'>";
echo"<option value='{q:10}'>10</option>";
echo"<option value='{q:30}'>30</option>";
echo"<option value='{q:60}'>60</option>";
echo"<option value='{q:100}'>100</option>";
echo"<option value='{q:300}'>300</option>";
echo"</select> <input type='submit' value='Buy Credits'/></div>";

Parse XML

if (isset($_POST["FoxyData"])) {
$output = '';
$FoxyData_encrypted = urldecode($_POST["FoxyData"]);
$FoxyData_decrypted = rc4crypt::decrypt($myKey,$FoxyData_encrypted);
$xml = new SimpleXMLElement($FoxyData_decrypted);
foreach ($xml->transactions->transaction as $transaction) {
// Loop through to get the product code, name, customer name, date, and transaction ID
$transaction_customer_name = $transaction->customer_last_name . ', ' . $transaction->customer_first_name;
$transaction_date = $transaction->transaction_date;
$transaction_id = $transaction->id;
foreach ($transaction->custom_fields->custom_field as $custom) {
$email = $custom->login;
foreach ($transaction->transaction_details->transaction_detail as $product) {
$product_code = $product->product_code;
$product_name = $product->product_name;
$product_quantity = $product->product_quantity;
$product_price = $product->product_price;
$category_code = $category->category_code;
if ($product_name=="Credits") {
$result = mysql_query("insert into ledger (date,email,weco,credit) values ('$transaction_date','$email','$transaction_id','$product_quantity') ",$connectID)or die("add failed"); }
else{ $result = mysql_query("insert into cd_sales (date,trans_id,cd_code,sale_price) values ('$transaction_date','$transaction_id','$product_name','$product_price') ",$connectID)or die("add failed"); }
echo 'foxy';

I tried changing $email = $custom->login; to $email = $custom->h:login; and that didn't work. Where did I go wrong?
  • brettbrett FoxyCart Team
    Hmmm... In my testing the custom fields are coming through fine, but here are the first steps:
    1) Does the $login actually output to the HTML? If you view source, do you see anything?
    2) If so, try putting quotes around it, as javascript can be really picky with invalid HTML (assuming you're using the default FoxyCart javascript, which serializes a form to GET it to the cart).
    3) When you do add the product to your cart, what do you see in the JSON (view source on the cart itself (inside the iframe) or the checkout). You should see it there. If you don't, your value isn't making it to the session at all. If you do see it in the JSON... then we may have a bug.

    To confirm: You're testing on v060? Or are you seeing this in a different version?
  • I'm using 5.1
    I've tried using quotes and it didn't help
    I've tested the $email before its sent to foxycart, and it is there.
    I can view it in the source code in the cart and at checkout.

    When I first was testing custom fields, the foreach loop didn't act as expected. I deleted the second custom field that was in the test.xml... code and then it worked fine. Could the problem be with the other hidden field -Terms?

    Now what?
  • brettbrett FoxyCart Team
    Have you tried using the "write to file" to grab what _is_ actually being sent? That's what I'd recommend. Then use what you get from FoxyCart to test post to your processor and see what's happening. It sounds like you may have an error in how you're...

    $email = $custom->login;
    That won't work (I don't think). You'd need something like $custom->custom_field_name

    But if you have multiple options (which you do) you need to check that you're setting the $email to the custom_field_value that has a corresponding custom_field_name == 'email'

    Make sense?
  • We I've tried your last suggestion, and it doesn't work.
    I think the problem occurs with the foreach loop.
    I only want to capture the login value (which now has been changed to email).
    Is there a way to write one line of code without using the foreach loop?
    I'm new to xml and I haven't figured out the construct quite yet.
    When I originally tested the xml feed I was successful, but then I only had one hidden field.
  • tookingstookings Member
    edited October 2009
    RickW, you may be able to do something like:
    foreach ($transaction->custom_fields->custom_field as $custom)
    if($custom->custom_field_name == "email")
    $email = $custom->custom_field_value;

    ...that is just off the cuff though, and doesn't scale very elegantly if you want to save multiple custom fields later. If you wouldn't mind whispering me a non-sensitive copy of a sample datafeed of yours, I could take a deeper peek.

    (Or, did that help?)
  • Yeah!!! That worked! Thank you!!!
Sign In or Register to comment.