Mage_Adminhtml_CustomerController Class Reference

Inheritance diagram for Mage_Adminhtml_CustomerController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 indexAction ()
 gridAction ()
 editAction ()
 newAction ()
 deleteAction ()
 saveAction ()
 exportCsvAction ()
 exportXmlAction ()
 ordersAction ()
 lastOrdersAction ()
 newsletterAction ()
 wishlistAction ()
 viewWishlistAction ()
 cartAction ()
 viewCartAction ()
 cartsAction ()
 productReviewsAction ()
 productTagsAction ()
 tagGridAction ()
 validateAction ()
 massSubscribeAction ()
 massUnsubscribeAction ()
 massDeleteAction ()
 massAssignGroupAction ()

Protected Member Functions

 _initCustomer ($idFieldName= 'id')
 _sendUploadResponse ($fileName, $content, $contentType='application/octet-stream')
 _isAllowed ()


Detailed Description

Definition at line 34 of file CustomerController.php.


Member Function Documentation

_initCustomer ( idFieldName = 'id'  )  [protected]

Definition at line 37 of file CustomerController.php.

00038     {
00039         $customerId = (int) $this->getRequest()->getParam($idFieldName);
00040         $customer = Mage::getModel('customer/customer');
00041 
00042         if ($customerId) {
00043             $customer->load($customerId);
00044         }
00045 
00046         Mage::register('current_customer', $customer);
00047         return $this;
00048     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 574 of file CustomerController.php.

00575     {
00576         return Mage::getSingleton('admin/session')->isAllowed('customer/manage');
00577     }

_sendUploadResponse ( fileName,
content,
contentType = 'application/octet-stream' 
) [protected]

Prepare file download response

Todo:
remove in 1.3
Deprecated:
please use $this->_prepareDownloadResponse()
See also:
Mage_Adminhtml_Controller_Action._prepareDownloadResponse()
Parameters:
string $fileName
string $content
string $contentType

Definition at line 283 of file CustomerController.php.

00284     {
00285         $this->_prepareDownloadResponse($fileName, $content, $contentType);
00286     }

cartAction (  ) 

[Handle and then] get a cart grid contents

Returns:
string

Definition at line 353 of file CustomerController.php.

00354     {
00355         $this->_initCustomer();
00356         $websiteId = $this->getRequest()->getParam('website_id');
00357 
00358         // delete an item from cart
00359         if ($deleteItemId = $this->getRequest()->getPost('delete')) {
00360             $quote = Mage::getModel('sales/quote')
00361                 ->setWebsite(Mage::app()->getWebsite($websiteId))
00362                 ->loadByCustomer(Mage::registry('current_customer'));
00363             $item = $quote->getItemById($deleteItemId);
00364             $quote->removeItem($deleteItemId);
00365             $quote->save();
00366         }
00367 
00368         $this->getResponse()->setBody(
00369             $this->getLayout()->createBlock('adminhtml/customer_edit_tab_cart', '', array('website_id'=>$websiteId))
00370                 ->toHtml()
00371         );
00372     }

cartsAction (  ) 

Get shopping carts from all websites for specified client

Returns:
string

Definition at line 394 of file CustomerController.php.

00395     {
00396         $this->_initCustomer();
00397         $this->getResponse()->setBody(
00398             $this->getLayout()->createBlock('adminhtml/customer_edit_tab_carts')->toHtml()
00399         );
00400     }

deleteAction (  ) 

Delete customer action

Definition at line 131 of file CustomerController.php.

00132     {
00133         $this->_initCustomer();
00134         $customer = Mage::registry('current_customer');
00135         if ($customer->getId()) {
00136             try {
00137                 $customer->load($customer->getId());
00138                 $customer->delete();
00139                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Customer was deleted'));
00140             }
00141             catch (Exception $e){
00142                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00143             }
00144         }
00145         $this->_redirect('*/customer');
00146     }

editAction (  ) 

Customer edit action

Set active menu item

Definition at line 91 of file CustomerController.php.

00092     {
00093         $this->_initCustomer();
00094         $this->loadLayout();
00095 
00096         $customer = Mage::registry('current_customer');
00097 
00098         // set entered data if was error when we do save
00099         $data = Mage::getSingleton('adminhtml/session')->getCustomerData(true);
00100 
00101         if (isset($data['account'])) {
00102             $customer->addData($data['account']);
00103         }
00104         if (isset($data['address']) && is_array($data['address'])) {
00105             foreach ($data['address'] as $addressId => $address) {
00106                 $addressModel = Mage::getModel('customer/address')->setData($address)
00107                     ->setId($addressId);
00108                 $customer->addAddress($addressModel);
00109             }
00110         }
00111 
00112         /**
00113          * Set active menu item
00114          */
00115         $this->_setActiveMenu('customer/new');
00116 
00117         $this->renderLayout();
00118     }

exportCsvAction (  ) 

Export customer grid to CSV format

Definition at line 252 of file CustomerController.php.

00253     {
00254         $fileName   = 'customers.csv';
00255         $content    = $this->getLayout()->createBlock('adminhtml/customer_grid')
00256             ->getCsv();
00257 
00258         $this->_prepareDownloadResponse($fileName, $content);
00259     }

exportXmlAction (  ) 

Export customer grid to XML format

Definition at line 264 of file CustomerController.php.

00265     {
00266         $fileName   = 'customers.xml';
00267         $content    = $this->getLayout()->createBlock('adminhtml/customer_grid')
00268             ->getXml();
00269 
00270         $this->_prepareDownloadResponse($fileName, $content);
00271     }

gridAction (  ) 

Definition at line 82 of file CustomerController.php.

00083     {
00084         $this->loadLayout();
00085         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/customer_grid')->toHtml());
00086     }

indexAction (  ) 

Customers list action

Set active menu item

Append customers block to content

Add breadcrumb item

Definition at line 53 of file CustomerController.php.

00054     {
00055         if ($this->getRequest()->getQuery('ajax')) {
00056             $this->_forward('grid');
00057             return;
00058         }
00059         $this->loadLayout();
00060 
00061         /**
00062          * Set active menu item
00063          */
00064         $this->_setActiveMenu('customer/manage');
00065 
00066         /**
00067          * Append customers block to content
00068          */
00069         $this->_addContent(
00070             $this->getLayout()->createBlock('adminhtml/customer', 'customer')
00071         );
00072 
00073         /**
00074          * Add breadcrumb item
00075          */
00076         $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Customers'), Mage::helper('adminhtml')->__('Customers'));
00077         $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Manage Customers'), Mage::helper('adminhtml')->__('Manage Customers'));
00078 
00079         $this->renderLayout();
00080     }

lastOrdersAction (  ) 

Customer last orders grid for ajax

Definition at line 301 of file CustomerController.php.

00301                                        {
00302         $this->_initCustomer();
00303         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/customer_edit_tab_view_orders')->toHtml());
00304     }

massAssignGroupAction (  ) 

Definition at line 549 of file CustomerController.php.

00550     {
00551         $customersIds = $this->getRequest()->getParam('customer');
00552         if(!is_array($customersIds)) {
00553              Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s)'));
00554         } else {
00555             try {
00556                 foreach ($customersIds as $customerId) {
00557                     $customer = Mage::getModel('customer/customer')->load($customerId);
00558                     $customer->setGroupId($this->getRequest()->getParam('group'));
00559                     $customer->save();
00560                 }
00561                 Mage::getSingleton('adminhtml/session')->addSuccess(
00562                     Mage::helper('adminhtml')->__(
00563                         'Total of %d record(s) were successfully updated', count($customersIds)
00564                     )
00565                 );
00566             } catch (Exception $e) {
00567                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00568             }
00569         }
00570 
00571         $this->_redirect('*/*/index');
00572     }

