2013-02-14 79 views
0

我試過各種方法來獲取customerID,但空值存儲在變量中。請指教:)Magento檢索客戶ID

下面我試過的東西的殘餘物。該文件位於根目錄中。

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'; 
} 
+0

也在這裏查看我的答案http://stackoverflow.com/questions/14743362/how-to-convert-standalone- php-files-to-magentos-mvc/14780910#14780910當我在關於獲取客戶信息(這並不是很容易)上漫步時 – 2013-02-15 20:32:30

+0

我實現了這些並獲取對非成員函數的getId() ! – CaitlinHavener 2013-02-15 21:26:29

+0

如果您看到我的'foreach($ dealer爲$ id => $ obj)'id是一個數字,'$ obj'是客戶對象。測試你的$ customers = Mage :: getModel('customer/customer') - > getCollection()'的結果以確保'$ customers'有一些東西。我使用'print_r($ customers)'。 – 2013-02-15 21:30:30

回答

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/

+0

Kalpesh我試過這個,我得到「調用一個非對象的成員函數getId()」。我意識到它沒有越過if語句,所以我將$ customer =從中取出,然後客戶變量是空白值。任何其他想法? – CaitlinHavener 2013-02-15 21:27:29

+0

@ user1964129我編輯了答案。你現在可以檢查一下嗎? – Kalpesh 2013-02-16 06:16:00

+0

是啊我沒有登錄,但我是!文件放置是一個問題? – CaitlinHavener 2013-02-16 23:17:31

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

這個答案怎麼得分'-1'????這是一個正確的答案 – 2014-09-17 14:38:25