26

啊,我如何获得客户ID!?这些都是我尝试过的!你能看出我做错了什么吗?

//include_once "app/Mage.php";
require_once '/home/ab71714/public_html/app/Mage.php';

//Mage::app("default");

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

if($customer = Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData();
    print_r($customerData);
    echo $customerData->getId();
}

//$customerData = Mage::getModel('customer/customer');
//$customerID = $customerData -> getId(); 

//$userinfo = $customerData->_origData; // fetch users info
$customerID=$customer -> getId(); 
//$customerID = $customerData->getEntityId();
//$customerID = $customerData[entity_id];
4

3 回答 3

68

尝试

 if(Mage::getSingleton('customer/session')->isLoggedIn()) {
     $customerData = Mage::getSingleton('customer/session')->getCustomer();
      echo $customerData->getId();
 }

查看Magento 中的当前用户?

于 2013-02-15T23:20:05.980 回答
17

最快的方法是

Mage::getSingleton('customer/session')->getId()
于 2013-06-21T13:12:08.527 回答
3

该函数isLoggedIn将只返回一个关于客户是否登录的布尔值,而不返回其他信息。

客户会话确实具有以下功能:

  1. getCustomerId: 这将返回客户 ID

  2. getCustomer: 这将返回客户对象。

于 2013-02-15T21:37:43.557 回答