Magento customer login programmatically

后端 未结 2 1084
天命终不由人
天命终不由人 2020-12-12 01:59

I have the code:

function loginUser( $email, $password )
{
    /** @var $session Mage_Customer_Model_Session */
    $session = Mage::getSingleton( \'customer         


        
2条回答
  •  误落风尘
    2020-12-12 02:42

     "frontend"));
    
        $websiteId = Mage::app()->getWebsite()->getId();
        $store = Mage::app()->getStore();
        $customer = Mage::getModel("customer/customer");
        $customer->website_id = $websiteId;
        $customer->setStore($store);
        try {
            $customer->loadByEmail($email);
            $session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
            $session->login($email, $password);
        }catch(Exception $e){
    
        }
    
    
      } 
    ?>
    

提交回复
热议问题