00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Customer 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Customer address edit block 00029 * 00030 * @category Mage 00031 * @package Mage_Customer 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_Customer_Block_Address_Edit extends Mage_Directory_Block_Data 00035 { 00036 protected $_address; 00037 protected $_countryCollection; 00038 protected $_regionCollection; 00039 00040 protected function _prepareLayout() 00041 { 00042 parent::_prepareLayout(); 00043 $this->_address = Mage::getModel('customer/address'); 00044 00045 // Init address object 00046 if ($id = $this->getRequest()->getParam('id')) { 00047 $this->_address->load($id); 00048 if ($this->_address->getCustomerId() != Mage::getSingleton('customer/session')->getCustomerId()) { 00049 $this->_address->setData(array()); 00050 } 00051 } 00052 00053 if ($headBlock = $this->getLayout()->getBlock('head')) { 00054 $headBlock->setTitle($this->getTitle()); 00055 } 00056 if ($postedData = Mage::getSingleton('customer/session')->getAddressFormData(true)) { 00057 $this->_address->setData($postedData); 00058 } 00059 } 00060 00061 public function getTitle() 00062 { 00063 if ($title = $this->getData('title')) { 00064 return $title; 00065 } 00066 if ($this->getAddress()->getId()) { 00067 $title = Mage::helper('customer')->__('Edit Address'); 00068 } 00069 else { 00070 $title = Mage::helper('customer')->__('Add New Address'); 00071 } 00072 return $title; 00073 } 00074 00075 public function getBackUrl() 00076 { 00077 if ($this->getData('back_url')) { 00078 return $this->getData('back_url'); 00079 } 00080 00081 if ($this->getCustomerAddressCount()) { 00082 return $this->getUrl('customer/address'); 00083 } else { 00084 return $this->getUrl('customer/account/'); 00085 } 00086 } 00087 00088 public function getSaveUrl() 00089 { 00090 return Mage::getUrl('customer/address/formPost', array('_secure'=>true, 'id'=>$this->getAddress()->getId())); 00091 } 00092 00093 public function getAddress() 00094 { 00095 return $this->_address; 00096 } 00097 00098 public function getCountryId() 00099 { 00100 if ($countryId = $this->getAddress()->getCountryId()) { 00101 return $countryId; 00102 } 00103 return parent::getCountryId(); 00104 } 00105 00106 public function getRegionId() 00107 { 00108 return $this->getAddress()->getRegionId(); 00109 } 00110 00111 public function getCustomerAddressCount() 00112 { 00113 return count(Mage::getSingleton('customer/session')->getCustomer()->getAddresses()); 00114 } 00115 00116 public function canSetAsDefaultBilling() 00117 { 00118 if (!$this->getAddress()->getId()) { 00119 return $this->getCustomerAddressCount(); 00120 } 00121 return !$this->isDefaultBilling(); 00122 } 00123 00124 public function canSetAsDefaultShipping() 00125 { 00126 if (!$this->getAddress()->getId()) { 00127 return $this->getCustomerAddressCount(); 00128 } 00129 return !$this->isDefaultShipping();; 00130 } 00131 00132 public function isDefaultBilling() 00133 { 00134 return $this->getAddress()->getId() && $this->getAddress()->getId()==Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling(); 00135 } 00136 00137 public function isDefaultShipping() 00138 { 00139 return $this->getAddress()->getId() && $this->getAddress()->getId()==Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping(); 00140 } 00141 00142 public function getCustomer() 00143 { 00144 return Mage::getSingleton('customer/session')->getCustomer(); 00145 } 00146 00147 public function getBackButtonUrl() 00148 {//echo '=>'.$this->getCustomerAddressCount();die(); 00149 if ($this->getCustomerAddressCount()) { 00150 return $this->getUrl('customer/address'); 00151 } else { 00152 return $this->getUrl('customer/account/'); 00153 } 00154 } 00155 }