Custom Shipping API - errorno 32?

General ShopSite user discussion

Custom Shipping API - errorno 32?

Postby greggbanse » Mon Nov 24, 2008 3:52 pm

I've been working out the details for implementing a custom shipping API. I found and read Michael Wong's explanation of CLI PHP (my setup) on PAIR. I'm getting an error no 32 now and I can't find an explanation of what the error is in the ShopSite ref manual nor here on the forums. Can someone give me a nudge in the right direction?

Full error: "Custom Shipping Add-on Error parent write: errno: 32"
greggbanse
 
Posts: 10
Joined: Fri Sep 12, 2008 6:08 am

Postby loren_d_c » Mon Nov 24, 2008 6:05 pm

This means that your script can't be executed for some reason. It could be permissions (if your script has the same ownership and permissions as the ShopSite order.cgi then that should be good), it could be that your script is not in UNIX text file format (if you are uploading it from a Windows computer, make sure you FTP it in ASCII mode so that the FTP transfer will make the conversion from DOS format to UNIX format), it could be that your script has the wrong path to the CLI-enabled PHP executable on the first line (the script should start with something like #!/usr/bin/php or whatever the path is to your CLI-enabled PHP binary).

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby greggbanse » Tue Nov 25, 2008 6:25 am

Hello once again Loren,
The script passes all 3 of those tests. The funny thing is that I can run it from the command line and get the desired output so I'm baffled why ShopSite gives me the error.
greggbanse
 
Posts: 10
Joined: Fri Sep 12, 2008 6:08 am

Postby greggbanse » Tue Nov 25, 2008 11:00 am

For those of you following this (or come across it in the future) here's what happened. It turns out you NEED to read in the variables being passed from ShopSite before it will work. SO to test your own setup here's what you need to do.

1) be sure you can talk to PHP via the command line. Use SSH to connect and enter php -i If you get a boatload of data about PHP and paths and variable then you're good to go. If not, you may need to locate where php is loaded and use that path - a typical path is: /usr/local/bin/php

2) Setup your Custom Shipping API to point to the file. Be sure it's in the correct location (on the custom shipping api config page within ShopSite admin you'll see the path it expects). Be sure the Ship From zip code is filled in.

3) I used the following very simple PHP file to test the connection and setup.

Code: Select all
#!/usr/local/bin/php -q
<?php
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%{$_SERVER['CONTENT_LENGTH']}s",$query_string);
parse_str($query_string,$params);
print "status=pass\n";
print "option_count=1\n";
print "s1option=Your Shipping\n";
print "s1price=5.00\n";
?>


The first part of the code came from Michael Wong's original post a few years ago (see below). I updated the PHP server variable to reflect the current syntax ($_SERVER instead of $SERVER).

4) Put the file on the server in the correct location, check that permissions and ownership are the same as on order.cgi (which should be in the same directory).

5) Be sure your Shipping Addon info is saved and that you saved changes on the Shipping configuration page too.

6) Go put something in the cart and view the cart. YOu should see Your Shipping option among the other shipping options.

HTH
G

Followup Resources
1) http://support.shopsite.com/forums/viewtopic.php?t=2028
greggbanse
 
Posts: 10
Joined: Fri Sep 12, 2008 6:08 am

Postby loren_d_c » Tue Nov 25, 2008 2:38 pm

Gregg,

Thanks for the follow up with your solution. One suggestion I have is that instead of this code to read the parameters from stdin:

Code: Select all
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%{$_SERVER['CONTENT_LENGTH']}s",$query_string);


Try this code instead:

Code: Select all
$query_string = trim(fgets(STDIN));


The problem with the former code is that I have seen some reports that it would stop parsing once it reaches a space character passed in the data. The later code should not have that problem. I found an example of it on the PHP website by googling for the term 'getting PHP parameters from stdin', see:

http://us3.php.net/features.commandline

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby greggbanse » Tue Nov 25, 2008 2:50 pm

Thanks for that Loren. I modified my code and it works great. Now I can finally get back to work on shipping fees based on East of the Mississippi or West of it! :)
greggbanse
 
Posts: 10
Joined: Fri Sep 12, 2008 6:08 am

Order API and Finite Options

Postby chinasprout » Wed Nov 26, 2008 12:58 pm

Just wanted to alert everyone who is using the above code in the order API that the basket variable for Finite Options is "Bnn-Finite_Options" (the code converts spaces to underscores).

Joachim
chinasprout
 
Posts: 1
Joined: Wed Nov 26, 2008 12:07 pm

Re: Custom Shipping API - errorno 32?

Postby b2tech » Mon Jul 18, 2011 10:09 am

Another 'gotcha' I ran into when attempting to create a PHP based Custom shipping add on:

This generic error:
"ShopSite detected that the information passed from the Custom Shipping Add-on is incomplete"

Everything was correct using an exact copy of the code from above:

I kept getting the generic "ShopSite detected that the information passed from the Custom Shipping Add-on is incomplete" error until PHP's zlib.output_compression was disabled.

So, output compression should be disabled before attempting to build a PHP custom shipping add on.

Code: Select all
#!/usr/local/bin/php -q
<?php

/* Deactivate zlib compression for files that interact with shopsite */
ini_set('zlib.output_compression', 'Off');

$query_string = trim(fgets(STDIN));
parse_str($query_string,$params);
print "status=pass\n";
print "option_count=1\n";
print "s1option=Your Shipping\n";
print "s1price=5.00\n";

?>
b2tech
 
Posts: 21
Joined: Tue Aug 03, 2010 2:51 pm
Location: MN

Re: Custom Shipping API - errorno 32?

Postby sitekickr » Wed Oct 16, 2013 4:45 am

Thanks guys for all the help - I've combined what I learned here with other posts and came up with this script:

http://www.sitekickr.com/snippets/php/shopsite-custom-shipping-module

It allows you to test via your browser as well, by copying the STDIN variables over to $_REQUEST variables.

Note: The CLI-enabled binary is specific to BlueHost, so you need to ask your webhost where the CLI-enabled binary is on your server.
sitekickr
 
Posts: 1
Joined: Wed Oct 16, 2013 4:42 am


Return to User Forum

Who is online

Users browsing this forum: Bing [Bot] and 72 guests