php 如何获取 Magento 客户 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14903646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:10:20  来源:igfitidea点击:

How to get Magento customer ID

phpmagento

提问by CaitlinHavener

Ugh how do I get the customer ID!!? These are all things I've tried! Can you see what I'm doing wrong?

呃,我如何获得客户 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];

回答by Renon Stewart

Try

尝试

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

See Current user in Magento?

在 Magento 中查看当前用户?

回答by Shadowbob

The fastest way is

最快的方法是

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

回答by dmanners

The function isLoggedInwill only return a boolean as to if a customer is logged in and no other information.

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

The customer session does have to following functions:

客户会话必须具有以下功能:

  1. getCustomerId: which will return the customer id

  2. getCustomer: which will return the customer object.

  1. getCustomerId: 这将返回客户 ID

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