Mage_Customer_AddressController Class Reference

Inheritance diagram for Mage_Customer_AddressController:

Mage_Core_Controller_Front_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 preDispatch ()
 indexAction ()
 editAction ()
 newAction ()
 formAction ()
 formPostAction ()
 deleteAction ()

Protected Member Functions

 _getSession ()


Detailed Description

Definition at line 35 of file AddressController.php.


Member Function Documentation

_getSession (  )  [protected]

Retrieve customer session object

Returns:
Mage_Customer_Model_Session

Definition at line 42 of file AddressController.php.

00043     {
00044         return Mage::getSingleton('customer/session');
00045     }

deleteAction (  ) 

Definition at line 154 of file AddressController.php.

00155     {
00156         $addressId = $this->getRequest()->getParam('id', false);
00157 
00158         if ($addressId) {
00159             $address = Mage::getModel('customer/address')->load($addressId);
00160 
00161             // Validate address_id <=> customer_id
00162             if ($address->getCustomerId() != $this->_getSession()->getCustomerId()) {
00163                 $this->_getSession()->addError($this->__('The address does not belong to this customer'));
00164                 $this->getResponse()->setRedirect(Mage::getUrl('*/*/index'));
00165                 return;
00166             }
00167 
00168             try {
00169                 $address->delete();
00170                 $this->_getSession()->addSuccess($this->__('The address was successfully deleted'));
00171             }
00172             catch (Exception $e){
00173                 $this->_getSession()->addError($this->__('There was an error while deleting the address'));
00174             }
00175         }
00176         $this->getResponse()->setRedirect(Mage::getUrl('*/*/index'));
00177     }

editAction (  ) 

Definition at line 76 of file AddressController.php.

00077     {
00078         $this->_forward('form');
00079     }

formAction (  ) 

Address book form

Definition at line 89 of file AddressController.php.

00090     {
00091         $this->loadLayout();
00092         $this->_initLayoutMessages('customer/session');
00093         if ($navigationBlock = $this->getLayout()->getBlock('customer_account_navigation')) {
00094             $navigationBlock->setActive('customer/address');
00095         }
00096         $this->renderLayout();
00097     }

formPostAction (  ) 

Definition at line 99 of file AddressController.php.

00100     {
00101         if (!$this->_validateFormKey()) {
00102             return $this->_redirect('*/*/');
00103         }
00104         // Save data
00105         if ($this->getRequest()->isPost()) {
00106             $address = Mage::getModel('customer/address')
00107                 ->setData($this->getRequest()->getPost())
00108                 ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
00109                 ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
00110                 ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
00111             $addressId = $this->getRequest()->getParam('id');
00112             if ($addressId) {
00113                 $customerAddress = $this->_getSession()->getCustomer()->getAddressById($addressId);
00114                 if ($customerAddress->getId() && $customerAddress->getCustomerId() == $this->_getSession()->getCustomerId()) {
00115                     $address->setId($addressId);
00116                 }
00117                 else {
00118                     $address->setId(null);
00119                 }
00120             }
00121             else {
00122                 $address->setId(null);
00123             }
00124             try {
00125                 $accressValidation = $address->validate();
00126                 if (true === $accressValidation) {
00127                     $address->save();
00128                     $this->_getSession()->addSuccess($this->__('The address was successfully saved'));
00129                     $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
00130                     return;
00131                 } else {
00132                     $this->_getSession()->setAddressFormData($this->getRequest()->getPost());
00133                     if (is_array($accressValidation)) {
00134                         foreach ($accressValidation as $errorMessage) {
00135                             $this->_getSession()->addError($errorMessage);
00136                         }
00137                     } else {
00138                         $this->_getSession()->addError($this->__('Can\'t save address'));
00139                     }
00140                 }
00141             }
00142             catch (Mage_Core_Exception $e) {
00143                 $this->_getSession()->setAddressFormData($this->getRequest()->getPost())
00144                     ->addException($e, $e->getMessage());
00145             }
00146             catch (Exception $e) {
00147                 $this->_getSession()->setAddressFormData($this->getRequest()->getPost())
00148                     ->addException($e, $this->__('Can\'t save address'));
00149             }
00150         }
00151         $this->_redirectError(Mage::getUrl('*/*/edit', array('id'=>$address->getId())));
00152     }

indexAction (  ) 

Customer addresses list

Definition at line 59 of file AddressController.php.

00060     {
00061         if (count($this->_getSession()->getCustomer()->getAddresses())) {
00062             $this->loadLayout();
00063             $this->_initLayoutMessages('customer/session');
00064             $this->_initLayoutMessages('catalog/session');
00065 
00066             if ($block = $this->getLayout()->getBlock('address_book')) {
00067                 $block->setRefererUrl($this->_getRefererUrl());
00068             }
00069             $this->renderLayout();
00070         }
00071         else {
00072             $this->getResponse()->setRedirect(Mage::getUrl('*/*/new'));
00073         }
00074     }

newAction (  ) 

Definition at line 81 of file AddressController.php.

00082     {
00083         $this->_forward('form');
00084     }

preDispatch (  ) 

Predispatch: shoud set layout area

Returns:
Mage_Core_Controller_Front_Action

Reimplemented from Mage_Core_Controller_Front_Action.

Definition at line 47 of file AddressController.php.

00048     {
00049         parent::preDispatch();
00050 
00051         if (!Mage::getSingleton('customer/session')->authenticate($this)) {
00052             $this->setFlag('', 'no-dispatch', true);
00053         }
00054     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:02 2009 for Magento by  doxygen 1.5.8