Functions:userGetAddresses
From Whirlwind eCommerce Wiki
Description
eV::userGetAddresses($fieldList,$userId) retrieves an array of stored address data for a particular user. This is useful for building an address book management form, also for presenting address options in a checkout address form page (billing / shipping address entry)
Syntax
$array = eV::userGetAddresses($fieldList[,$userId]);
Paramaters
- $fieldList STRING REQUIRED
- Comma separated list of fields to be returned in the array.
- Available fields to place in $fieldList:
- addressName
- firstName
- lastName
- company
- street1
- street2
- city
- state
- state_alt
- zipCode
- country
- phone1
- phone2
- phone3
- fax
- $userId INT OPTIONAL
- userId for which addresses will be retrieved. Defaults to the current logged in user ($_SESSION['user']['userId']) if not provided.
Return Values
Returns a multidimensional array of address data. The first dimension is the index of the address. The second dimension contains the fields that are returned for the address.
Return array is as follows:
Array ( [0] => Array ( [addressId] => INT // POSSIBLE fields returned (as dictated by the $fieldList attribute) [addressName] => String [firstName] => String [lastName] => String [company] => String [street1] => String [street2] => String [city] => String [state] => String [zipCode] => String [country] => String [phone1] => String [phone2] => String [phone3] => String [fax] => String ) [1] => Array... )
Examples
- Simple retrieval and display of addresses
// get addresses $addressArr = eV::userGetAddresses('firstName,lastName,city,state,zipCode'); // display addresses foreach($addressArr as $address) { echo "<hr>" . $address['firstName'] . " " . $address['lastName']; echo "<br>" . $address['city'] . " " . $address['state'] . ", " . $address['zipCode']; };
- Creating an address book management form
- Creating a billing address checkout form using stored addresses