massDeleteAction (  ) 

Definition at line 523 of file CustomerController.php.

00524     {
00525         $customersIds = $this->getRequest()->getParam('customer');
00526         if(!is_array($customersIds)) {
00527              Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s)'));
00528         } else {
00529             try {
00530                 $customer = Mage::getModel('customer/customer');
00531                 foreach ($customersIds as $customerId) {
00532                     $customer->reset()
00533                         ->load($customerId)
00534                         ->delete();
00535                 }
00536                 Mage::getSingleton('adminhtml/session')->addSuccess(
00537                     Mage::helper('adminhtml')->__(
00538                         'Total of %d record(s) were successfully deleted', count($customersIds)
00539                     )
00540                 );
00541             } catch (Exception $e) {
00542                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00543             }
00544         }
00545 
00546         $this->_redirect('*/*/index');
00547     }

massSubscribeAction (  ) 

Definition at line 473 of file CustomerController.php.

00474     {
00475         $customersIds = $this->getRequest()->getParam('customer');
00476         if(!is_array($customersIds)) {
00477              Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s)'));
00478 
00479         } else {
00480             try {
00481                 foreach ($customersIds as $customerId) {
00482                     $customer = Mage::getModel('customer/customer')->load($customerId);
00483                     $customer->setIsSubscribed(true);
00484                     $customer->save();
00485                 }
00486                 Mage::getSingleton('adminhtml/session')->addSuccess(
00487                     Mage::helper('adminhtml')->__(
00488                         'Total of %d record(s) were successfully updated', count($customersIds)
00489                     )
00490                 );
00491             } catch (Exception $e) {
00492                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00493             }
00494         }
00495         $this->_redirect('*/*/index');
00496     }

