Magento检索客户ID

时间:2013-02-14 03:45:04

标签: php magento

我尝试了各种方法来获取customerID,但是在变量中存储了一个空值。请指教:)

在我尝试的事物的残余下面。该文件位于根目录中。

require_once '/home/ab71714/public_html/app/Mage.php';
//Mage::app("default");

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

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

 if(Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customerId = Mage::getModel('customer/session')->getCustomer()->getId();
} else {
    echo 'Not logged In';
}

2 个答案:

答案 0 :(得分:2)

require "/home/ab71714/public_html/app/Mage.php";
umask(0);
Mage::app();

$session = Mage::getSingleton('customer/session');
if($session->isLoggedIn()) {
    print_r($session);
    $customerId = $session->getCustomer()->getId();
} else {
    echo 'Not logged In';
}

了解更多信息:

http://ka.lpe.sh/2011/06/19/magento-get-customer-details-customer-id-name-email/

答案 1 :(得分:2)

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