[英]Accessing custom variables from a .phtml in Magento
我有一個執行我的代碼的文件(js.phtml)。 我需要訪問一些用戶數據。 當我在js.phtml中的error_log($ this)時,它顯示“ Mage_Core_Block_Template”-這讓我感到困惑。 我希望它是父類,而不是傳遞給我的.phtml文件的類的值。
那么,如何為.phtml文件提供自定義對象或方法? 我對Magento來說是個超級新手,我剛剛開始從事一項工作,因此對可能使用不正確的術語表示歉意。
編輯:我的完整文件路徑是:
這里還有一個完整的模塊目錄:
編輯:我需要訪問用戶國家和用戶ID。 國家為空也可以。
編輯:我一直在做其他研究,看來我可以做這樣的事情: Magento中的當前用戶?
但是我還沒有在代碼中嘗試過...。
編輯:弄清楚了:
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getEntityId(), true));
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getCountry(), true));
獲取客戶ID:
echo Mage::getSingleton('customer/session')->getCustomer()->getId();
獲取國家/地區-取決於來自哪個地址。 這是從默認帳單地址獲取國家/地區代碼的示例:
echo Mage::getSingleton('customer/session')->getCustomer()->getDefaultBillingAddress()->getCountry();
我對Magento有點陌生,但是我認為這應該可行。
$customer = Mage::getSingleton('customer/session')->getCustomer();
那得到顧客對象。 然后...
echo $customer->getAddresses();
那應該使該國在地址中某處。 至於用戶名...我在文檔頁面上沒有看到它。
echo $customer->getAttributes();
看看里面有什么。 文檔頁面位於:
http://docs.magentocommerce.com/Mage_Customer/Mage_Customer_Model_Customer.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.