*/ class Mage_Persistent_Helper_Session extends Mage_Core_Helper_Data { /** * Instance of Session Model * * @var null|Mage_Persistent_Model_Session */ protected $_sessionModel; /** * Persistent customer * * @var null|Mage_Customer_Model_Customer */ protected $_customer; /** * Is "Remember Me" checked * * @var null|bool */ protected $_isRememberMeChecked; /** * Get Session model * * @return Mage_Persistent_Model_Session */ public function getSession() { if (is_null($this->_sessionModel)) { $this->_sessionModel = Mage::getModel('persistent/session'); $this->_sessionModel->loadByCookieKey(); } return $this->_sessionModel; } /** * Force setting session model * * @param Mage_Persistent_Model_Session $sessionModel * @return Mage_Persistent_Model_Session */ public function setSession($sessionModel) { $this->_sessionModel = $sessionModel; return $this->_sessionModel; } /** * Check whether persistent mode is running * * @return bool */ public function isPersistent() { return $this->getSession()->getId() && Mage::helper('persistent')->isEnabled(); } /** * Check if "Remember Me" checked * * @return bool */ public function isRememberMeChecked() { if (is_null($this->_isRememberMeChecked)) { //Try to get from checkout session $isRememberMeChecked = Mage::getSingleton('checkout/session')->getRememberMeChecked(); if (!is_null($isRememberMeChecked)) { $this->_isRememberMeChecked = $isRememberMeChecked; Mage::getSingleton('checkout/session')->unsRememberMeChecked(); return $isRememberMeChecked; } /** @var $helper Mage_Persistent_Helper_Data */ $helper = Mage::helper('persistent'); return $helper->isEnabled() && $helper->isRememberMeEnabled() && $helper->isRememberMeCheckedDefault(); } return (bool)$this->_isRememberMeChecked; } /** * Set "Remember Me" checked or not * * @param bool $checked */ public function setRememberMeChecked($checked = true) { $this->_isRememberMeChecked = $checked; } /** * Return persistent customer * * @return Mage_Customer_Model_Customer|bool */ public function getCustomer() { if (is_null($this->_customer)) { $customerId = $this->getSession()->getCustomerId(); $this->_customer = Mage::getModel('customer/customer')->load($customerId); } return $this->_customer; } }