Mage_Customer_Model_Address_Abstract Class Reference

Inheritance diagram for Mage_Customer_Model_Address_Abstract:

Mage_Core_Model_Abstract Varien_Object Mage_Customer_Model_Address Mage_Sales_Model_Order_Address Mage_Sales_Model_Quote_Address

List of all members.

Public Member Functions

 getName ()
 getStreet ($line=0)
 getStreet1 ()
 getStreet2 ()
 getStreet3 ()
 getStreet4 ()
 getStreetFull ()
 setStreetFull ($street)
 setStreet ($street)
 explodeStreetAddress ()
 implodeStreetAddress ()
 getRegion ()
 getRegionCode ()
 getRegionId ()
 getCountry ()
 getCountryModel ()
 getRegionModel ($region=null)
 getHtmlFormat ()
 getFormated ($html=false)
 format ($type)
 getConfig ()
 validate ()

Protected Member Functions

 _beforeSave ()

Protected Attributes

 $_eventPrefix = 'customer_address'
 $_eventObject = 'customer_address'

Static Protected Attributes

static $_countryModels = array()
static $_regionModels = array()


Detailed Description

Address abstract model

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Abstract.php.


Member Function Documentation

_beforeSave (  )  [protected]

Processing object before save data

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Reimplemented in Mage_Sales_Model_Quote_Address.

Definition at line 313 of file Abstract.php.

00314     {
00315         parent::_beforeSave();
00316         $this->getRegion();
00317         return $this;
00318     }

explodeStreetAddress (  ) 

Create fields street1, street2, etc.

To be used in controllers for views data

Definition at line 141 of file Abstract.php.

00142     {
00143         $streetLines = $this->getStreet();
00144         foreach ($streetLines as $i=>$line) {
00145             $this->setData('street'.($i+1), $line);
00146         }
00147         return $this;
00148     }

format ( type  ) 

Definition at line 293 of file Abstract.php.

00294     {
00295         if(!($formatType = $this->getConfig()->getFormatByCode($type))
00296             || !$formatType->getRenderer()) {
00297             return null;
00298         }
00299 
00300         return $formatType->getRenderer()->render($this);
00301     }

getConfig (  ) 

Retrive address config object

Returns:
Mage_Customer_Model_Address_Config

Definition at line 308 of file Abstract.php.

00309     {
00310         return Mage::getSingleton('customer/address_config');
00311     }

getCountry (  ) 

Definition at line 235 of file Abstract.php.

00236     {
00237         /*if ($this->getData('country_id') && !$this->getData('country')) {
00238             $this->setData('country', Mage::getModel('directory/country')->load($this->getData('country_id'))->getIso2Code());
00239         }
00240         return $this->getData('country');*/
00241         $country = $this->getCountryId();
00242         return $country ? $country : $this->getData('country');
00243     }

getCountryModel (  ) 

Retrive country model

Returns:
Mage_Directory_Model_Country

Definition at line 250 of file Abstract.php.

00251     {
00252         if(!isset(self::$_countryModels[$this->getCountryId()])) {
00253             self::$_countryModels[$this->getCountryId()] = Mage::getModel('directory/country')->load($this->getCountryId());
00254         }
00255 
00256         return self::$_countryModels[$this->getCountryId()];
00257     }

getFormated ( html = false  ) 

Deprecated:
for public function format

Definition at line 288 of file Abstract.php.

00289     {
00290         return $this->format($html ? 'html' : 'text');//Mage::getModel('directory/country')->load($this->getCountryId())->formatAddress($this, $html);
00291     }

getHtmlFormat (  ) 

Deprecated:
for public function format

Definition at line 280 of file Abstract.php.

00281     {
00282         return $this->getConfig()->getFormatByCode('html');
00283     }

getName (  ) 

Definition at line 50 of file Abstract.php.

00051     {
00052         $name = '';
00053         if ($this->getPrefix()) {
00054             $name .= $this->getPrefix() . ' ';
00055         }
00056         $name .= $this->getFirstname();
00057         if ($this->getMiddlename()) {
00058             $name .= ' ' . $this->getMiddlename();
00059         }
00060         $name .=  ' ' . $this->getLastname();
00061         if ($this->getSuffix()) {
00062             $name .= ' ' . $this->getSuffix();
00063         }
00064         return $name;
00065     }

getRegion (  ) 

Retrieve region name

Returns:
string

Definition at line 164 of file Abstract.php.

00165     {
00166         $regionId = $this->getData('region_id');
00167         $region   = $this->getData('region');
00168 
00169         if ($regionId) {
00170             if ($this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
00171                 $region = $this->getRegionModel($regionId)->getName();
00172                 $this->setData('region', $region);
00173             }
00174         }
00175 
00176         if (!empty($region) && is_string($region)) {
00177             $this->setData('region', $region);
00178         }
00179         elseif (!$regionId && is_numeric($region)) {
00180             if ($this->getRegionModel($region)->getCountryId() == $this->getCountryId()) {
00181                 $this->setData('region', $this->getRegionModel($region)->getName());
00182                 $this->setData('region_id', $region);
00183             }
00184         }
00185         elseif ($regionId && !$region) {
00186             if ($this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
00187                 $this->setData('region', $this->getRegionModel($regionId)->getName());
00188             }
00189         }
00190 
00191         return $this->getData('region');
00192     }

getRegionCode (  ) 

Return 2 letter state code if available, otherwise full region name

Definition at line 198 of file Abstract.php.

