PHP ShopSite Custom Shipping Module

One method of integrating custom shipping into ShopSite. Parameters are passed into the request body, so it's a bit different that using the query string in it's traditional fashion through $_GET.

Ask your web host where the CLI-enabled PHP binary is on your shared server.
#!/ramdisk/bin/php5-cli -q
<?php
// note - you need a CLI-enabled php binary, the usual /usr/bin/php may not work.  
// Ask your host about this

ini_set('zlib.output_compression', 'Off');

$query_string = trim(fgets(STDIN));  // here's the difference, we need to pull parameters from STDIN!
parse_str($query_string);

// we'll load these into request variables, so you can test this script from a browser
if (!isset($_REQUEST['item_total'])) {
	$_REQUEST['item_total'] = $item_total;

	for($i = 1; $i <= $item_total; $i++) {
		$_REQUEST['p' . $i . 'ship'] = ${"p" . $i . "ship"};
		$_REQUEST['p' . $i . 'weight'] = ${"p" . $i . "weight"};
		$_REQUEST['p' . $i . 'quantity'] = ${"p" . $i . "quantity"};
	}

	$_REQUEST['cust_zip'] = $cust_zip;
}

$weight = 0;
$productCount = $_REQUEST['item_total'];
for($i = 1; $i <= $productCount; $i++) {
	if($_REQUEST['p' . $i . 'ship'] === 'Y')
		$weight += ($_REQUEST['p' . $i . 'weight'] * $_REQUEST['p' . $i . 'quantity']);
}


// PERFORM SHIPPING CALCULATIONS HERE
$theRate = 5.00


print "status=pass\n";
print "option_count=1\n";
print "s1option=Shipping Option 1\n";
printf ("s1price=%0.2f\n", $theRate);

?>
Posted by
Snippet Viewed 1639 times.

Share your PHP code snippets:

  • Get some recognition & link back to your site.

 

Submit | Browse

Most Recent php snippets

Most Viewed