massUnsubscribeAction (  ) 

Definition at line 498 of file CustomerController.php.

00499     {
00500         $customersIds = $this->getRequest()->getParam('customer');
00501         if(!is_array($customersIds)) {
00502              Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s)'));
00503         } else {
00504             try {
00505                 foreach ($customersIds as $customerId) {
00506                     $customer = Mage::getModel('customer/customer')->load($customerId);
00507                     $customer->setIsSubscribed(false);
00508                     $customer->save();
00509                 }
00510                 Mage::getSingleton('adminhtml/session')->addSuccess(
00511                     Mage::helper('adminhtml')->__(
00512                         'Total of %d record(s) were successfully updated', count($customersIds)
00513                     )
00514                 );
00515             } catch (Exception $e) {
00516                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00517             }
00518         }
00519 
00520         $this->_redirect('*/*/index');
00521     }

newAction (  ) 

Create new customer action

Definition at line 123 of file CustomerController.php.

00124     {
00125         $this->_forward('edit');
00126     }

newsletterAction (  ) 

Customer newsletter grid

Definition at line 310 of file CustomerController.php.

00311     {
00312         $this->_initCustomer();
00313         $subscriber = Mage::getModel('newsletter/subscriber')
00314             ->loadByCustomer(Mage::registry('current_customer'));
00315 
00316         Mage::register('subscriber', $subscriber);
00317         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/customer_edit_tab_newsletter_grid')->toHtml());
00318     }

ordersAction (  ) 

Customer orders grid

Definition at line 292 of file CustomerController.php.

00292                                    {
00293         $this->_initCustomer();
00294         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/customer_edit_tab_orders')->toHtml());
00295     }

productReviewsAction (  ) 

Definition at line 402 of file CustomerController.php.

00403     {
00404         $this->_initCustomer();
00405         $this->getResponse()->setBody(
00406             $this->getLayout()->createBlock('adminhtml/review_grid', 'admin.customer.reviews')
00407                 ->setCustomerId(Mage::registry('current_customer')->getId())
00408                 ->setUseAjax(true)
00409                 ->toHtml()
00410         );
00411     }

productTagsAction (  ) 

Definition at line 413 of file CustomerController.php.

00414     {
00415         $this->_initCustomer();
00416         $this->getResponse()->setBody(
00417             $this->getLayout()->createBlock('adminhtml/customer_edit_tab_tag', 'admin.customer.tags')
00418                 ->setCustomerId(Mage::registry('current_customer')->getId())
00419                 ->setUseAjax(true)
00420                 ->toHtml()
00421         );
00422     }

saveAction (  ) 

Save customer action

We need set post_index for detect default addresses

Definition at line 151 of file CustomerController.php.

00152     {
00153         if ($data = $this->getRequest()->getPost()) {
00154             $redirectBack   = $this->getRequest()->getParam('back', false);
00155             $this->_initCustomer('customer_id');
00156             $customer = Mage::registry('current_customer');
00157 
00158             // Prepare customer saving data
00159             if (isset($data['account'])) {
00160                 $customer->addData($data['account']);
00161             }
00162 
00163             if (isset($data['address'])) {
00164                 // unset template data
00165                 if (isset($data['address']['_template_'])) {
00166                     unset($data['address']['_template_']);
00167                 }
00168 
00169                 foreach ($data['address'] as $index => $addressData) {
00170                     $address = Mage::getModel('customer/address');
00171                     $address->setData($addressData);
00172 
00173                     if ($addressId = (int) $index) {
00174                         $address->setId($addressId);
00175                     }
00176                     /**
00177                      * We need set post_index for detect default addresses
00178                      */
00179                     $address->setPostIndex($index);
00180                     $customer->addAddress($address);
00181                 }
00182             }
00183 
00184             if(isset($data['subscription'])) {
00185                 $customer->setIsSubscribed(true);
00186             } else {
00187                 $customer->setIsSubscribed(false);
00188             }
00189 
00190             $isNewCustomer = !$customer->getId();
00191             try {
00192                 if ($customer->getPassword() == 'auto') {
00193                     $customer->setPassword($customer->generatePassword());
00194                 }
00195 
00196                 // force new customer active
00197                 if ($isNewCustomer) {
00198                     $customer->setForceConfirmed(true);
00199                 }
00200 
00201                 Mage::dispatchEvent('adminhtml_customer_prepare_save',
00202                     array('customer' => $customer, 'request' => $this->getRequest())
00203                 );
00204 
00205                 $customer->save();
00206 
00207                 // send welcome email
00208                 if ($customer->getWebsiteId() && $customer->hasData('sendemail')) {
00209                     if ($isNewCustomer) {
00210                         $customer->sendNewAccountEmail();
00211                     }
00212                     // confirm not confirmed customer
00213                     elseif ((!$customer->getConfirmation())) {
00214                         $customer->sendNewAccountEmail('confirmed');
00215                     }
00216                 }
00217 
00218                 // TODO? Send confirmation link, if deactivating account
00219 
00220                 if ($newPassword = $customer->getNewPassword()) {
00221                     if ($newPassword == 'auto') {
00222                         $newPassword = $customer->generatePassword();
00223                     }
00224                     $customer->changePassword($newPassword);
00225                     $customer->sendPasswordReminderEmail();
00226                 }
00227 
00228                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Customer was successfully saved'));
00229                 Mage::dispatchEvent('adminhtml_customer_save_after', array('customer' => $customer));
00230 
00231                 if ($redirectBack) {
00232                     $this->_redirect('*/*/edit', array(
00233                         'id'    => $customer->getId(),
00234                         '_current'=>true
00235                     ));
00236                     return;
00237                 }
00238             }
00239             catch (Exception $e){
00240                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00241                 Mage::getSingleton('adminhtml/session')->setCustomerData($data);
00242                 $this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id'=>$customer->getId())));
00243                 return;
00244             }
00245         }
00246         $this->getResponse()->setRedirect($this->getUrl('*/customer'));
00247     }