00199     {
00200         $regionId = $this->getData('region_id');
00201         $region   = $this->getData('region');
00202 
00203         if (!$regionId && is_numeric($region)) {
00204             if ($this->getRegionModel($region)->getCountryId() == $this->getCountryId()) {
00205                 $this->setData('region_code', $this->getRegionModel($region)->getCode());
00206             }
00207         }
00208         elseif ($regionId) {
00209             if ($this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
00210                 $this->setData('region_code', $this->getRegionModel($regionId)->getCode());
00211             }
00212         }
00213         elseif (is_string($region)) {
00214             $this->setData('region_code', $region);
00215         }
00216         return $this->getData('region_code');
00217     }

getRegionId (  ) 

Definition at line 219 of file Abstract.php.

00220     {
00221         $regionId = $this->getData('region_id');
00222         $region   = $this->getData('region');
00223         if (!$regionId) {
00224             if (is_numeric($region)) {
00225                 $this->setData('region_id', $region);
00226                 $this->unsRegion();
00227             } else {
00228                 $regionModel = Mage::getModel('directory/region')->loadByCode($this->getRegionCode(), $this->getCountryId());
00229                 $this->setData('region_id', $regionModel->getId());
00230             }
00231         }
00232         return $this->getData('region_id');
00233     }

getRegionModel ( region = null  ) 

Retrive country model

Returns:
Mage_Directory_Model_Country

Definition at line 264 of file Abstract.php.

00265     {
00266         if(is_null($region)) {
00267             $region = $this->getRegionId();
00268         }
00269 
00270         if(!isset(self::$_regionModels[$region])) {
00271             self::$_regionModels[$region] = Mage::getModel('directory/region')->load($region);
00272         }
00273 
00274         return self::$_regionModels[$region];
00275     }

getStreet ( line = 0  ) 

get address street

Parameters:
int $line address line index
Returns:
string

Definition at line 73 of file Abstract.php.

00074     {
00075         $street = parent::getData('street');
00076         if (-1 === $line) {
00077             return $street;
00078         } else {
00079             $arr = is_array($street) ? $street : explode("\n", $street);
00080             if (0 === $line || $line === null) {
00081                 return $arr;
00082             } elseif (isset($arr[$line-1])) {
00083                 return $arr[$line-1];
00084             } else {
00085                 return '';
00086             }
00087         }
00088     }

getStreet1 (  ) 

Definition at line 90 of file Abstract.php.

00091     {
00092         return $this->getStreet(1);
00093     }

getStreet2 (  ) 

Definition at line 95 of file Abstract.php.

00096     {
00097         return $this->getStreet(2);
00098     }

getStreet3 (  ) 

Definition at line 100 of file Abstract.php.

00101     {
00102         return $this->getStreet(3);
00103     }

getStreet4 (  ) 

Definition at line 105 of file Abstract.php.

00106     {
00107         return $this->getStreet(4);
00108     }

getStreetFull (  ) 

Definition at line 110 of file Abstract.php.

00111     {
00112         return $this->getData('street');
00113     }

implodeStreetAddress (  ) 

To be used when processing _POST

Definition at line 153 of file Abstract.php.

00154     {
00155         $this->setStreet($this->getData('street'));
00156         return $this;
00157     }

setStreet ( street  ) 

set address street informa

Parameters:
unknown_type $street
Returns:
unknown

Definition at line 126 of file Abstract.php.

00127     {
00128         if (is_array($street)) {
00129             $street = trim(implode("\n", $street));
00130         }
00131         $this->setData('street', $street);
00132         return $this;
00133     }

setStreetFull ( street  ) 

Definition at line 115 of file Abstract.php.

00116     {
00117         return $this->setStreet($street);
00118     }

validate (  ) 

Validate address attribute values

Returns:
bool

Definition at line 325 of file Abstract.php.

00326     {
00327         $errors = array();
00328         $helper = Mage::helper('customer');
00329         $this->implodeStreetAddress();
00330         if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
00331             $errors[] = $helper->__('Please enter first name.');
00332         }
00333 
00334         if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
00335             $errors[] = $helper->__('Please enter last name.');
00336         }
00337 
00338         if (!Zend_Validate::is($this->getStreet(1), 'NotEmpty')) {
00339             $errors[] = $helper->__('Please enter street.');
00340         }
00341 
00342         if (!Zend_Validate::is($this->getCity(), 'NotEmpty')) {
00343             $errors[] = $helper->__('Please enter city.');
00344         }
00345 
00346         if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
00347             $errors[] = $helper->__('Please enter telephone.');
00348         }
00349 
00350         if (!Zend_Validate::is($this->getPostcode(), 'NotEmpty')) {
00351             $errors[] = $helper->__('Please enter zip/postal code.');
00352         }
00353 
00354         if (!Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
00355             $errors[] = $helper->__('Please enter country.');
00356         }
00357 
00358         if ($this->getCountryModel()->getRegionCollection()->getSize()
00359                && !Zend_Validate::is($this->getRegionId(), 'NotEmpty')) {
00360             $errors[] = $helper->__('Please enter state/province.');
00361         }
00362 
00363         if (empty($errors)) {
00364             return true;
00365         }
00366         return $errors;
00367     }


Member Data Documentation

$_countryModels = array() [static, protected]

Definition at line 41 of file Abstract.php.

$_eventObject = 'customer_address' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 35 of file Abstract.php.

$_eventPrefix = 'customer_address' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 34 of file Abstract.php.

$_regionModels = array() [static, protected]

Definition at line 48 of file Abstract.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:03 2009 for Magento by  doxygen 1.5.8