Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Re-add (optional) sending of notification emails for mass activation

  • Loading branch information...
commit 1fa2f82082fe6020d2cc2cdaee3ae2759e94897e 1 parent 472eb72
@Vinai authored
View
78 app/code/community/Netzarbeiter/CustomerActivation/controllers/AdminController.php
@@ -19,6 +19,9 @@
class Netzarbeiter_CustomerActivation_AdminController extends Mage_Adminhtml_Controller_Action
{
+ /**
+ * Activate or deactivate all selected customers
+ */
public function massActivationAction()
{
$customerIds = $this->getRequest()->getParam('customer');
@@ -28,16 +31,23 @@ public function massActivationAction()
Mage::helper('customeractivation')->__('Please select item(s)')
);
} else {
- $activationStatus = $this->getRequest()->getParam('customer_activated');
+ $paramValue = $this->getRequest()->getParam('customer_activated');
+
try {
Mage::getResourceModel('customeractivation/customer')
- ->massSetActivationStatus($customerIds, $activationStatus);
+ ->massSetActivationStatus(
+ $customerIds, $this->_shouldSetToActivated($paramValue)
+ );
Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('customeractivation')->__(
'Total of %d record(s) were successfully saved', count($customerIds)
)
);
+
+ if ($this->_shouldSendActivationNotification($paramValue)) {
+ $this->_sendActivationNotificationEmails($customerIds);
+ }
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
@@ -46,6 +56,70 @@ public function massActivationAction()
$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()
{
return Mage::getSingleton('admin/session')->isAllowed('customer/manage');
Please sign in to comment.
Something went wrong with that request. Please try again.