Functions:orderGetShipArray

From Whirlwind eCommerce Wiki
Revision as of 02:54, 26 February 2009 by 71.163.185.8 (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Description

eV::orderGetShipArray($itemTotal=NULL,$toZip=NULL,$totalWeight=NULL) retrieves an array of shipping options that can be offered to visitors for an order. The shipping options will be calculated based on the attributes sent in combinations with the shipping settings set up in Settings > eCommerce and Shipping.

Syntax

$array = eV::orderGetShipArray([$itemTotal],[$toZip],[$totalWeight]);

Paramaters

NOTE: either $itemTotal (for shipping level tables) OR $toZip+$totalWeight (for Fedex calculations) are required

  • $itemTotal FLOAT OPTIONAL
The order dollar value to be used for pulling shipping options / prices from the Shipping level tables.
  • $toZip INT OPTIONAL
The shipping zip code that the order will be sent to. Used to retrieve shipping options / prices from the Fedex zone shipping tables.
  • $totalWeight FLOAT OPTIONAL
The total weight to be considered when retrieving shipping options / prices from the Fedex zone shipping tables.

Return Values

Returns a multidimensional array of shipping options and their details. The first dimension is the index of the shipping options. The second dimension contains the keys for each of the shipping option's data elements.

The returned array is as follows:


Array
(
    [0] => Array
        ( 
            [type] => String
            [typeCode] => String
            [shipAmount] => Float
            // the following 3 fields are only included if the shipping data is from the level tables
            [charge] => Float
            [percent] => Float
            [minAmount] => Float
        )
    [1] => Array...
       ( .. same as above ..)
)


Examples

Using Fedex Tables (be sure fedex shipping option is setup and configured via Settings
// lets get the weight and target zip code
$orderArr = eV::orderGetCompleteArray();
 
// extract data from orderArr that will be passed to orderGetShipArray function
$weight = $orderArr['order']['weightTotal'];
$toZip = $orderArr['items'][0]['zipCode'];
 
// extract data from orderArr for current shipping option/prices selected
$currentShipTypeCode = $orderArr['items'][0]['shipTypeCode'];
 
// extract addressId for form select
$sale_addressId = $orderArr['items'][0]['sale_addressId']
 
// get shipping options
// note we are using the 2nd ($toZip) and 3rd ($weight) attributes because this is a Fedex shipping query
$shipArr = eV::orderGetShipArray(NULL,$toZip,$weight);
 
// output shipping options as a form allowing customer to select and commit to the cart
echo "<form action=\"index.php\" method=\"post\">";
echo "<select name=\"shipping4addressId" . $sale_addressId . "\">";
foreach($shipArr as $ship) {
echo "<option value=\"" . htmlspecialchars($ship['typeCode']) . "\";
if($currentShipTypeCode == $ship['typeCode']) echo " selected ";
echo ">" . htmlspecialchars($ship['shipType']) . ": " . eV::dollarFormat($ship['shipAmount']) . "</option>";
};
echo "</select>";
// lets put zipCode in this form since its required to get the shipping total
echo " Enter Zip Code: <input type=\"text\" name=\"zipCode\" value=\"" . htmlspecialchars($toZip) . "\" size=\"12\" maxlength=\"10\">";
echo " <input type=\"submit\" value=\"Submit\"> ";
echo " <input type=\"hidden\" name=\"fa\" value=\"ORDER.cartUpdate\"> ";
echo "</form>";
Using Shipping Price Levels (requires setup in Settings > eCommerce AND levels created in Shipping)
// lets get the weight and target zip code
$orderArr = eV::orderGetCompleteArray();
 
// extract data from orderArr that will be passed to orderGetShipArray function
$itemTotal = $orderArr['order']['itemTotal'];
 
// extract data from orderArr for current shipping option/prices selected
$currentShipTypeCode = $orderArr['items'][0]['shipTypeCode'];
 
// extract addressId for form select
$sale_addressId = $orderArr['items'][0]['sale_addressId']
 
// get shipping options
// note we are using only the 1st ($itemTotal) attribute because this is a Shipping level table query
$shipArr = eV::orderGetShipArray($itemTotal);
 
// output shipping options as a form allowing customer to select and commit to the cart
echo "<form action=\"index.php\" method=\"post\">";
echo "<select name=\"shipping4addressId" . $sale_addressId . "\">";
foreach($shipArr as $ship) {
echo "<option value=\"" . htmlspecialchars($ship['typeCode']) . "\";
if($currentShipTypeCode == $ship['typeCode']) echo " selected ";
echo ">" . htmlspecialchars($ship['shipType']) . ": " . eV::dollarFormat($ship['shipAmount']) . "</option>";
};
echo "</select>";
echo " <input type=\"submit\" value=\"Submit\"> ";
echo " <input type=\"hidden\" name=\"fa\" value=\"ORDER.cartUpdate\"> ";
echo "</form>";