Skip to content

Commit

Permalink
Re-add (optional) sending of notification emails for mass activation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinai committed Jul 16, 2013
1 parent 472eb72 commit 1fa2f82
Showing 1 changed file with 76 additions and 2 deletions.
Expand Up @@ -19,6 +19,9 @@


class Netzarbeiter_CustomerActivation_AdminController extends Mage_Adminhtml_Controller_Action class Netzarbeiter_CustomerActivation_AdminController extends Mage_Adminhtml_Controller_Action
{ {
/**
* Activate or deactivate all selected customers
*/
public function massActivationAction() public function massActivationAction()
{ {
$customerIds = $this->getRequest()->getParam('customer'); $customerIds = $this->getRequest()->getParam('customer');
Expand All @@ -28,16 +31,23 @@ public function massActivationAction()
Mage::helper('customeractivation')->__('Please select item(s)') Mage::helper('customeractivation')->__('Please select item(s)')
); );
} else { } else {
$activationStatus = $this->getRequest()->getParam('customer_activated'); $paramValue = $this->getRequest()->getParam('customer_activated');

try { try {
Mage::getResourceModel('customeractivation/customer') Mage::getResourceModel('customeractivation/customer')
->massSetActivationStatus($customerIds, $activationStatus); ->massSetActivationStatus(
$customerIds, $this->_shouldSetToActivated($paramValue)
);


Mage::getSingleton('adminhtml/session')->addSuccess( Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('customeractivation')->__( Mage::helper('customeractivation')->__(
'Total of %d record(s) were successfully saved', count($customerIds) 'Total of %d record(s) were successfully saved', count($customerIds)
) )
); );

if ($this->_shouldSendActivationNotification($paramValue)) {
$this->_sendActivationNotificationEmails($customerIds);
}
} catch (Exception $e) { } catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
} }
Expand All @@ -46,6 +56,70 @@ public function massActivationAction()
$this->_redirect('adminhtml/customer'); $this->_redirect('adminhtml/customer');
} }


/**
* Based on the mass action query parameter, should customers be activated or not.
*
* @param $paramValue
* @return int
*/
protected function _shouldSetToActivated($paramValue)
{
switch ($paramValue) {
case Netzarbeiter_CustomerActivation_Helper_Data::STATUS_ACTIVATE_WITH_EMAIL:
case Netzarbeiter_CustomerActivation_Helper_Data::STATUS_ACTIVATE_WITHOUT_EMAIL:
$activationStatus = 1;
break;
case Netzarbeiter_CustomerActivation_Helper_Data::STATUS_DEACTIVATE:
default:
$activationStatus = 0;
break;
}
return $activationStatus;
}

/**
* Based on the mass action query parameter, should customer notifications be sent or not
*
* @param $paramValue
* @return bool
*/
protected function _shouldSendActivationNotification($paramValue)
{
switch ($paramValue) {
case Netzarbeiter_CustomerActivation_Helper_Data::STATUS_ACTIVATE_WITH_EMAIL:
$sendEmail = true;
break;
case Netzarbeiter_CustomerActivation_Helper_Data::STATUS_ACTIVATE_WITHOUT_EMAIL:
case Netzarbeiter_CustomerActivation_Helper_Data::STATUS_DEACTIVATE:
default:
$sendEmail = false;
break;
}
return $sendEmail;
}

/**
* Send notification emails to all selected customers
*
* @param array $customerIds
*/
protected function _sendActivationNotificationEmails(array $customerIds)
{
$helper = Mage::helper('customeractivation');
$customers = Mage::getResourceModel('customer/customer_collection')
->addAttributeToFilter('entity_id', array('in' => $customerIds))
->addAttributeToSelect('*')
->addNameToSelect();
foreach ($customers as $customer) {
$helper->sendCustomerNotificationEmail($customer);
}
}

/**
* Check the admin user is allowed to manage customer accounts
*
* @return bool
*/
protected function _isAllowed() protected function _isAllowed()
{ {
return Mage::getSingleton('admin/session')->isAllowed('customer/manage'); return Mage::getSingleton('admin/session')->isAllowed('customer/manage');
Expand Down

0 comments on commit 1fa2f82

Please sign in to comment.