2014-05-16 27 views
8

根據用戶是否登錄,最簡單/最值得推薦的方法是擁有一些條件佈局邏輯?Magento中的條件佈局塊取決於是否已登錄?

如..僞代碼在XML文件中

if (customer logged in) 
    display this custom onepage checkout layout block 
otherwise 
    display this other custom layout block (for guests) 

回答

10

使用條件(local.xml中,page.xml等)。例如。以添加的CMS塊如果客戶登錄:

<customer_logged_in> <reference name="name_of_reference_block"> <block type="cms/block" name="block_name"> <action method="setBlockId"> <block_id>block_id</block_id> </action> </block> </reference> </customer_logged_in>

而且相同的邏輯爲註銷用戶,例如刪除塊:

<customer_logged_out> <reference name="name_of_reference_block"> <remove name="name_of_block_to_remove"></remove> </reference> </customer_logged_out>

+1

哇 - 看起來輝煌,感謝傑拉德 – Zabs

+0

是有可能在這些'customer_logged_in/out'條件標籤中引用一個控制器?例如。就像:(...)' – Alan

+0

你知道在Magento 2中做到這一點嗎? –

6

您也可以使用Magento的客戶助手在你的模板:

if($this->helper('customer')->isLoggedIn()){ 

//Show block to logged in customers 

}else{ 

// Show different block to guest users 

} 

或者使用:

Mage::helper('customer')->isLoggedIn()