Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Additonal Processing After Payment


Guest

Recommended Posts

I have my site setup with payment by Paypal, and I have the return page set to checkout_success.php. Everything works fine as far as the ordering process goes with respect to Paypal and osComerce.

 

Now I have to add some extra processing. Right now all of our products are drop shipped and the vendor uses a SOAP client to place our orders. I got all of their code working on a separate test page. Now I am trying to integrate their code into the existing checkout_process.php page.

 

(Question #1- is that the right place for it?) I have to send them the products one by one in a simple text string. I placed the new code right between

 

// load the after_process function from the payment modules

$payment_modules->after_process();

 

and

 

// release the cart and variables

$cart->reset(true);

 

Since I need to examine the cart contents, I needed to add code before the cart was reset. I'm not a PHP guru but I constructed the following code in between the two lines above:

 

// set up SOAP and Account information for web service

include("nusoap.php"); //Required SOAP Connection Class

include("vardef.php"); //Account Information & Service Keys

include("required.php"); //Required PHP Functions

// create SOAP client connection to Order webservice

$OrderService = new soapclient("http://order.ekeystone.com/WSElectronicOrder/ElectronicOrder.asmx?WSDL",true);

 

//examine cart contents, place drop ship order for products

 

//put the customer info together for the products

//first the static info

$keyponumber = $insert_id;

$keyaddinfo = "";

$keydropinfo = "";

$keyfirstname = $order->delivery['firstname'];

$keymiddleinit = "";

$keylastname = $order->delivery['lastname'];

$keycompanyname = $order->delivery['company'];

$keyaddress1 = $order->delivery['street_address'];

$keyaddress2 = "";

$keycity = $order->delivery['city'];

$keystate = $order->delivery['state'];

$keypostcode = $order->delivery['postcode'];

$keyphoneno = $order->customer['telephone'];

$keycountry = "US";

$keycustemail = $order->customer['email_address'];

 

// how many products in the cart

$products = $cart->get_products();

for ($i=0, $n=sizeof($products); $i<$n; $i++) {

 

// dynamic fields

$keyproductno = $products[$i]['model'];

$keyquantity = $products[$i]['qty'];

 

$keydropinfo = $keyfirstname.", ".$keymiddleinit.", ".$keylastname.", ".$keycompanyname.", ".$keyaddress1.", ".$keyaddress2.", ".$keycity.", ".$keystate.", ".$keypostcode.", ".$keyphoneno.", ".$keycountry.", ".$keycustemail;

$order_params = "<PlaceOrderDropShip xmlns='http://eKeystone.com'>"; //Define Order Service Parameters

$order_params.= "<Key>"; // Open Key

$order_params.= $order_key; //Electronic Order Webservice Key

$order_params.= "</Key>"; //Close Key

$order_params.= "<FullAccountNo>"; // Open Account Number

$order_params.= $cust_number; //Customer Account Number

$order_params.="</FullAccountNo>"; //Close Account Number

$order_params.="<FullPartNo>"; // Open Part Number

$order_params.= $keyproductno; //Get Part Number from Previous Post

$order_params.="</FullPartNo>"; //Close Part Number

$order_params.="<Quant>"; // Open Quantity

$order_params.= $keyquantity; // Quantity

$order_params.="</Quant>"; //Close Quantity

$order_params.="<DropShipInfo>"; //Open Drop Ship Info

$order_params.= $keydropinfo;

$order_params.="</DropShipInfo>";//Close Drop Ship Info

$order_params.="<PONumber>"; //Open PO Number

$order_params.= $keyponumber; //PO Number

$order_params.="</PONumber>"; //Close PO Number

$order_params.="<AdditionalInfo>"; //Open Additional Info

$order_params.= $keyaddinfo; //Additional Info

$order_params.="</AdditionalInfo>"; //Close Additional Info

$order_params.="</PlaceOrderDropShip>"; // Close Place Order XML Parameter String

$order = $OrderService->call('PlaceOrderDropShip',$order_params); //Call Order Service with parameters specified above

 

$outputstring = $keydropinfo . $orderkey . $cust_number . $keyproductno . $keyquantity . $i . $n . $keyponumber;

@ $fp = fopen("$DOCUMENT_ROOT/osCommerce/catalog/results.txt",'ab');

fwrite($fp,$outputstring);

fclose($fp);

}

 

If you look at it closely, I'm basically building a string to send for each product. Again, this code worked on a test page with hard-coded values. Now since I'm trying to get them from osCommerce, I'm having a lot of issues. I actually can't tell if anything is happening in this section. I added the last few lines above to write the variables out to a text file so I could see if anything was correct and the file never gets any information.

 

I am most concerned with how I set up the loop and if I am trying to get the values correctly from the products in the cart. Also if anyone can tell me why the text file doesn't work, that would make me happy too. Also, I'm not sure if $insert_id is te right value to use fora PO number, but I want it to match whatever the number used to identify the order in the admin panel so they can be matched up.

 

I have been puling my hair out all day on this one, I beg for someone to look at it. I haven't ruled out that something is wrong with the drop ship code, but other than reassigning the values of the variables to product information in the cart, it is the same as my test page which worked beautifuly.

 

:'( After 16 hours today on this, I have to go get some sleep.....

 

Anyone who can help me with this.....thank you very much. I would love to finish this tomorrow so I can enjoy a holiday next week.....

Link to comment
Share on other sites

It seems a reasonable place for the code. Try echoing out your $order_params string - the write to file may well not be working as you expect. At least this way, you'll see if there's anything there or not.

 

Also, bear in mind the problems with customers not returning to your store after completing a paypal payment.

Link to comment
Share on other sites

It seems a reasonable place for the code. Try echoing out your $order_params string - the write to file may well not be working as you expect. At least this way, you'll see if there's anything there or not.

 

Also, bear in mind the problems with customers not returning to your store after completing a paypal payment.

 

I made one change since last night, i renamed one variable which is supposed to hold the result back from the web service from $order to $keyorder. I didn't notice a change in its perormance, but the $order variable was already used somewhere else, so I decided to remove this duplication.

 

I have found out that the web service is not getting data like it did on the test page, so I'm leaning towards the problem being that I am not pushing the data from the cart into the variables to transmit correctly.

 

The echo trick didn't work either, there is a redirect to checokut_success.php on that page. When I disabled the redirect to to try to see the echo result. Nothing was there.

Link to comment
Share on other sites

I made one change since last night, i renamed one variable which is supposed to hold the result back from the web service from $order to $keyorder. I didn't notice a change in its perormance, but the $order variable was already used somewhere else, so I decided to remove this duplication.

 

I have found out that the web service is not getting data like it did on the test page, so I'm leaning towards the problem being that I am not pushing the data from the cart into the variables to transmit correctly.

 

The echo trick didn't work either, there is a redirect to checokut_success.php on that page. When I disabled the redirect to to try to see the echo result. Nothing was there.

 

The fact that the page fired the redirect is telling me that your code did not fire at all. Whenever an echo or print (or anything is output to the browser then a redirect will fail with the familiar "Warning: Cannot modify header information - headers...") So I would say your code is not executing.

 

for instance

<?php
print "Ha, Try to redirect now!!<br />";
header("location: index.php");
?>

 

This would print out to the browser

 

Ha, Try to redirect now!!

 

Warning: Cannot modify header information - headers already sent by (output started at...

 

It will never redirect.

 

Do you have conditional code that means your bit will only execute when a certain condition is true.

 

I can only echo(no pun intended) what FalseDawn said. Put in some echo/print statements all over your code.

 

So before it goes to your code put

 

Print "About to enter new code<br />";

 

So when it is first supposed to be into your new piece if code put at the top

 

Print "I'm in the new piece of code<br />";

 

and put print statements all over your code at various parts testing variables are set as you are expecting.

 

This way you will see at which point it is getting to in the code (if at all). Dont worry about the redirect it will never fire if issuing print statements to the browser (and they are actually being called).

 

Also the fact that nothing is being written to the file would suggest it not being called, again though remove the @ which suppresses any errors.

 

Obviously before you release this to Live remove (or comment out) the print statements etc.

 

and maybe post up your entire file.

 

Mike

Link to comment
Share on other sites

I have confirmed that the code works and successfully drop ships an order for a single product and hard-coding values for all the data except the quantity and part number ( I have eliminated the others - but i had to hard code these two to make sure the drop shipper could get anything). So I am about to repeat it with these last two again being filled in by variables. I commented out the for loop and ordered a single product.

 

 

// how many products in the cart

$products = $cart->get_products();

for ($i=0, $n=sizeof($products); $i<$n; $i++) {

 

// dynamic fields- about to make sure the drop shipper can see this data

$keyproductno = $products[$i]['model'];

$keyquantity = $products[$i]['qty'];

 

[a bunch of code that has been verified is here]

 

$outputstring = $keydropinfo . $orderkey . $cust_number . $keyproductno . $keyquantity . $i . $n . $keyponumber . $keyorder;

$fp = fopen("$DOCUMENT_ROOT/osCommerce/catalog/results.txt",'ab');

fwrite($fp,$outputstring);

fclose($fp);

echo($outputstring);

}

 

So, if these last two pieces are recived on the next test, the issue is my loop, and note the text file and echo are inside the loop. This may suggest why it never seemed to execute. So can anyone check out the loop to see if it makes sense?

Link to comment
Share on other sites

$products = $cart->get_products();

//for ($i=0, $n=sizeof($products); $i<$n; $i++) {

 

// dynamic fields- about to make sure the drop shipper can see this data

$keyproductno = $products[$i]['model'];

$keyquantity = $products[$i]['qty'];

 

 

These two variables are not being filled. I have the loop currently commented out to test just these two variables. So something is wrong with

 

$products = $cart->get_products();

 

or

 

$keyproductno = $products[$i]['model'];

$keyquantity = $products[$i]['qty'];

 

Any ideas?

Link to comment
Share on other sites

after this line

 

$products = $cart->get_products();

 

put

 

print_r($products);

 

It should output the array contained in $products, post the output here.

Link to comment
Share on other sites

I would also re-write your for loop, looks very convoluted.

 

 

$products = $cart->get_products();
$SizeOfArray = sizeof($products);

for ($i=0; $i<$SizeOfArray; $i++){
 //do whatever
}

 

Yes you could put $i<sizeof($products) in the for loop, but it would need to call the size of function each time it loops which in this case may not be a huge performance hit, but it is good practice to get used to writing code that is efficient.

Link to comment
Share on other sites

after this line

 

$products = $cart->get_products();

 

put

 

print_r($products);

 

It should output the array contained in $products, post the output here.

 

I tried this but I do not get any results displayed- it still redirects to checkout_success.php. Code both before and after this section executes however because my drop shipper is receiving the rest of the info and I change the test product each time so I can carefully track each test. So perhaps $products = $cart->get_products(); is not returning a result leaving nothing to print?

Link to comment
Share on other sites

I tried this but I do not get any results displayed- it still redirects to checkout_success.php. Code both before and after this section executes however because my drop shipper is receiving the rest of the info and I change the test product each time so I can carefully track each test. So perhaps $products = $cart->get_products(); is not returning a result leaving nothing to print?

 

Well if there was something in $products then print_r() function would have output it to the browser.

 

Just before $products = $cart->get_products(); put

 

print "The cart ID is : ".$cart->cartID;

Link to comment
Share on other sites

Well if there was something in $products then print_r() function would have output it to the browser.

 

Just before $products = $cart->get_products(); put

 

print "The cart ID is : ".$cart->cartID;

 

 

Is there a way to output these print statements out to another window? I'm still not getting anything displayed, even when displaying variables that are successfuly transmitting to the drop-shipper. I do have the STS template system installed maybe it is affecting the display.

 

I di dmake the change to the for loop, and I agree it is much cleaner now. Thanks!

Link to comment
Share on other sites

it should be $products[$i]['quantity'] I believe

 

Also, when developing new code, it's always a good idea to turn on ALL error reporting.

Find this in application_top.php

:

 

 

// set the level of error reporting

error_reporting(E_ALL & ~E_NOTICE);

 

 

Change to

// set the level of error reporting

error_reporting(E_ALL);

 

 

You'll then see all those variables that are never initialised, as well as a load of other potential problems.

Link to comment
Share on other sites

Is there a way to output these print statements out to another window? I'm still not getting anything displayed, even when displaying variables that are successfuly transmitting to the drop-shipper. I do have the STS template system installed maybe it is affecting the display.

 

I di dmake the change to the for loop, and I agree it is much cleaner now. Thanks!

 

 

I think we got it! :D

 

$keyquantity = $products[$i]['quantity']; instead of $keyquantity = $products[$i]['qty'];

 

I had copied an example from somewhere on the forum, but I didn't notice the issue until I started poking around shopping_cart.php and the get_products() function that the field name didn't match.

 

Apparent the drop shipper tests both the product model number and the quantity together and doesn't commit the order unless both are validated. Since the quantity remained at 0, the order was never placed.

 

I still never got any out put to the browser though....but I'll think I will let that go for now since I just needed it to debug. Thanks again Mike! I owe you for replying with good questions each time!

Link to comment
Share on other sites

lol, I beat you by 1 minute! :lol:

 

 

and I owe you too! Thanks!

 

That had to be the hardest bug I have yet hard to deal with in PHP. I'm much more use to it in .NET ! :D

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...