如何在magento中使用触发器(观察者)进行用户注册

时间:2014-12-31 05:43:54

标签: magento triggers observers

我需要在注册后更改客户状态。因此,当用户尝试在管理员批准后登录我的网站时,他可以访问该帐户,同时我想使用触发器并更改该客户的状态以及给予的更新我的另一个SAP服务器数据库所以在这里我需要知道在客户状态被更改状态期间将触发什么事件..?请任何人回答我的问题..

1 个答案:

答案 0 :(得分:0)

这里使用的是Netzarbeiter_CustomerActivation代码

******代码************

公共职能customerSaveAfter($ observer)     {         / ** @var Mage_Customer_Model_Customer $ customer * /         $ customer = $ observer-> getEvent() - > getCustomer();

    $helper = Mage::helper('customeractivation');
    $storeId = $helper->getCustomerStoreId($customer);

    if (! $helper->isModuleActive($storeId)) {
        return;
    }

    $groupId = $customer->getGroupId();
    $defaultStatus = $helper->getDefaultActivationStatus($groupId, $storeId);








    try {
        if (Mage::app()->getStore()->isAdmin()) {
            if (!$customer->getOrigData('customer_activated') && $customer->getCustomerActivated()) {
                // Send customer email only if it isn't a new account and it isn't activated by default
                if (!($customer->getCustomerActivationNewAccount() && $defaultStatus)) {
                    $helper->sendCustomerNotificationEmail($customer);

              ***  Added Code Here **********

获取用户详细信息并在管理员批准后,客户详细信息将通过您的API发送到另一台服务器

                    $CustomerID=$customer->getId();
                    $FirstName=$customer->getFirstname();
                    $MiddleName=$customer->getMiddlename(); 
                    $LastName=$customer->getLastname();
                    $Gender=$customer->getGender();
                    $EmailID=$customer->getEmail();
                    $WebSite=$customer->getWebsiteId();
                    $GroupID=$customer->getGroupId(); 
                    $DOB=$customer->getDob();
                    $TaxVat=$customer->getTaxvat();
                    $date= date("Ymd", strtotime($DOB));
                    $url = "http://server/WebSAPApi/Service1.asmx/CreateCustomer?CustomerID=$CustomerID&FirstName=$FirstName&MiddleName=$MiddleName&LastName=$LastName&Gender=$Gender&EmailID=$EmailID&WebSite=$WebSite&GroupID=$GroupID&DOB=$date&TaxVat=$TaxVat";
                   function httpGet($url)
                    {
                        $ch = curl_init();  

                        curl_setopt($ch,CURLOPT_URL,$url);
                        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);


                        $output=curl_exec($ch);

                        curl_close($ch);
                        return $output;
                    }                   

                    $msg = httpGet($url);
                    Mage::log($url.$msg, null, 'mylog.log', true);**

******添加代码的结尾**********

                }
            }
        } else {
            if ($customer->getCustomerActivationNewAccount()) {









                // Only notify the admin if the default is deactivated or the "always notify" flag is configured
                $alwaysNotify = Mage::getStoreConfig(self::XML_PATH_ALWAYS_NOTIFY_ADMIN, $storeId,$d);
                if (!$defaultStatus || $alwaysNotify) {
                    $helper->sendAdminNotificationEmail($customer);
                }




            }
            $customer->setCustomerActivationNewAccount(false);
        }
    } catch (Exception $e) {
        Mage::throwException($e->getMessage());
    }
}