tagGridAction (  ) 

Definition at line 424 of file CustomerController.php.

00425     {
00426         $this->_initCustomer();
00427         $this->getResponse()->setBody(
00428             $this->getLayout()->createBlock('adminhtml/customer_edit_tab_tag', 'admin.customer.tags')
00429                 ->setCustomerId(Mage::registry('current_customer'))
00430                 ->toHtml()
00431         );
00432     }

validateAction (  ) 

Definition at line 434 of file CustomerController.php.

00435     {
00436         $response = new Varien_Object();
00437         $response->setError(0);
00438         $websiteId = Mage::app()->getStore()->getWebsiteId();
00439         $accountData = $this->getRequest()->getPost('account');
00440 
00441 
00442         $customer = Mage::getModel('customer/customer');
00443         if ($id = $this->getRequest()->getParam('id')) {
00444             $customer->load($id);
00445             $websiteId = $customer->getWebsiteId();
00446         }
00447         if (isset($accountData['website_id'])) {
00448             $websiteId = $accountData['website_id'];
00449         }
00450 
00451         # Checking if we received email. If not - ERROR
00452         if( !($accountData['email']) ) {
00453             $response->setError(1);
00454             Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__("Please fill in 'email' field."));
00455             $this->_initLayoutMessages('adminhtml/session');
00456             $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
00457         } else {
00458             # Trying to load customer with the same email and return error message
00459             # if customer with the same email address exisits
00460             $checkCustomer = Mage::getModel('customer/customer')
00461                 ->setWebsiteId($websiteId);
00462             $checkCustomer->loadByEmail($accountData['email']);
00463             if( $checkCustomer->getId() && ($checkCustomer->getId() != $customer->getId()) ) {
00464                 $response->setError(1);
00465                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Customer with the same email already exists.'));
00466                 $this->_initLayoutMessages('adminhtml/session');
00467                 $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
00468             }
00469         }
00470         $this->getResponse()->setBody($response->toJson());
00471     }

viewCartAction (  ) 

Get shopping cart to view only

Definition at line 378 of file CustomerController.php.

00379     {
00380         $this->_initCustomer();
00381 
00382         $this->getResponse()->setBody(
00383             $this->getLayout()->createBlock('adminhtml/customer_edit_tab_view_cart')
00384                 ->setWebsiteId($this->getRequest()->getParam('website_id'))
00385                 ->toHtml()
00386         );
00387     }

viewWishlistAction (  ) 

Customer last view wishlist for ajax

Definition at line 342 of file CustomerController.php.

00343     {
00344         $this->_initCustomer();
00345         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/customer_edit_tab_view_wishlist')->toHtml());
00346     }

wishlistAction (  ) 

Definition at line 320 of file CustomerController.php.

00321     {
00322         $this->_initCustomer();
00323         $customer = Mage::registry('current_customer');
00324         if ($customer->getId()) {
00325             if($itemId = (int) $this->getRequest()->getParam('delete')) {
00326                 try {
00327                     Mage::getModel('wishlist/item')->load($itemId)
00328                         ->delete();
00329                 }
00330                 catch (Exception $e) {
00331                     //
00332                 }
00333             }
00334         }
00335         $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/customer_edit_tab_wishlist')->toHtml());
00336     }


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

Generated on Sat Jul 4 17:23:11 2009 for Magento by  doxygen 1.5.8