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: /**
29: * Customer address entity resource model
30: *
31: * @category Mage
32: * @package Mage_Customer
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Customer_Model_Resource_Address extends Mage_Eav_Model_Entity_Abstract
36: {
37: /**
38: * Resource initialization
39: */
40: protected function _construct()
41: {
42: $resource = Mage::getSingleton('core/resource');
43: $this->setType('customer_address')->setConnection(
44: $resource->getConnection('customer_read'),
45: $resource->getConnection('customer_write')
46: );
47: }
48:
49: /**
50: * Set default shipping to address
51: *
52: * @param Varien_Object $address
53: * @return Mage_Customer_Model_Resource_Address
54: */
55: protected function _afterSave(Varien_Object $address)
56: {
57: if ($address->getIsCustomerSaveTransaction()) {
58: return $this;
59: }
60: if ($address->getId() && ($address->getIsDefaultBilling() || $address->getIsDefaultShipping())) {
61: $customer = Mage::getModel('customer/customer')
62: ->load($address->getCustomerId());
63:
64: if ($address->getIsDefaultBilling()) {
65: $customer->setDefaultBilling($address->getId());
66: }
67: if ($address->getIsDefaultShipping()) {
68: $customer->setDefaultShipping($address->getId());
69: }
70: $customer->save();
71: }
72: return $this;
73: }
74:
75: /**
76: * Return customer id
77: * @deprecated
78: *
79: * @param Mage_Customer_Model_Address $object
80: * @return int
81: */
82: public function getCustomerId($object)
83: {
84: return $object->getData('customer_id') ? $object->getData('customer_id') : $object->getParentId();
85: }
86:
87: /**
88: * Set customer id
89: * @deprecated
90: *
91: * @param Mage_Customer_Model_Address $object
92: * @param int $id
93: * @return Mage_Customer_Model_Address
94: */
95: public function setCustomerId($object, $id)
96: {
97: return $this;
98: }
99: }
100: