我在嘗試設置會話變量,因此每個會話僅出現一次彈出框。在打開緩存的情況下在Magento中設置會話變量
爲此,我創建了一個模塊,當有人關閉彈出窗口時,通過AJAX調用該模塊。模塊的控制器設置會話變量。控制器看起來像這樣:
class Company_Popup_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
Mage::getSingleton('core/session')->setNewsletterPopup('yes');
}
}
超級簡單。
然後,在塊I檢查會話變量被設置(或者如果用戶已登錄):
class Company_Popup_Block_Popup extends Mage_Core_Block_Template
{
public function displayPopup(){
if(!$this->helper('customer')->isLoggedIn() && Mage::getSingleton('core/session')->getNewsletterPopup() == null){
return true;
}
else{
return false;
}
}
public function getSessionData(){
return Mage::getSingleton('core/session');
}
}
模板文件然後調用displayPopup方法,要麼顯示通訊彈出或不。
這一切都很完美......直到我打開緩存時,會話變量沒有被設置,或者至少在塊/模板文件中無法訪問。
我在這裏錯過了什麼?
你在哪裏渲染你的區塊,例如它是在footer.phtml? – Theodores
您正在運行CE還是EE版? –
它可能會更簡單,如果你只是使用javascript和餅乾女巫沒有緩存。你只能爲當前會話設置一個cookie ... –