如何获得Magento客户ID

时间:2013-02-15 21:32:01

标签: php magento

我怎么得到客户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];

3 个答案:

答案 0 :(得分:64)

尝试

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

请参阅Current user in Magento?

答案 1 :(得分:16)

最快的方法是

Mage::getSingleton('customer/session')->getId()

答案 2 :(得分:3)

函数isLoggedIn仅返回一个布尔值,表示客户是否已登录而没有其他信息。

客户会话必须遵循以下功能:

  1. getCustomerId:将返回客户ID

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