Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Customer_AccountController
  • Mage_Customer_AddressController
  • Mage_Customer_Block_Account
  • Mage_Customer_Block_Account_Dashboard
  • Mage_Customer_Block_Account_Dashboard_Address
  • Mage_Customer_Block_Account_Dashboard_Block
  • Mage_Customer_Block_Account_Dashboard_Hello
  • Mage_Customer_Block_Account_Dashboard_Info
  • Mage_Customer_Block_Account_Dashboard_Newsletter
  • Mage_Customer_Block_Account_Dashboard_Sidebar
  • Mage_Customer_Block_Account_Forgotpassword
  • Mage_Customer_Block_Account_Navigation
  • Mage_Customer_Block_Account_Resetpassword
  • Mage_Customer_Block_Address_Book
  • Mage_Customer_Block_Address_Edit
  • Mage_Customer_Block_Address_Renderer_Default
  • Mage_Customer_Block_Form_Edit
  • Mage_Customer_Block_Form_Login
  • Mage_Customer_Block_Form_Register
  • Mage_Customer_Block_Newsletter
  • Mage_Customer_Block_Widget_Abstract
  • Mage_Customer_Block_Widget_Dob
  • Mage_Customer_Block_Widget_Gender
  • Mage_Customer_Block_Widget_Name
  • Mage_Customer_Block_Widget_Taxvat
  • Mage_Customer_Helper_Address
  • Mage_Customer_Helper_Data
  • Mage_Customer_Model_Address
  • Mage_Customer_Model_Address_Abstract
  • Mage_Customer_Model_Address_Api
  • Mage_Customer_Model_Address_Api_V2
  • Mage_Customer_Model_Address_Config
  • Mage_Customer_Model_Api2_Customer
  • Mage_Customer_Model_Api2_Customer_Address
  • Mage_Customer_Model_Api2_Customer_Address_Rest
  • Mage_Customer_Model_Api2_Customer_Address_Rest_Admin_V1
  • Mage_Customer_Model_Api2_Customer_Address_Rest_Customer_V1
  • Mage_Customer_Model_Api2_Customer_Address_Validator
  • Mage_Customer_Model_Api2_Customer_Rest
  • Mage_Customer_Model_Api2_Customer_Rest_Admin_V1
  • Mage_Customer_Model_Api2_Customer_Rest_Customer_V1
  • Mage_Customer_Model_Api_Resource
  • Mage_Customer_Model_Attribute
  • Mage_Customer_Model_Attribute_Backend_Data_Boolean
  • Mage_Customer_Model_Attribute_Data
  • Mage_Customer_Model_Attribute_Data_Abstract
  • Mage_Customer_Model_Attribute_Data_Boolean
  • Mage_Customer_Model_Attribute_Data_Date
  • Mage_Customer_Model_Attribute_Data_File
  • Mage_Customer_Model_Attribute_Data_Hidden
  • Mage_Customer_Model_Attribute_Data_Image
  • Mage_Customer_Model_Attribute_Data_Multiline
  • Mage_Customer_Model_Attribute_Data_Multiselect
  • Mage_Customer_Model_Attribute_Data_Postcode
  • Mage_Customer_Model_Attribute_Data_Select
  • Mage_Customer_Model_Attribute_Data_Text
  • Mage_Customer_Model_Attribute_Data_Textarea
  • Mage_Customer_Model_Config_Share
  • Mage_Customer_Model_Convert_Adapter_Customer
  • Mage_Customer_Model_Convert_Parser_Customer
  • Mage_Customer_Model_Customer
  • Mage_Customer_Model_Customer_Api
  • Mage_Customer_Model_Customer_Api_V2
  • Mage_Customer_Model_Customer_Attribute_Backend_Billing
  • Mage_Customer_Model_Customer_Attribute_Backend_Password
  • Mage_Customer_Model_Customer_Attribute_Backend_Shipping
  • Mage_Customer_Model_Customer_Attribute_Backend_Store
  • Mage_Customer_Model_Customer_Attribute_Backend_Website
  • Mage_Customer_Model_Customer_Attribute_Source_Group
  • Mage_Customer_Model_Customer_Attribute_Source_Store
  • Mage_Customer_Model_Customer_Attribute_Source_Website
  • Mage_Customer_Model_Entity_Address
  • Mage_Customer_Model_Entity_Address_Attribute_Backend_Region
  • Mage_Customer_Model_Entity_Address_Attribute_Backend_Street
  • Mage_Customer_Model_Entity_Address_Attribute_Collection
  • Mage_Customer_Model_Entity_Address_Attribute_Source_Country
  • Mage_Customer_Model_Entity_Address_Attribute_Source_Region
  • Mage_Customer_Model_Entity_Address_Collection
  • Mage_Customer_Model_Entity_Attribute
  • Mage_Customer_Model_Entity_Attribute_Collection
  • Mage_Customer_Model_Entity_Customer
  • Mage_Customer_Model_Entity_Customer_Collection
  • Mage_Customer_Model_Entity_Form_Attribute
  • Mage_Customer_Model_Entity_Form_Attribute_Collection
  • Mage_Customer_Model_Entity_Group
  • Mage_Customer_Model_Entity_Group_Collection
  • Mage_Customer_Model_Entity_Setup
  • Mage_Customer_Model_Entity_Wishlist_Collection
  • Mage_Customer_Model_Form
  • Mage_Customer_Model_Group
  • Mage_Customer_Model_Group_Api
  • Mage_Customer_Model_Group_Api_V2
  • Mage_Customer_Model_Observer
  • Mage_Customer_Model_Resource_Address
  • Mage_Customer_Model_Resource_Address_Attribute_Backend_Region
  • Mage_Customer_Model_Resource_Address_Attribute_Backend_Street
  • Mage_Customer_Model_Resource_Address_Attribute_Collection
  • Mage_Customer_Model_Resource_Address_Attribute_Source_Country
  • Mage_Customer_Model_Resource_Address_Attribute_Source_Region
  • Mage_Customer_Model_Resource_Address_Collection
  • Mage_Customer_Model_Resource_Attribute
  • Mage_Customer_Model_Resource_Attribute_Collection
  • Mage_Customer_Model_Resource_Customer
  • Mage_Customer_Model_Resource_Customer_Collection
  • Mage_Customer_Model_Resource_Form_Attribute
  • Mage_Customer_Model_Resource_Form_Attribute_Collection
  • Mage_Customer_Model_Resource_Group
  • Mage_Customer_Model_Resource_Group_Collection
  • Mage_Customer_Model_Resource_Setup
  • Mage_Customer_Model_Resource_Wishlist_Collection
  • Mage_Customer_Model_Session
  • Mage_Customer_ReviewController

Interfaces

  • Mage_Customer_Block_Address_Renderer_Interface

Exceptions

  • Mage_Customer_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Customer
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Address abstract model
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Customer
 32:  * @author     Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Customer_Model_Address_Abstract extends Mage_Core_Model_Abstract
 35: {
 36:     /**
 37:      * Possible customer address types
 38:      */
 39:     const TYPE_BILLING  = 'billing';
 40:     const TYPE_SHIPPING = 'shipping';
 41: 
 42:     /**
 43:      * Prefix of model events
 44:      *
 45:      * @var string
 46:      */
 47:     protected $_eventPrefix = 'customer_address';
 48: 
 49:     /**
 50:      * Name of event object
 51:      *
 52:      * @var string
 53:      */
 54:     protected $_eventObject = 'customer_address';
 55: 
 56:     /**
 57:      * Directory country models
 58:      *
 59:      * @var array
 60:      */
 61:     static protected $_countryModels = array();
 62: 
 63:     /**
 64:      * Directory region models
 65:      *
 66:      * @var array
 67:      */
 68:     static protected $_regionModels = array();
 69: 
 70:     /**
 71:      * Get full customer name
 72:      *
 73:      * @return string
 74:      */
 75:     public function getName()
 76:     {
 77:         $name = '';
 78:         $config = Mage::getSingleton('eav/config');
 79:         if ($config->getAttribute('customer_address', 'prefix')->getIsVisible() && $this->getPrefix()) {
 80:             $name .= $this->getPrefix() . ' ';
 81:         }
 82:         $name .= $this->getFirstname();
 83:         if ($config->getAttribute('customer_address', 'middlename')->getIsVisible() && $this->getMiddlename()) {
 84:             $name .= ' ' . $this->getMiddlename();
 85:         }
 86:         $name .=  ' ' . $this->getLastname();
 87:         if ($config->getAttribute('customer_address', 'suffix')->getIsVisible() && $this->getSuffix()) {
 88:             $name .= ' ' . $this->getSuffix();
 89:         }
 90:         return $name;
 91:     }
 92: 
 93:     /**
 94:      * get address street
 95:      *
 96:      * @param   int $line address line index
 97:      * @return  string
 98:      */
 99:     public function getStreet($line=0)
100:     {
101:         $street = parent::getData('street');
102:         if (-1 === $line) {
103:             return $street;
104:         } else {
105:             $arr = is_array($street) ? $street : explode("\n", $street);
106:             if (0 === $line || $line === null) {
107:                 return $arr;
108:             } elseif (isset($arr[$line-1])) {
109:                 return $arr[$line-1];
110:             } else {
111:                 return '';
112:             }
113:         }
114:     }
115: 
116:     public function getStreet1()
117:     {
118:         return $this->getStreet(1);
119:     }
120: 
121:     public function getStreet2()
122:     {
123:         return $this->getStreet(2);
124:     }
125: 
126:     public function getStreet3()
127:     {
128:         return $this->getStreet(3);
129:     }
130: 
131:     public function getStreet4()
132:     {
133:         return $this->getStreet(4);
134:     }
135: 
136:     public function getStreetFull()
137:     {
138:         return $this->getData('street');
139:     }
140: 
141:     public function setStreetFull($street)
142:     {
143:         return $this->setStreet($street);
144:     }
145: 
146:     /**
147:      * set address street informa
148:      *
149:      * @param unknown_type $street
150:      * @return unknown
151:      */
152:     public function setStreet($street)
153:     {
154:         if (is_array($street)) {
155:             $street = trim(implode("\n", $street));
156:         }
157:         $this->setData('street', $street);
158:         return $this;
159:     }
160: 
161:     /**
162:      * Create fields street1, street2, etc.
163:      *
164:      * To be used in controllers for views data
165:      *
166:      */
167:     public function explodeStreetAddress()
168:     {
169:         $streetLines = $this->getStreet();
170:         foreach ($streetLines as $i=>$line) {
171:             $this->setData('street'.($i+1), $line);
172:         }
173:         return $this;
174:     }
175: 
176:     /**
177:      * To be used when processing _POST
178:      */
179:     public function implodeStreetAddress()
180:     {
181:         $this->setStreet($this->getData('street'));
182:         return $this;
183:     }
184: 
185:     /**
186:      * Retrieve region name
187:      *
188:      * @return string
189:      */
190:     public function getRegion()
191:     {
192:         $regionId = $this->getData('region_id');
193:         $region   = $this->getData('region');
194: 
195:         if ($regionId) {
196:                if ($this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
197:                    $region = $this->getRegionModel($regionId)->getName();
198:                 $this->setData('region', $region);
199:             }
200:         }
201: 
202:         if (!empty($region) && is_string($region)) {
203:             $this->setData('region', $region);
204:         }
205:         elseif (!$regionId && is_numeric($region)) {
206:             if ($this->getRegionModel($region)->getCountryId() == $this->getCountryId()) {
207:                 $this->setData('region', $this->getRegionModel($region)->getName());
208:                 $this->setData('region_id', $region);
209:             }
210:         }
211:         elseif ($regionId && !$region) {
212:                if ($this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
213:                 $this->setData('region', $this->getRegionModel($regionId)->getName());
214:             }
215:         }
216: 
217:         return $this->getData('region');
218:     }
219: 
220:     /**
221:      * Return 2 letter state code if available, otherwise full region name
222:      *
223:      */
224:     public function getRegionCode()
225:     {
226:         $regionId = $this->getData('region_id');
227:         $region   = $this->getData('region');
228: 
229:         if (!$regionId && is_numeric($region)) {
230:             if ($this->getRegionModel($region)->getCountryId() == $this->getCountryId()) {
231:                 $this->setData('region_code', $this->getRegionModel($region)->getCode());
232:             }
233:         }
234:         elseif ($regionId) {
235:             if ($this->getRegionModel($regionId)->getCountryId() == $this->getCountryId()) {
236:                 $this->setData('region_code', $this->getRegionModel($regionId)->getCode());
237:             }
238:         }
239:         elseif (is_string($region)) {
240:             $this->setData('region_code', $region);
241:         }
242:         return $this->getData('region_code');
243:     }
244: 
245:     public function getRegionId()
246:     {
247:         $regionId = $this->getData('region_id');
248:         $region   = $this->getData('region');
249:         if (!$regionId) {
250:             if (is_numeric($region)) {
251:                 $this->setData('region_id', $region);
252:                 $this->unsRegion();
253:             } else {
254:                 $regionModel = Mage::getModel('directory/region')
255:                     ->loadByCode($this->getRegionCode(), $this->getCountryId());
256:                 $this->setData('region_id', $regionModel->getId());
257:             }
258:         }
259:         return $this->getData('region_id');
260:     }
261: 
262:     public function getCountry()
263:     {
264:         /*if ($this->getData('country_id') && !$this->getData('country')) {
265:             $this->setData('country', Mage::getModel('directory/country')
266:                 ->load($this->getData('country_id'))->getIso2Code());
267:         }
268:         return $this->getData('country');*/
269:         $country = $this->getCountryId();
270:         return $country ? $country : $this->getData('country');
271:     }
272: 
273:     /**
274:      * Retrive country model
275:      *
276:      * @return Mage_Directory_Model_Country
277:      */
278:     public function getCountryModel()
279:     {
280:         if(!isset(self::$_countryModels[$this->getCountryId()])) {
281:             self::$_countryModels[$this->getCountryId()] = Mage::getModel('directory/country')
282:                 ->load($this->getCountryId());
283:         }
284: 
285:         return self::$_countryModels[$this->getCountryId()];
286:     }
287: 
288:     /**
289:      * Retrive country model
290:      *
291:      * @return Mage_Directory_Model_Country
292:      */
293:     public function getRegionModel($region=null)
294:     {
295:         if(is_null($region)) {
296:             $region = $this->getRegionId();
297:         }
298: 
299:         if(!isset(self::$_regionModels[$region])) {
300:             self::$_regionModels[$region] = Mage::getModel('directory/region')->load($region);
301:         }
302: 
303:         return self::$_regionModels[$region];
304:     }
305: 
306:     /**
307:      * @deprecated for public function format
308:      */
309:     public function getHtmlFormat()
310:     {
311:         return $this->getConfig()->getFormatByCode('html');
312:     }
313: 
314:     /**
315:      * @deprecated for public function format
316:      */
317:     public function getFormated($html=false)
318:     {
319:         return $this->format($html ? 'html' : 'text');
320:         //Mage::getModel('directory/country')->load($this->getCountryId())->formatAddress($this, $html);
321:     }
322: 
323:     public function format($type)
324:     {
325:         if(!($formatType = $this->getConfig()->getFormatByCode($type))
326:             || !$formatType->getRenderer()) {
327:             return null;
328:         }
329:         Mage::dispatchEvent('customer_address_format', array('type' => $formatType, 'address' => $this));
330:         return $formatType->getRenderer()->render($this);
331:     }
332: 
333:     /**
334:      * Retrive address config object
335:      *
336:      * @return Mage_Customer_Model_Address_Config
337:      */
338:     public function getConfig()
339:     {
340:         return Mage::getSingleton('customer/address_config');
341:     }
342: 
343:     protected function _beforeSave()
344:     {
345:         parent::_beforeSave();
346:         $this->getRegion();
347:         return $this;
348:     }
349: 
350:     /**
351:      * Validate address attribute values
352:      *
353:      * @return bool
354:      */
355:     public function validate()
356:     {
357:         $errors = array();
358:         $this->implodeStreetAddress();
359:         if (!Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
360:             $errors[] = Mage::helper('customer')->__('Please enter the first name.');
361:         }
362: 
363:         if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
364:             $errors[] = Mage::helper('customer')->__('Please enter the last name.');
365:         }
366: 
367:         if (!Zend_Validate::is($this->getStreet(1), 'NotEmpty')) {
368:             $errors[] = Mage::helper('customer')->__('Please enter the street.');
369:         }
370: 
371:         if (!Zend_Validate::is($this->getCity(), 'NotEmpty')) {
372:             $errors[] = Mage::helper('customer')->__('Please enter the city.');
373:         }
374: 
375:         if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
376:             $errors[] = Mage::helper('customer')->__('Please enter the telephone number.');
377:         }
378: 
379:         $_havingOptionalZip = Mage::helper('directory')->getCountriesWithOptionalZip();
380:         if (!in_array($this->getCountryId(), $_havingOptionalZip)
381:             && !Zend_Validate::is($this->getPostcode(), 'NotEmpty')
382:         ) {
383:             $errors[] = Mage::helper('customer')->__('Please enter the zip/postal code.');
384:         }
385: 
386:         if (!Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
387:             $errors[] = Mage::helper('customer')->__('Please enter the country.');
388:         }
389: 
390:         if ($this->getCountryModel()->getRegionCollection()->getSize()
391:                && !Zend_Validate::is($this->getRegionId(), 'NotEmpty')
392:                && Mage::helper('directory')->isRegionRequired($this->getCountryId())
393:         ) {
394:             $errors[] = Mage::helper('customer')->__('Please enter the state/province.');
395:         }
396: 
397:         if (empty($errors) || $this->getShouldIgnoreValidation()) {
398:             return true;
399:         }
400:         return $errors;
401:     }
402: }
403: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0