【问题标题】:Magento retrieve customer IDMagento 检索客户 ID
【发布时间】:2013-02-14 03:45:04
【问题描述】:

我尝试了各种方法来获取 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';
}

【问题讨论】:

  • 也可以在这里查看我的答案stackoverflow.com/questions/14743362/…,因为我正在讨论获取客户信息(这并不容易)
  • 我已经实现了这些并在非对象上调用了成员函数 getId()!
  • 如果你看到我的foreach( $dealers as $id => $obj),id 是一个数字,$obj 是客户对象。测试来自您的$customers=Mage::getModel('customer/customer')->getCollection() 的结果,以确保$customers 有一些东西。我为此使用print_r($customers)

标签: php magento


【解决方案1】:
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/

【讨论】:

  • Kalpesh 我已经尝试过了,我得到“调用非对象上的成员函数 getId()”。我意识到它没有通过 if 语句,所以我将 $customer= 从中取出,然后 customer 变量是一个空白值。还有其他想法吗?
  • @user1964129 我已经编辑了答案。你现在可以检查一下吗?
  • 是的,我没有登录,但我登录了!文件放置有问题吗?
  • 您要获取管理员 ID(后端)还是客户 ID(前端)?
【解决方案2】:
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customerData = Mage::getSingleton('customer/session')->getCustomer();
    echo $customerData->getId();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 2013-01-24
    • 2018-08-26
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2022-10-09
    相关资源
    最近更新 更多