00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Customer_Model_Entity_Address extends Mage_Eav_Model_Entity_Abstract
00035 {
00036 public function __construct()
00037 {
00038 $resource = Mage::getSingleton('core/resource');
00039 $this->setType('customer_address')->setConnection(
00040 $resource->getConnection('customer_read'),
00041 $resource->getConnection('customer_write')
00042 );
00043 }
00044
00045 protected function _afterSave(Varien_Object $address)
00046 {
00047 if ($address->getId() && ($address->getIsDefaultBilling() || $address->getIsDefaultShipping())) {
00048 $customer = Mage::getModel('customer/customer')
00049 ->load($address->getCustomerId());
00050
00051 if ($address->getIsDefaultBilling()) {
00052 $customer->setDefaultBilling($address->getId());
00053 }
00054 if ($address->getIsDefaultShipping()) {
00055 $customer->setDefaultShipping($address->getId());
00056 }
00057 $customer->save();
00058 }
00059 return $this;
00060 }
00061
00062 public function getCustomerId($object)
00063 {
00064 return $object->getData('customer_id') ? $object->getData('customer_id') :$object->getParentId();
00065 }
00066
00067 public function setCustomerId($object, $id)
00068 {
00069 $object->setParentId($id);
00070 $object->setData('customer_id', $id);
00071 return $object;
00072 }
00073 }