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: * Customer address model
29: *
30: * @category Mage
31: * @package Mage_Customer
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Customer_Model_Address extends Mage_Customer_Model_Address_Abstract
35: {
36: protected $_customer;
37:
38: protected function _construct()
39: {
40: $this->_init('customer/address');
41: }
42:
43: /**
44: * Retrieve address customer identifier
45: *
46: * @return integer
47: */
48: public function getCustomerId()
49: {
50: return $this->_getData('customer_id') ? $this->_getData('customer_id') : $this->getParentId();
51: }
52:
53: /**
54: * Declare address customer identifier
55: *
56: * @param integer $id
57: * @return Mage_Customer_Model_Address
58: */
59: public function setCustomerId($id)
60: {
61: $this->setParentId($id);
62: $this->setData('customer_id', $id);
63: return $this;
64: }
65:
66: /**
67: * Retrieve address customer
68: *
69: * @return Mage_Customer_Model_Customer | false
70: */
71: public function getCustomer()
72: {
73: if (!$this->getCustomerId()) {
74: return false;
75: }
76: if (empty($this->_customer)) {
77: $this->_customer = Mage::getModel('customer/customer')
78: ->load($this->getCustomerId());
79: }
80: return $this->_customer;
81: }
82:
83: /**
84: * Specify address customer
85: *
86: * @param Mage_Customer_Model_Customer $customer
87: */
88: public function setCustomer(Mage_Customer_Model_Customer $customer)
89: {
90: $this->_customer = $customer;
91: $this->setCustomerId($customer->getId());
92: return $this;
93: }
94:
95: /**
96: * Delete customer address
97: *
98: * @return Mage_Customer_Model_Address
99: */
100: public function delete()
101: {
102: parent::delete();
103: $this->setData(array());
104: return $this;
105: }
106:
107: /**
108: * Retrieve address entity attributes
109: *
110: * @return array
111: */
112: public function getAttributes()
113: {
114: $attributes = $this->getData('attributes');
115: if (is_null($attributes)) {
116: $attributes = $this->_getResource()
117: ->loadAllAttributes($this)
118: ->getSortedAttributes();
119: $this->setData('attributes', $attributes);
120: }
121: return $attributes;
122: }
123:
124: public function __clone()
125: {
126: $this->setId(null);
127: }
128:
129: /**
130: * Return Entity Type instance
131: *
132: * @return Mage_Eav_Model_Entity_Type
133: */
134: public function getEntityType()
135: {
136: return $this->_getResource()->getEntityType();
137: }
138:
139: /**
140: * Return Entity Type ID
141: *
142: * @return int
143: */
144: public function getEntityTypeId()
145: {
146: $entityTypeId = $this->getData('entity_type_id');
147: if (!$entityTypeId) {
148: $entityTypeId = $this->getEntityType()->getId();
149: $this->setData('entity_type_id', $entityTypeId);
150: }
151: return $entityTypeId;
152: }
153:
154: /**
155: * Return Region ID
156: *
157: * @return int
158: */
159: public function getRegionId()
160: {
161: return (int)$this->getData('region_id');
162: }
163:
164: /**
165: * Set Region ID. $regionId is automatically converted to integer
166: *
167: * @param int $regionId
168: * @return Mage_Customer_Model_Address
169: */
170: public function setRegionId($regionId)
171: {
172: $this->setData('region_id', (int)$regionId);
173: return $this;
174: }
175: }
176: