26

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

//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];
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
CaitlinHavener
  • 1,408
  • 3
  • 24
  • 53

3 Answers3

68

Try

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

See Current user in Magento?

Community
  • 1
  • 1
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
17

The fastest way is

Mage::getSingleton('customer/session')->getId()
Shadowbob
  • 1,402
  • 2
  • 16
  • 24
3

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

The customer session does have to following functions:

  1. getCustomerId: which will return the customer id

  2. getCustomer: which will return the customer object.

Pang
  • 9,564
  • 146
  • 81
  • 122
dmanners
  • 2,062
  • 1
  • 18
  • 24
  • It's not even getting past the logged in boolean when I AM logged in. – CaitlinHavener Feb 16 '13 at 23:19
  • have you tried adding the following line after the Mage::app(); Mage::getSingleton('core/session', array('name'=>'frontend')); though are you access the admin section or the front end? – dmanners Feb 18 '13 at 07:40