Functions:ordersGetList
From Whirlwind eCommerce Wiki
Description
eV::ordersGetList() retrieves a multidimensional array of order information. Especially useful for order history pages.
Syntax
$array = eV::orderGetList([$fieldList[,$userId[,$fromDate[,$toDate]]]]);
Paramaters
- $fieldList STRING (optional)
- comma-delimited list of fields to be returned. If not passed, all fields will be returned.
- $userId INT (optional)
- system designated unique userId - all orders that belong to the user will be returned. Defaults to the current session's user.
- $fromDate DATETIME (optional)
- if passed, only orders completed during or after the $fromDate will be returned
- $toDate DATETIME (optional)
- if passed, only orders completed during or before the $toDate will be returned
Return Values
Returns a multidimensional array where the first dimension is the index of the order, and the second dimension is the order's field names:
Array ( [0] => Array ( // fields automatically included [orderId] => INT [orderNumber] => IN [createDate] => DATETIME [completeDate] => DATETIME [cancelDate] => DATETIME [user_firstName] => STR [user_lastName] => STR [user_emailAddress] => STR [ship_firstName] => STR [ship_lastName] => STR [ship_emailAddress] => STR [pay_firstName] => STR [pay_lastName] => STR [pay_emailAddress] => STR [itemTotal] => FLOAT // cost of items in cart added up [discountTotal] => FLOAT // discount totals added up [orderTotal] => FLOAT // cost of items in cart added up, less discounts [taxTotal] => FLOAT // total taxes charged to order [shipTotal] => FLOAT // total shipping charged to order [orderGrandTotal] => FLOAT // sum total of everything (item, tax, ship, less discount) for order ) [1] => Array ( ... ) )
Example
// kick if logged out // recommended to place in 'pre process' code of template - no reason to waste processing power if we just gonna kick to home. // also consider replacing the target page below with a link to the login page eV::authorizeIsLoggedIn('index.php?message=You must be logged in to view your order history') // get listing $arrOrders = eV::ordersGetList("orderId,orderNumber,completeDate,cancelDate,orderTotal"); // start off a table echo "<table><tr><td>Order Number</td><td>Date</td><td>Total</td></tr>"; // we have orders, lets loop $orderCount = 0; foreach($arrOrders as $order) { // only display orders that are completed and current (not cancelled) if(!empty($order['completeDate']) && empty($order['cancelDate'])) { $orderCount++; echo "<tr><td><a href=\"index.php?fa=ORDER.invoice&orderNumber=" . $order['orderNumber'] . "\">" . $order['orderNumber'] . "</a></td>"; echo "<td>" . date('M d, Y',strtotime($order['completeDate'])) . "</td>"; echo "<td>" . eV::dollarFormat($order['orderGrandTotal']) . "</td></tr>"; // end if order qualifies to be displayed }; // end order loop }; if(!$orderCount){ // no orders, display message echo "<tr><td colspan=3>You have no orders at this time</td></tr>"; }; // close the table echo "</table>"; // fin!