PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Persistent/Helper/Session.php

https://github.com/FiveDigital/magento2
PHP | 141 lines | 50 code | 12 blank | 79 comment | 7 complexity | 86604b7b321389ca16c019d1cc193d21 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Persistent
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Persistent Shopping Cart Data Helper
  28. *
  29. * @category Mage
  30. * @package Mage_Persistent
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Persistent_Helper_Session extends Mage_Core_Helper_Data
  34. {
  35. /**
  36. * Instance of Session Model
  37. *
  38. * @var null|Mage_Persistent_Model_Session
  39. */
  40. protected $_sessionModel;
  41. /**
  42. * Persistent customer
  43. *
  44. * @var null|Mage_Customer_Model_Customer
  45. */
  46. protected $_customer;
  47. /**
  48. * Is "Remember Me" checked
  49. *
  50. * @var null|bool
  51. */
  52. protected $_isRememberMeChecked;
  53. /**
  54. * Get Session model
  55. *
  56. * @return Mage_Persistent_Model_Session
  57. */
  58. public function getSession()
  59. {
  60. if (is_null($this->_sessionModel)) {
  61. $this->_sessionModel = Mage::getModel('Mage_Persistent_Model_Session');
  62. $this->_sessionModel->loadByCookieKey();
  63. }
  64. return $this->_sessionModel;
  65. }
  66. /**
  67. * Force setting session model
  68. *
  69. * @param Mage_Persistent_Model_Session $sessionModel
  70. * @return Mage_Persistent_Model_Session
  71. */
  72. public function setSession($sessionModel)
  73. {
  74. $this->_sessionModel = $sessionModel;
  75. return $this->_sessionModel;
  76. }
  77. /**
  78. * Check whether persistent mode is running
  79. *
  80. * @return bool
  81. */
  82. public function isPersistent()
  83. {
  84. return $this->getSession()->getId() && Mage::helper('Mage_Persistent_Helper_Data')->isEnabled();
  85. }
  86. /**
  87. * Check if "Remember Me" checked
  88. *
  89. * @return bool
  90. */
  91. public function isRememberMeChecked()
  92. {
  93. if (is_null($this->_isRememberMeChecked)) {
  94. //Try to get from checkout session
  95. $isRememberMeChecked = Mage::getSingleton('Mage_Checkout_Model_Session')->getRememberMeChecked();
  96. if (!is_null($isRememberMeChecked)) {
  97. $this->_isRememberMeChecked = $isRememberMeChecked;
  98. Mage::getSingleton('Mage_Checkout_Model_Session')->unsRememberMeChecked();
  99. return $isRememberMeChecked;
  100. }
  101. /** @var $helper Mage_Persistent_Helper_Data */
  102. $helper = Mage::helper('Mage_Persistent_Helper_Data');
  103. return $helper->isEnabled() && $helper->isRememberMeEnabled() && $helper->isRememberMeCheckedDefault();
  104. }
  105. return (bool)$this->_isRememberMeChecked;
  106. }
  107. /**
  108. * Set "Remember Me" checked or not
  109. *
  110. * @param bool $checked
  111. */
  112. public function setRememberMeChecked($checked = true)
  113. {
  114. $this->_isRememberMeChecked = $checked;
  115. }
  116. /**
  117. * Return persistent customer
  118. *
  119. * @return Mage_Customer_Model_Customer|bool
  120. */
  121. public function getCustomer()
  122. {
  123. if (is_null($this->_customer)) {
  124. $customerId = $this->getSession()->getCustomerId();
  125. $this->_customer = Mage::getModel('Mage_Customer_Model_Customer')->load($customerId);
  126. }
  127. return $this->_customer;
  128. }
  129. }