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];
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: getCustomerId : which will return the customer id. getCustomer : which will return the customer object.
We will Get Customer ID Without Session in Magento 2. You can get the customer Id using through the customer session but if you want to get customer id without using customer session you can you the follow code. > A NULL value is returned even if the customer is logged in.
Magento\Checkout\Model\Session– Checkout session is used to store checkout related information. Magento\Customer\Model\Session– Customer session is used for customer, frontend login and all other activities.
Try
if(Mage::getSingleton('customer/session')->isLoggedIn()) { $customerData = Mage::getSingleton('customer/session')->getCustomer(); echo $customerData->getId(); }
See Current user in Magento?
The fastest way is
Mage::getSingleton('customer/session')->getId()
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:
getCustomerId
: which will return the customer id
getCustomer
: which will return the customer object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With