php - Magento modify customer activation module for customer group -
i'm trying modify netzarbeiter's customer activation module extension flags customer group admin approval. following block of code have been modifying.
/** * flag new accounts such * * @param varien_event_observer $observer */ public function customersavebefore($observer) { $customer = $observer->getevent()->getcustomer(); //$customer_group_id=$customer->getcustomergroupid(); $customer_group_id = mage::getsingleton('customer/session')->getcustomergroupid(); mage::log('the customer group id is'. $customer_group_id , null, 'caitlin.log'); if ($customer_group_id=1) mage::log('i have general group id \n',null,'caitlin.log'); else if ($customer_group_id=5) mage::log('i have test group id \n',null,'caitlin.log'); else mage::log('i dont understand! \n',null,'caitlin.log'); $storeid = mage::helper('customeractivation')->getcustomerstoreid($customer); if (mage::getstoreconfig(self::xml_path_module_disabled, $storeid)) { return; } if (!$customer->getid()) { if ($customer_group_id =5){ $defaultstatus = mage::getstoreconfig(self::xml_path_default_status, $storeid); $customer->setcustomeractivated($defaultstatus); $customer->setcustomeractivationnewaccount(true); } else{ $customer->setcustomeractivated('yes'); $customer->setcustomeractivationnewaccount(false); mage::log('this block initiated',null,'caitlin.log'); } } }
so far, customer id being logged correctly, when registering customer of customer group id "1" program not entering else statement "this block has been initiated" log. can see doing wrong or has idea getting program automatically flag particular customer group approval only?
the whole model below:
<?php /** * magento * * notice of license * * source file subject open software license (osl 3.0) * bundled package in file license.txt. * available through world-wide-web @ url: * http://opensource.org/licenses/osl-3.0.php * if did not receive copy of license , unable * obtain through world-wide-web, please send email * license@magentocommerce.com can send copy immediately. * * package netzarbeiter_customeractivation * copyright copyright (c) 2012 vinai kopp http://netzarbeiter.com/ * license http://opensource.org/licenses/osl-3.0.php open software license (osl 3.0) */ class netzarbeiter_customeractivation_model_observer extends mage_core_model_abstract { const xml_path_module_disabled = 'customer/customeractivation/disable_ext'; const xml_path_default_status = 'customer/customeractivation/activation_status_default'; const xml_path_always_notify_admin = 'customer/customeractivation/always_send_admin_email'; /** * fired on customer_login event * check if customer has been activated (via adminhtml) * if not, through login error * * @param varien_event_observer $observer */ public function customerlogin($observer) { if (mage::getstoreconfig(self::xml_path_module_disabled)) { return; } if ($this->_isapirequest()) { return; } $customer = $observer->getevent()->getcustomer(); $session = mage::getsingleton('customer/session'); if (!$customer->getcustomeractivated()) { /* * fake old logout() method without deleting session , messages */ $session->setcustomer(mage::getmodel('customer/customer'))->setid(null); if ($this->_checkrequestroute('customer', 'account', 'createpost')) { /* * if regular registration, display message */ $message = mage::helper('customeractivation')->__('please wait account activated'); $session->addsuccess($message); } else { /* * other types of login */ mage::throwexception(mage::helper('customeractivation')->__('this account not activated.')); } } } /** * flag new accounts such * * @param varien_event_observer $observer */ public function customersavebefore($observer) { $customer = $observer->getevent()->getcustomer(); //$customer_group_id=$customer->getcustomergroupid(); $customer_group_id = mage::getsingleton('customer/session')->getcustomergroupid(); mage::log('the customer group id is'. $customer_group_id , null, 'caitlin.log'); if ($customer_group_id=1) mage::log('i have general group id \n',null,'caitlin.log'); else if ($customer_group_id=5) mage::log('i have test group id \n',null,'caitlin.log'); else mage::log('i dont understand! \n',null,'caitlin.log'); $storeid = mage::helper('customeractivation')->getcustomerstoreid($customer); if (mage::getstoreconfig(self::xml_path_module_disabled, $storeid)) { return; } if (!$customer->getid()) { if ($customer_group_id =5){ $defaultstatus = mage::getstoreconfig(self::xml_path_default_status, $storeid); $customer->setcustomeractivated($defaultstatus); $customer->setcustomeractivationnewaccount(true); } else{ $customer->setcustomeractivated('yes'); $customer->setcustomeractivationnewaccount(false); mage::log('this block initiated',null,'caitlin.log'); } } } /** * send out emails * * @param varien_event_observer $observer */ public function customersaveafter($observer) { $customer = $observer->getevent()->getcustomer(); $storeid = mage::helper('customeractivation')->getcustomerstoreid($customer); if (mage::getstoreconfig(self::xml_path_module_disabled, $storeid)) { return; } $defaultstatus = mage::getstoreconfig(self::xml_path_default_status, $storeid); try { if (mage::app()->getstore()->isadmin()) { if (!$customer->getorigdata('customer_activated') && $customer->getcustomeractivated()) { // send customer email if isn't new account , isn't activated default if (!($customer->getcustomeractivationnewaccount() && $defaultstatus)) { mage::helper('customeractivation')->sendcustomernotificationemail($customer); } } } else { if ($customer->getcustomeractivationnewaccount()) { // notify admin if default deactivated or "always notify" flag configured $alwaysnotify = mage::getstoreconfig(self::xml_path_always_notify_admin, $storeid); if (!$defaultstatus || $alwaysnotify) { mage::helper('customeractivation')->sendadminnotificationemail($customer); } } $customer->setcustomeractivationnewaccount(false); } } catch (exception $e) { mage::throwexception($e->getmessage()); } } public function salescovertquoteaddresstoorder(varien_event_observer $observer) { /** @var $address mage_sales_model_quote_address */ $address = $observer->getevent()->getaddress(); $this->_abortcheckoutregistration($address->getquote()); } /** * abort registration during checkout if default activation status false. * * should work with: onepage checkout, multishipping checkout , custom * checkout types, long use standard converter model * mage_sales_model_convert_quote. * * expected state after checkout: * - customer saved * - no order placed * - guest quote still contains items * - customer quote contains no items * - customer redirected login page * - customer sees message * * @param varien_event_observer $observer */ protected function _abortcheckoutregistration(mage_sales_model_quote $quote) { if (mage::getstoreconfig(self::xml_path_module_disabled, $quote->getstoreid())) { return; } if ($this->_isapirequest()) { return; } if (!mage::getsingleton('customer/session')->isloggedin() && !$quote->getcustomerisguest()) { // order being created non-activated customer $customer = $quote->getcustomer()->save(); if (! $customer->getcustomeractivated()) { // abort order placement // exception handling can not assumed useful // todo: merge guest quote customer quote , save customer quote, don't log customer in // add message $message = mage::helper('customeractivation')->__( 'please wait account activated, log in , continue checkout' ); mage::getsingleton('core/session')->addsuccess($message); // handle redirect login page $targeturl = mage::geturl('customer/account/login'); $response = mage::app()->getresponse(); if (mage::app()->getrequest()->isajax()) { // assume 1 page checkout $result = array('redirect' => $targeturl); $response->setbody(mage::helper('core')->jsonencode($result)); } else if ($response->cansendheaders(true)) { // assume multishipping checkout $response->clearheader('location') ->setredirect($targeturl); } $response->sendresponse(); /* ugly, need stop further order processing */ exit(); } } } /** * return true if reqest made via api * * @return boolean */ protected function _isapirequest() { return mage::app()->getrequest()->getmodulename() === 'api'; } /** * check current module, controller , action against given values. * * @param string $module * @param string $controller * @param string $action * @return bool */ protected function _checkrequestroute($module, $controller, $action) { $req = mage::app()->getrequest(); if (strtolower($req->getmodulename()) == $module && strtolower($req->getcontrollername()) == $controller && strtolower($req->getactionname()) == $action ) { return true; } return false; } /** * add customer_activated attribute grid. * * rouven alexander rieker <rouven.rieker@itabs.de> base code. * * @param varien_event_observer $observer */ public function coreblockabstracttohtmlbefore(varien_event_observer $observer) { if (mage::getstoreconfig(self::xml_path_module_disabled)) { return; } /** @var $block mage_core_block_abstract */ $block = $observer->getevent()->getblock(); if ($block->getid() == 'customergrid') { /** @var $helper netzarbeiter_customeractivation_helper_data */ $helper = mage::helper('customeractivation'); // add attribute column grid $block->addcolumnafter( 'customer_activated', array( 'header' => $helper->__('customer activated'), 'align' => 'center', 'width' => '80px', 'type' => 'options', 'options' => array( '0' => $helper->__('no'), '1' => $helper->__('yes') ), 'default' => '0', 'index' => 'customer_activated', 'renderer' => 'customeractivation/adminhtml_widget_grid_column_renderer_boolean' ), 'customer_since' ); // set new columns order.. otherwise our column last 1 $block->sortcolumnsbyorder(); } } /** * add customer activation option mass action block. * * can't done during block abstract e * * @param varien_event_observer $observer */ public function adminhtmlblockhtmlbefore(varien_event_observer $observer) { // check grid customer grid if ($observer->getblock()->getid() != 'customergrid') { return; } // check if there massaction block , if yes, add massaction customeractivation $massblock = $observer->getblock()->getmassactionblock(); if ($massblock) { /** @var $helper netzarbeiter_customeractivation_helper_data */ $helper = mage::helper('customeractivation'); $massblock->additem( 'customer_activated', array( 'label' => $helper->__('customer activated'), 'url' => mage::geturl('customeractivation/admin/massactivation'), 'additional' => array( 'status' => array( 'name' => 'customer_activated', 'type' => 'select', 'class' => 'required-entry', 'label' => $helper->__('customer activated'), 'values' => array( '1' => $helper->__('yes'), '0' => $helper->__('no') ) ) ) ) ); } } /** * add customer_activated attribute customer grid collection * * @param varien_event_observer $observer */ public function eavcollectionabstractloadbefore(varien_event_observer $observer) { if (mage::getstoreconfig(self::xml_path_module_disabled)) { return; } // cheap check reduce overhead on product , category collections if (mage::app()->getrequest()->getcontrollername() !== 'customer') { return; } /** @var $collection mage_customer_model_resource_customer_collection */ $collection = $observer->getevent()->getcollection(); // add attribute customer collections $customertypeid = mage::getsingleton('eav/config')->getentitytype('customer')->getid(); $collectiontypeid = $collection->getentity()->gettypeid(); if ($customertypeid == $collectiontypeid) { $collection->addattributetoselect('customer_activated'); } } }
simple mistake. using assignment operator =
rather comparison operator ==
.
Comments
Post a Comment