Contents |
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.
$array = eV::orderGetShipArray([$itemTotal],[$toZip],[$totalWeight]);
NOTE: either $itemTotal (for shipping level tables) OR $toZip+$totalWeight (for Fedex calculations) are required
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 ..)
)
// 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>";
// 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>";