Functions:orderGetCompleteArray
From Whirlwind eCommerce Wiki
Revision as of 21:52, 19 October 2008 by 71.163.185.8 (Talk)
Description
Retrieves data for entire order including items, payments, addresses, etc. Use for building shopping cart page, order review/summary page and order receipts.
Syntax
$orderArray = eV::orderGetCompleteArray($orderId=NULL)
Paramaters
- $orderId INT OPTIONAL
- unique orderId as assigned by the system upon creation of the order. If empty, the system will default to the current shopping cart (session.order.orderId)
Return Values
Associative array of complete order information. The array is as follows:
Array ( [items] => Array ( [0] => Array ( [itemId] => INT [createDate] => DATETIME [modDate] => DATETIME [createUserId] => INT [modUserId] => INT [quantity] => INT [pricePer] => FLOAT [listPricePer] => FLOAT [sale_addressId] => INT [shipType] => STRING [shipTypeCode] => STRING [shipAmount] => FLOAT [addressName] => STRING [taxAmount] => FLOAT [firstName] => STRING [lastName] => STRING [user_addressId] => INT [street1] => STRING [street2] => STRING [city] => STRING [state] => STRING [zipCode] => INT [country] => STRING [phone1] => STRING [phone2] => STRING [phone3] => STRING [fax] => STRING [emailAddress] => STING [instructions] => STRING [deliveryDate] => DATETIME [imagePath] => STRING [isDiscontinued] => BIT [productId] => INT [productName] => STRING [productNumber] => STRING [sku] => STRING [cartDescription] => STRING [isTaxable] => BIT [shippingSurcharge] => FLOAT [affiliatePoints] => INT [weight] => FLOAT [options] => Array ( [0] => Array ( [groupName] => STRING [title] => STRING [price] => FLOAT ) [1] => Array ... ) ) [1] => Array ... ) [payments] => Array ( [0] => Array ( [paymentId] => INT [createDate] => DATETIME [modDate] => DATETIME [createUserId] => INT [modUserId] => INT [sale_addressId] => INT [accountNumber] => STRING [expDate] => DATETIME [authNumber] => STRING [cancelDate] => DATETIME [manualPayment] => BIT [processDate] => DATETIME [amount] => FLOAT [payType] => STRING [taxAmount] => FLOAT [firstName] => STRING [lastName] => STRING [user_addressId] => INT [street1] => STRING [street2] => STRING [city] => STRING [state] => STRING [zipCode] => INT [country] => STRING [phone1] => STRING [phone2] => STRING [phone3] => STRING [fax] => STRING [emailAddress] => STRING [instructions] => STRING ) [1] => Array ... ) [discounts] => Array ( [0] => Array ( [discountId] => INT [prod_discountId] => INT [discountCode] => STRING [description] => STRING [amount] => FLOAT [createDate] => DATETIME [modDate] => DATETIME [createUserId] => INT [modUserId] => INT [mutuallyExclusive] => BIT [itemId] => INT [isStatic] => BIT ) [1] => Array ... ) [order] => Array ( [orderId] => INT [orderNumber] => INT [completeDate] => DATETIME [cancelDate] => DATETIME [checkoutRegistrationDate] => DATETIME [checkoutAddressDate] => DATETIME [checkoutPaymentDate] => DATETIME [checkoutConfirmationDate] => DATETIME [add2CartDate] => DATETIME [accountUserId] => INT [adminUserId] => INT [notes] => STRING [HTTP_REFERER] => STING [ENTRY_URL] => STRING [IP_ADDRESS] => STRING [createDate] => DATETIME [modDate] => DATETIME [createUserId] => INT [modUserId] => INT [itemTotal] => FLOAT [shippingTotal] => FLOAT [taxTotal] => FLOAT [itemSurchargeTotal] => FLOAT [paymentTotal] => FLOAT [discountTotal] => FLOAT [discountFreeTotal] => FLOAT [grandTotal] => FLOAT [totalDue] => FLOAT [totalQuantity] => INT [weightTotal] => FLOAT ) )
Examples
- Example of use in Shopping Cart
// shopping cart // get our order info $completeOrderArray = eV::orderGetCompleteArray($_SESSION['order']['orderId']); // shortcut the assoc arrays returned, easier to reference later $orderArr = $completeOrderArray['order']; $itemArr = $completeOrderArray['items']; $discountArr = $completeOrderArray['discounts']; // payment info not usually shown in cart, but for the sake of this example ill shortcut it also $paymentArr = $completeOrderArray['payments']; // get shipping information to be used in shipping selection // first set a blank array $shipArr = array(); // than populate the array onlyy if items are in the cart // this will error out with no items in cart as the attempt... // ... to get the zip code from an invalid item index will error // note we pass the zip code from the first item - ship addresses are tied to items // note we get the weightTotal from the orderArr // below is a sample call if we are using zip, weight based shipping: if(!empty($itemArr)) $shipArr = eV::orderGetShipArray(NULL,$itemArr[0]['zipCode'],$orderArr['weightTotal']); // below is a smple call if we are using shipping levels // which are $ based, not ship / weight based if(!empty($itemArr)) $shipArr = eV::orderGetShipArray($orderArr['itemTotal']); // link to continue checkout process // note we only show it if items are in the cart. No reason to checkout on empty cart // note we are using the redirectIfRegistered attribute to have user skip this page if they are registered (logged in) and go directly to the checkoutShipping page if(count($itemArr) > 0) echo "<a href=\"index.php?fa=ORDER.register&redirectIfRegistered=" . rawurlencode('index.php?fa=ORDER.checkoutShipping') . "\">CONTINUE CHECKOUT</a>"; // start the cart form echo "<form action=\"index.php\" method=\"post\" name=\"cartForm\">"; // hidden attrib - rrquired for cart form, tells it what to do when submitted echo "<input type=\"hidden\" name=\"fa\" value=\"ORDER.cartUpdate\">"; // display any messages passed into the cart // this will show notification messages to the shopper, such as when they add discounts to the cart, or a discount gets dropped because they no longer qualify, etc... if(!empty($message)) echo "<hr>$message"; // drop a message that the cart is empty if nothing is in it if(count($itemArr) == 0) { echo "<hr>Your cart is empty"; } else { // something in it? well lets let visitor know what we are about to display echo "<hr>Cart Items:"; }; // alrighty lets loop thru items in cart and display them foreach($itemArr as $item){ // link back to product // note we can pass the productId in the URL and the system will find the first page that contains that product echo "<br><a href=\"index.php?productId=" . $item['productId'] . "\">" . $item['productName'] . "</a>"; // display the cart description, only if it has value if(!empty($item['cartDescription'])) echo "<br>" . $item['cartDescription']; // does this item have options? lets spit em out then.... if(count($item['options']) > 0){ echo "<br>"; // loop through the options foreach($item['options'] as $option){ // display the option echo $option['groupName'] . ": " .$option['title'] . " "; // if item has a dollar value associated with it, lets show that also... // the dollarFormat function is a quick shortcut to turn an int/float into a dollar formatted output if(floatval($option['price']) > 0) echo "(+" . eV::dollarFormat($option['price']) . ") "; // end looping through options }; // end if we have options }; // display the item sku // the item sku is the full appended sku including the productNumber + all option skus echo "<br>Item #: " . $item['sku']; // quantity field // note the name is quantity# where # is the itemId // This tells the recieving script what quantity to change echo "<input name=\"quantity" . $item['itemId'] . "\" value=\"" . $item['quantity'] . "\" type=\"text\" size=\"5\" />"; // update link // this link just submits the form // all quantities will be updates upon form submittion // the single update function tries to update quantities, discounts and shipping selection echo "<a href=\"javascript:window.document.cartForm.submit();\">UPDATE</a> "; // remove link // this does the same thing as submitting the quantity form... // except it instructs one item quantity to be set to 0... // which the system will use as a queue to drop the item all together // note that other item's quantities are not passed here... // if not passed, the system will leave thier quantity as is echo "<a href=\"index.php?fa=ORDER.cartUpdate&quantity" . $item['itemId'] . "=0\">REMOVE</a> "; // output the price per item and the total price (quantity x pricePer) echo "x " . eV::dollarFormat($item['pricePer']) . " = " . eV::dollarFormat(($item['pricePer'] * $item['quantity'])); // end looping through items }; // merchandise total echo "<hr>TOTAL:" . eV::dollarFormat($orderArr['itemTotal']); // add a discount/coupon form field echo "<hr>Enter Coupon Here: <input name=\"discountCode\" type=\"text\" size=\"15\" /> "; // link to post discount // note this link submits the cart form... // this means that all quantities will be updated as well based on entries above // and vice-verse if a discount is entered and the update is clicked for a quantity... // the system will attempt to apply the discount // the single update function tries to update quantities, discounts and shipping selection echo "<a href=\"javascript:window.document.cartForm.submit();\">APPLY</a>"; // display the discounts // loop thru discount array foreach ($discountArr as $disc){ // discount the discount code // this is the same code entered by the user to apply the discount echo "<br>Discount: " . $disc['discountCode']; // display a link to remove the discount // this is necessary as some discounts will not work with other discounts in the cart // also admins can set the carts to only allow one discount per order in Settings echo " <a href=\"index.php?fa=ORDER.discountRemove&discountId=" . $disc['discountId'] . "\">remove</a> "; // discount description echo $disc['description']; // discount value // note we add the negative "-" sign // as all discount values are in the array as positive numbers echo " -" . eV::dollarFormat($disc['amount']); // end loop through discounts }; // shipping options // lets only display if there are items in the cart if(count($itemArr) > 0){ echo "<hr>Select Shipping Option: "; // shipping option select field // note the name of the field "shipping4addressId#... // .. this is to support multiple shipping addresses with different ship methods... // .. a future function // also note that the address and shipping data are attached to the item(s) // we call on the sale_addressId from the first item since we are not using multi-shipto-addresses // only need this field if multiple shipping options for visitor, otherwise don't include echo "<select name=\"shipping4addressId" . $itemArr[0]['sale_addressId'] . "\">"; // loop thru each shipping option and display as an option for($i=0;$i<count($shipArr);$i++){ // start the option box, set the typeCode as the value echo "<option value=\"" . $shipArr[$i]['typeCode'] . "\""; // if this matches the current ship method selected by user, than select this option if($shipArr[$i]['typeCode'] == $itemArr[0]['shipTypeCode']) echo " selected "; // complete the option box, display the full ship type and it's cost echo ">" . $shipArr[$i]['type'] . " : " . eV::dollarFormat($shipArr[$i]['shipAmount']) . "</option>"; // end loop through shipping options }; // close out the shipping select field echo "\n</select>"; // zip code entry field for shipping echo " Enter Zip Code: "; // note we popoulate it with the zipCode from the first item in the cart // only need zipCode here if using zip based shipping, like fedex // level shipping is not zip code based, therefore dont need this field echo "<input type=\"text\" name=\"zipCode\" value=\"" . $itemArr[0]['zipCode'] . "\" size=\"12\" maxlength=\"10\"> "; // update link // as before, updating the form will post changes to shipping, add discount and post changes to quantities echo "<a href=\"javascript:window.document.cartForm.submit();\">update</a>"; // current shipping charge echo " Shipping: " . eV::dollarFormat($orderArr['shippingTotal']); // lets show the total due echo "<hr>Total: " . eV::dollarFormat($orderArr['totalDue']); // end if items in cart }; // repeat link to continue checkout process // note we only show it if items are in the cart. No reason to checkout on empty cart // note we are using the redirectIfRegistered attribute to have user skip this page if they are registered (logged in) and go directly to the checkoutShipping page if(count($itemArr) > 0) echo "<hr><a href=\"index.php?fa=ORDER.register&redirectIfRegistered=" . rawurlencode('index.php?fa=ORDER.checkoutShipping') . "\">CONTINUE CHECKOUT</a>"; // close out the form echo "</form>"; // add a new page // assign the new cart template to the page // check the 'hide this page from in-site searches' in the control tab // in Settings > eCommerce tab: set the cart page id to the pageId of the page you just created