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_Sales
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: /**
29: * Sales order address model
30: *
31: * @method Mage_Sales_Model_Resource_Order_Address _getResource()
32: * @method Mage_Sales_Model_Resource_Order_Address getResource()
33: * @method int getParentId()
34: * @method Mage_Sales_Model_Order_Address setParentId(int $value)
35: * @method int getCustomerAddressId()
36: * @method Mage_Sales_Model_Order_Address setCustomerAddressId(int $value)
37: * @method int getQuoteAddressId()
38: * @method Mage_Sales_Model_Order_Address setQuoteAddressId(int $value)
39: * @method Mage_Sales_Model_Order_Address setRegionId(int $value)
40: * @method int getCustomerId()
41: * @method Mage_Sales_Model_Order_Address setCustomerId(int $value)
42: * @method string getFax()
43: * @method Mage_Sales_Model_Order_Address setFax(string $value)
44: * @method Mage_Sales_Model_Order_Address setRegion(string $value)
45: * @method string getPostcode()
46: * @method Mage_Sales_Model_Order_Address setPostcode(string $value)
47: * @method string getLastname()
48: * @method Mage_Sales_Model_Order_Address setLastname(string $value)
49: * @method string getCity()
50: * @method Mage_Sales_Model_Order_Address setCity(string $value)
51: * @method string getEmail()
52: * @method Mage_Sales_Model_Order_Address setEmail(string $value)
53: * @method string getTelephone()
54: * @method Mage_Sales_Model_Order_Address setTelephone(string $value)
55: * @method string getCountryId()
56: * @method Mage_Sales_Model_Order_Address setCountryId(string $value)
57: * @method string getFirstname()
58: * @method Mage_Sales_Model_Order_Address setFirstname(string $value)
59: * @method string getAddressType()
60: * @method Mage_Sales_Model_Order_Address setAddressType(string $value)
61: * @method string getPrefix()
62: * @method Mage_Sales_Model_Order_Address setPrefix(string $value)
63: * @method string getMiddlename()
64: * @method Mage_Sales_Model_Order_Address setMiddlename(string $value)
65: * @method string getSuffix()
66: * @method Mage_Sales_Model_Order_Address setSuffix(string $value)
67: * @method string getCompany()
68: * @method Mage_Sales_Model_Order_Address setCompany(string $value)
69: *
70: * @category Mage
71: * @package Mage_Sales
72: * @author Magento Core Team <core@magentocommerce.com>
73: */
74: class Mage_Sales_Model_Order_Address extends Mage_Customer_Model_Address_Abstract
75: {
76: protected $_order;
77:
78: protected $_eventPrefix = 'sales_order_address';
79: protected $_eventObject = 'address';
80:
81: /**
82: * Initialize resource
83: */
84: protected function _construct()
85: {
86: $this->_init('sales/order_address');
87: }
88:
89: /**
90: * Init mapping array of short fields to its full names
91: *
92: * @return Mage_Sales_Model_Order_Address
93: */
94: protected function _initOldFieldsMap()
95: {
96: $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order_address');
97: return $this;
98: }
99:
100: /**
101: * Set order
102: *
103: * @return Mage_Sales_Model_Order_Address
104: */
105: public function setOrder(Mage_Sales_Model_Order $order)
106: {
107: $this->_order = $order;
108: return $this;
109: }
110:
111: /**
112: * Get order
113: *
114: * @return Mage_Sales_Model_Order
115: */
116: public function getOrder()
117: {
118: if (!$this->_order) {
119: $this->_order = Mage::getModel('sales/order')->load($this->getParentId());
120: }
121: return $this->_order;
122: }
123:
124: /**
125: * Before object save manipulations
126: *
127: * @return Mage_Sales_Model_Order_Address
128: */
129: protected function _beforeSave()
130: {
131: parent::_beforeSave();
132:
133: if (!$this->getParentId() && $this->getOrder()) {
134: $this->setParentId($this->getOrder()->getId());
135: }
136:
137: // Init customer address id if customer address is assigned
138: if ($this->getCustomerAddress()) {
139: $this->setCustomerAddressId($this->getCustomerAddress()->getId());
140: }
141:
142: return $this;
143: }
144: }
145: