diff --git a/.phpstan.dist.baseline.neon b/.phpstan.dist.baseline.neon index f9f7f2e4abb..baa07d8cf2b 100644 --- a/.phpstan.dist.baseline.neon +++ b/.phpstan.dist.baseline.neon @@ -2688,6 +2688,12 @@ parameters: count: 1 path: app/code/core/Mage/Checkout/Block/Cart/Shipping.php + - + message: '#^Call to function is_array\(\) with non\-empty\-array will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: app/code/core/Mage/Checkout/Block/Multishipping/Success.php + - message: '#^Method Mage_Checkout_Block_Onepage_Billing\:\:_getTaxvat\(\) should return Mage_Customer_Block_Widget_Taxvat but returns Mage_Core_Block_Abstract\|false\.$#' identifier: return.type @@ -4584,18 +4590,6 @@ parameters: count: 1 path: app/code/core/Mage/Install/Model/Config.php - - - message: '#^Method Mage_Install_Model_Installer\:\:getDataModel\(\) should return Mage_Install_Model_Session but returns Mage_Install_Model_Installer_Data\|null\.$#' - identifier: return.type - count: 1 - path: app/code/core/Mage/Install/Model/Installer.php - - - - message: '#^Parameter \#1 \$model of method Mage_Install_Model_Installer\:\:setDataModel\(\) expects Mage_Install_Model_Installer_Data, Mage_Install_Model_Session given\.$#' - identifier: argument.type - count: 1 - path: app/code/core/Mage/Install/Model/Installer.php - - message: '#^Parameter \#2 \$value of method Mage_Core_Model_Resource_Setup\:\:setConfigData\(\) expects string, int given\.$#' identifier: argument.type @@ -5034,12 +5028,6 @@ parameters: count: 1 path: app/code/core/Mage/ProductAlert/controllers/AddController.php - - - message: '#^PHPDoc tag @var with type Mage_Catalog_Model_Product is not subtype of native type 0\|0\.0\|''''\|''0''\|array\{\}\|false\|null\.$#' - identifier: varTag.nativeType - count: 1 - path: app/code/core/Mage/ProductAlert/controllers/AddController.php - - message: '#^Method Mage_Rating_Model_Resource_Rating\:\:getEntityIdByCode\(\) should return int but returns string\|false\|null\.$#' identifier: return.type diff --git a/app/code/core/Mage/Admin/Model/Observer.php b/app/code/core/Mage/Admin/Model/Observer.php index 2fee461b49e..38a3e635dbe 100644 --- a/app/code/core/Mage/Admin/Model/Observer.php +++ b/app/code/core/Mage/Admin/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Admin */ -class Mage_Admin_Model_Observer +class Mage_Admin_Model_Observer extends Mage_Core_Model_Observer { public const FLAG_NO_LOGIN = 'no-login'; @@ -31,8 +31,7 @@ class Mage_Admin_Model_Observer */ public function actionPreDispatchAdmin($observer) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); $request = Mage::app()->getRequest(); $user = $session->getUser(); @@ -53,8 +52,7 @@ public function actionPreDispatchAdmin($observer) } if (!$user || !$user->getId()) { if ($request->getPost('login')) { - /** @var Mage_Core_Model_Session $coreSession */ - $coreSession = Mage::getSingleton('core/session'); + $coreSession = $this->getCoreSession(); if ($coreSession->validateFormKey($request->getPost('form_key'))) { $postLogin = $request->getPost('login'); @@ -62,13 +60,11 @@ public function actionPreDispatchAdmin($observer) $password = $postLogin['password'] ?? ''; $session->login($username, $password, $request); $request->setPost('login', null); - } else { - if (!$request->getParam('messageSent')) { - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('adminhtml')->__('Invalid Form Key. Please refresh the page.'), - ); - $request->setParam('messageSent', true); - } + } elseif (!$request->getParam('messageSent')) { + $this->getAdminhtmlSession()->addError( + Mage::helper('adminhtml')->__('Invalid Form Key. Please refresh the page.'), + ); + $request->setParam('messageSent', true); } $coreSession->renewFormKey(); diff --git a/app/code/core/Mage/Admin/Model/Resource/Acl.php b/app/code/core/Mage/Admin/Model/Resource/Acl.php index 33f2540234e..a1761396bfe 100644 --- a/app/code/core/Mage/Admin/Model/Resource/Acl.php +++ b/app/code/core/Mage/Admin/Model/Resource/Acl.php @@ -140,8 +140,8 @@ public function loadRules(Mage_Admin_Model_Acl $acl, array $rulesArr) } } - if ($orphanedResources !== [] && $acl->isAllowed(Mage::getSingleton('admin/session')->getUser()->getAclRole(), 'admin/system/acl/orphaned_resources')) { - Mage::getSingleton('adminhtml/session')->addNotice( + if ($orphanedResources !== [] && $acl->isAllowed($this->getAdminSession()->getUser()->getAclRole(), 'admin/system/acl/orphaned_resources')) { + $this->getAdminhtmlSession()->addNotice( Mage::helper('adminhtml')->__( 'The following role resources are no longer available in the system: %s. You can delete them by clicking here.', implode(', ', $orphanedResources), diff --git a/app/code/core/Mage/Admin/Model/Session.php b/app/code/core/Mage/Admin/Model/Session.php index 2f2ba2fb388..e72a054850c 100644 --- a/app/code/core/Mage/Admin/Model/Session.php +++ b/app/code/core/Mage/Admin/Model/Session.php @@ -165,7 +165,7 @@ public function login($username, $password, $request = null) $this->setUser($user); $this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); if ($backendLocale = $user->getBackendLocale()) { - Mage::getSingleton('adminhtml/session')->setLocale($backendLocale); + $this->getAdminhtmlSession()->setLocale($backendLocale); } $alternativeUrl = $this->_getRequestUri($request); @@ -218,8 +218,8 @@ public function refreshAcl($user = null) /** * Check current user permission on resource and privilege * - * Mage::getSingleton('admin/session')->isAllowed('admin/catalog') - * Mage::getSingleton('admin/session')->isAllowed('catalog') + * $this->getAdminSession()->isAllowed('admin/catalog') + * $this->getAdminSession()->isAllowed('catalog') * * @param string $resource * @param string $privilege @@ -320,7 +320,7 @@ protected function _loginFailed($e, $request, $username, $message) } if ($request && !$request->getParam('messageSent')) { - Mage::getSingleton('adminhtml/session')->addError($message); + $this->getAdminhtmlSession()->addError($message); $request->setParam('messageSent', true); } } diff --git a/app/code/core/Mage/Admin/Model/User.php b/app/code/core/Mage/Admin/Model/User.php index 9655a4af4e9..5039a54ef99 100644 --- a/app/code/core/Mage/Admin/Model/User.php +++ b/app/code/core/Mage/Admin/Model/User.php @@ -157,9 +157,9 @@ protected function _beforeSave() // Change user password $data['password'] = $this->_getEncodedPassword($this->getNewPassword()); $data['new_password'] = $data['password']; - $sessionUser = $this->getSession()->getUser(); + $sessionUser = $this->getAdminSession()->getUser(); if ($sessionUser && $sessionUser->getId() == $this->getId()) { - $this->getSession()->setUserPasswordChanged(true); + $this->getAdminSession()->setUserPasswordChanged(true); } } elseif ($this->getPassword() && $this->getPassword() != $this->getOrigData('password')) { // New user password @@ -183,10 +183,12 @@ protected function _beforeSave() /** * @return Mage_Admin_Model_Session -*/ + * @deprecated + * @see getAdminSession() + */ protected function getSession() { - return Mage::getSingleton('admin/session'); + return $this->getAdminSession(); } /** @@ -435,7 +437,7 @@ public function login($username, $password) if ($this->authenticate($username, $password)) { $this->getResource()->recordLogin($this); - Mage::getSingleton('core/session')->renewFormKey(); + $this->getCoreSession()->renewFormKey(); } return $this; } @@ -451,11 +453,11 @@ public function reload() $oldPassword = $this->getPassword(); $this->setId(null); $this->load($id); - $isUserPasswordChanged = $this->getSession()->getUserPasswordChanged(); + $isUserPasswordChanged = $this->getAdminSession()->getUserPasswordChanged(); if (!$isUserPasswordChanged && $this->getPassword() !== $oldPassword) { $this->setId(null); } elseif ($isUserPasswordChanged) { - $this->getSession()->setUserPasswordChanged(false); + $this->getAdminSession()->setUserPasswordChanged(false); } return $this; } @@ -520,7 +522,7 @@ public function findFirstAvailableMenu($parent = null, $path = '', $level = 0) } foreach ($parent->children() as $childName => $child) { $aclResource = 'admin/' . $path . $childName; - if (Mage::getSingleton('admin/session')->isAllowed($aclResource)) { + if ($this->getAdminSession()->isAllowed($aclResource)) { if (!$child->children) { return (string) $child->action; } elseif ($child->children) { @@ -564,7 +566,7 @@ public function getStartupPageUrl() { $startupPage = Mage::getStoreConfig(self::XML_PATH_STARTUP_PAGE); $aclResource = 'admin/' . $startupPage; - if (Mage::getSingleton('admin/session')->isAllowed($aclResource)) { + if ($this->getAdminSession()->isAllowed($aclResource)) { $nodePath = 'menu/' . implode('/children/', explode('/', $startupPage)) . '/action'; $url = (string) Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode($nodePath); if ($url) { diff --git a/app/code/core/Mage/AdminNotification/Model/Observer.php b/app/code/core/Mage/AdminNotification/Model/Observer.php index 64cac5079ac..57e2f632279 100644 --- a/app/code/core/Mage/AdminNotification/Model/Observer.php +++ b/app/code/core/Mage/AdminNotification/Model/Observer.php @@ -20,17 +20,16 @@ * @category Mage * @package Mage_AdminNotification */ -class Mage_AdminNotification_Model_Observer +class Mage_AdminNotification_Model_Observer extends Mage_Core_Model_Observer { /** * Predispath admin action controller */ public function preDispatch(Varien_Event_Observer $observer) { - if (Mage::getSingleton('admin/session')->isLoggedIn()) { - $feedModel = Mage::getModel('adminnotification/feed'); + if ($this->getAdminSession()->isLoggedIn()) { /** @var Mage_AdminNotification_Model_Feed $feedModel */ - + $feedModel = Mage::getModel('adminnotification/feed'); $feedModel->checkUpdate(); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php index 25ed93a0cbe..c0efe1db00f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Api/User/Edit/Tab/Main.php @@ -121,7 +121,7 @@ protected function _prepareForm() ]); } - if (Mage::getSingleton('admin/session')->getUser()->getId() != $model->getUserId()) { + if ($this->getAdminSession()->getUser()->getId() != $model->getUserId()) { $fieldset->addField('is_active', 'select', [ 'name' => 'is_active', 'label' => Mage::helper('adminhtml')->__('This account is'), diff --git a/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php b/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php index 2e4fd66fe6a..38af4fe40e9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php +++ b/app/code/core/Mage/Adminhtml/Block/Cache/Notifications.php @@ -52,7 +52,7 @@ public function getManageUrl() */ protected function _toHtml() { - if (Mage::getSingleton('admin/session')->isAllowed('system/cache')) { + if ($this->getAdminSession()->isAllowed('system/cache')) { return parent::_toHtml(); } return ''; diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php index c717c65b9c4..ac2fe5f6915 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tree.php @@ -126,7 +126,7 @@ public function getStoreSwitcherHtml() public function getLoadTreeUrl($expanded = null) { $params = ['_current' => true, 'id' => null,'store' => null]; - if ((is_null($expanded) && Mage::getSingleton('admin/session')->getIsTreeWasExpanded()) + if ((is_null($expanded) && $this->getAdminSession()->getIsTreeWasExpanded()) || $expanded == true ) { $params['expand_all'] = true; @@ -149,7 +149,7 @@ public function getSwitchTreeUrl() public function getIsWasExpanded() { - return Mage::getSingleton('admin/session')->getIsTreeWasExpanded(); + return $this->getAdminSession()->getIsTreeWasExpanded(); } public function getMoveUrl() diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php index 9b55933a74f..f96b02e6694 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php @@ -76,7 +76,7 @@ protected function _prepareForm() // Add new attribute button if it is not an image tab if (!$form->getElement('media_gallery') - && Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/attributes') + && $this->getAdminSession()->isAllowed('catalog/attributes/attributes') ) { $headerBar = $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_attributes_create'); diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php index 896aabe6f15..2cdca6cc348 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php @@ -132,7 +132,7 @@ protected function _prepareLayout() if ($this->getRequest()->getParam('id', false)) { if ($this->isModuleEnabled('Mage_Review', 'catalog')) { - if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')) { + if ($this->getAdminSession()->isAllowed('admin/catalog/reviews_ratings')) { $this->addTab('reviews', [ 'label' => Mage::helper('catalog')->__('Product Reviews'), 'url' => $this->getUrl('*/*/reviews', ['_current' => true]), @@ -141,7 +141,7 @@ protected function _prepareLayout() } } if ($this->isModuleEnabled('Mage_Tag', 'catalog')) { - if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')) { + if ($this->getAdminSession()->isAllowed('admin/catalog/tag')) { $this->addTab('tags', [ 'label' => Mage::helper('catalog')->__('Product Tags'), 'url' => $this->getUrl('*/*/tagGrid', ['_current' => true]), diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php index 5b59c1ed066..29cd266613d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php @@ -323,7 +323,7 @@ protected function _prepareMassaction() ], ]); - if (Mage::getSingleton('admin/session')->isAllowed('catalog/update_attributes')) { + if ($this->getAdminSession()->isAllowed('catalog/update_attributes')) { $this->getMassactionBlock()->addItem(MassAction::ATTRIBUTES, [ 'label' => Mage::helper('catalog')->__('Update Attributes'), 'url' => $this->getUrl('*/catalog_product_action_attribute/edit', ['_current' => true]), diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php index 2172105d662..68fb3f44f44 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page.php @@ -44,6 +44,6 @@ public function __construct() */ protected function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + return $this->getAdminSession()->isAllowed('cms/page/' . $action); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php index 7aae67aaadb..99db1a8cfd1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit.php @@ -72,7 +72,7 @@ public function getHeaderText() */ protected function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + return $this->getAdminSession()->isAllowed('cms/page/' . $action); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php index 25800b26c8e..9ee060a842c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Content.php @@ -137,6 +137,6 @@ public function isHidden() */ protected function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + return $this->getAdminSession()->isAllowed('cms/page/' . $action); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php index 08663208973..27eacdc1050 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php @@ -179,6 +179,6 @@ public function isHidden() */ protected function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + return $this->getAdminSession()->isAllowed('cms/page/' . $action); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php index cdf5aae7639..d33d6c80c15 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php @@ -159,6 +159,6 @@ public function isHidden() */ protected function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + return $this->getAdminSession()->isAllowed('cms/page/' . $action); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php index e99f8ef6ff5..65a916dab69 100644 --- a/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php +++ b/app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Meta.php @@ -115,6 +115,6 @@ public function isHidden() */ protected function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action); + return $this->getAdminSession()->isAllowed('cms/page/' . $action); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php index 6878e398306..f26873fa704 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit.php @@ -29,7 +29,7 @@ public function __construct() $this->_controller = 'customer'; if ($this->getCustomerId() && - Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/create') + $this->getAdminSession()->isAllowed('sales/order/actions/create') ) { $this->_addButton('order', [ 'label' => Mage::helper('customer')->__('Create Order'), diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php index 6501341710c..82ede924797 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php @@ -54,7 +54,7 @@ protected function _beforeToHtml() // load: Orders, Shopping Cart, Wishlist, Product Reviews, Product Tags - with ajax if (Mage::registry('current_customer')->getId()) { - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/view')) { $this->addTab('orders', [ 'label' => Mage::helper('customer')->__('Orders'), 'class' => 'ajax', @@ -74,9 +74,7 @@ protected function _beforeToHtml() 'url' => $this->getUrl('*/*/wishlist', ['_current' => true]), ]); - if ($this->isModuleOutputEnabled('Mage_Newsletter') - && Mage::getSingleton('admin/session')->isAllowed('newsletter/subscriber') - ) { + if ($this->isModuleOutputEnabled('Mage_Newsletter') && $this->getAdminSession()->isAllowed('newsletter/subscriber')) { /** @var Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter $block */ $block = $this->getLayout()->createBlock('adminhtml/customer_edit_tab_newsletter'); $this->addTab('newsletter', [ @@ -85,9 +83,7 @@ protected function _beforeToHtml() ]); } - if ($this->isModuleOutputEnabled('Mage_Review') - && Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings') - ) { + if ($this->isModuleOutputEnabled('Mage_Review') && $this->getAdminSession()->isAllowed('catalog/reviews_ratings')) { $this->addTab('reviews', [ 'label' => Mage::helper('customer')->__('Product Reviews'), 'class' => 'ajax', @@ -95,9 +91,7 @@ protected function _beforeToHtml() ]); } - if ($this->isModuleEnabled('Mage_Tag') - && Mage::getSingleton('admin/session')->isAllowed('catalog/tag') - ) { + if ($this->isModuleEnabled('Mage_Tag') && $this->getAdminSession()->isAllowed('catalog/tag')) { $this->addTab('tags', [ 'label' => Mage::helper('customer')->__('Product Tags'), 'class' => 'ajax', diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php index f10e02b07f9..f726dc2316a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php @@ -46,7 +46,7 @@ public function getDeleteUrl() if (!Mage::getSingleton('adminhtml/url')->useSecretKey()) { return $this->getUrl('*/*/delete', [ $this->_objectId => $this->getRequest()->getParam($this->_objectId), - 'form_key' => Mage::getSingleton('core/session')->getFormKey(), + 'form_key' => $this->getCoreSession()->getFormKey(), ]); } else { return parent::getDeleteUrl(); diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php index 3e9e532cd17..e340da44b76 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php @@ -79,9 +79,9 @@ protected function _prepareLayout() ); } - if (Mage::getSingleton('adminhtml/session')->getCustomerGroupData()) { - $form->addValues(Mage::getSingleton('adminhtml/session')->getCustomerGroupData()); - Mage::getSingleton('adminhtml/session')->setCustomerGroupData(null); + if ($this->getAdminhtmlSession()->getCustomerGroupData()) { + $form->addValues($this->getAdminhtmlSession()->getCustomerGroupData()); + $this->getAdminhtmlSession()->setCustomerGroupData(null); } else { $form->addValues($customerGroup->getData()); } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php index 41dc00ee9c8..a37f0ca83da 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php @@ -150,7 +150,7 @@ protected function _prepareColumns() */ public function getRowUrl($row) { - return (Mage::getSingleton('admin/session')->isAllowed('customer/manage') && $row->getCustomerId()) + return ($this->getAdminSession()->isAllowed('customer/manage') && $row->getCustomerId()) ? $this->getUrl('*/customer/edit', ['id' => $row->getCustomerId()]) : ''; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Denied.php b/app/code/core/Mage/Adminhtml/Block/Denied.php index 4f0c48cdf6f..3654707831c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Denied.php +++ b/app/code/core/Mage/Adminhtml/Block/Denied.php @@ -22,7 +22,7 @@ class Mage_Adminhtml_Block_Denied extends Mage_Adminhtml_Block_Template { public function hasAvailaleResources() { - $user = Mage::getSingleton('admin/session')->getUser(); + $user = $this->getAdminSession()->getUser(); if ($user && $user->hasAvailableResources()) { return true; } diff --git a/app/code/core/Mage/Adminhtml/Block/Notification/Window.php b/app/code/core/Mage/Adminhtml/Block/Notification/Window.php index 4f00b756d3a..9f0cf56e9ce 100644 --- a/app/code/core/Mage/Adminhtml/Block/Notification/Window.php +++ b/app/code/core/Mage/Adminhtml/Block/Notification/Window.php @@ -87,7 +87,7 @@ public function canShow() return $this->_available; } - if (!Mage::getSingleton('admin/session')->isFirstPageAfterLogin()) { + if (!$this->getAdminSession()->isFirstPageAfterLogin()) { $this->_available = false; return false; } @@ -167,8 +167,7 @@ public function getSeverityText() protected function _isAllowed() { if (!is_null($this->_aclResourcePath)) { - return Mage::getSingleton('admin/session') - ->isAllowed('admin/system/adminnotification/show_toolbar'); + return $this->getAdminSession()->isAllowed('admin/system/adminnotification/show_toolbar'); } else { return true; } diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Head.php b/app/code/core/Mage/Adminhtml/Block/Page/Head.php index 65d04040146..8c53991a5d3 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Head.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Head.php @@ -37,7 +37,7 @@ protected function _getUrlModelClass() */ public function getFormKey() { - return Mage::getSingleton('core/session')->getFormKey(); + return $this->getCoreSession()->getFormKey(); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Header.php b/app/code/core/Mage/Adminhtml/Block/Page/Header.php index ae124ac4670..fce8fe46509 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Header.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Header.php @@ -35,7 +35,7 @@ public function getHomeLink() public function getUser() { - return Mage::getSingleton('admin/session')->getUser(); + return $this->getAdminSession()->getUser(); } public function getLogoutLink() diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php index 7b6c531d7d8..3277d3f13ac 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php @@ -66,7 +66,7 @@ public function getCacheKeyInfo() $cacheKeyInfo = [ 'admin_top_nav', $this->getActive(), - Mage::getSingleton('admin/session')->getUser()->getId(), + $this->getAdminSession()->getUser()->getId(), Mage::app()->getLocale()->getLocaleCode(), ]; // Add additional key parameters if needed @@ -219,7 +219,7 @@ protected function _checkDepends(Varien_Simplexml_Element $depends) protected function _checkAcl($resource) { try { - $res = Mage::getSingleton('admin/session')->isAllowed($resource); + $res = $this->getAdminSession()->isAllowed($resource); } catch (Exception $e) { return false; } diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource/Grid.php b/app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource/Grid.php index 143a2dd87e2..6d5f6934b1e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/OrphanedResource/Grid.php @@ -37,7 +37,7 @@ public function __construct() protected function _prepareCollection() { $collection = Mage::getResourceModel('admin/rules_collection') - ->addFieldToFilter('resource_id', ['nin' => Mage::getSingleton('admin/session')->getAcl()->getResources()]) + ->addFieldToFilter('resource_id', ['nin' => $this->getAdminSession()->getAcl()->getResources()]) ->addFieldToSelect('resource_id'); $collection->getSelect()->group('resource_id'); diff --git a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php index 13d79d10993..ce8e9eeafc6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Main.php @@ -124,7 +124,7 @@ protected function _prepareForm() ]); } - if (Mage::getSingleton('admin/session')->getUser()->getId() != $model->getUserId()) { + if ($this->getAdminSession()->getUser()->getId() != $model->getUserId()) { $fieldset->addField('is_active', 'select', [ 'name' => 'is_active', 'label' => Mage::helper('adminhtml')->__('This account is'), diff --git a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php index 31ae938201a..a91ec378ca8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Rating/Edit/Tab/Form.php @@ -50,13 +50,13 @@ protected function _prepareForm() ]); } - if (Mage::getSingleton('adminhtml/session')->getRatingData()) { - $form->setValues(Mage::getSingleton('adminhtml/session')->getRatingData()); - $data = Mage::getSingleton('adminhtml/session')->getRatingData(); + if ($this->getAdminhtmlSession()->getRatingData()) { + $form->setValues($this->getAdminhtmlSession()->getRatingData()); + $data = $this->getAdminhtmlSession()->getRatingData(); if (isset($data['rating_codes'])) { $this->_setRatingCodes($data['rating_codes']); } - Mage::getSingleton('adminhtml/session')->setRatingData(null); + $this->getAdminhtmlSession()->setRatingData(null); } elseif (Mage::registry('rating_data')) { $form->setValues(Mage::registry('rating_data')->getData()); if (Mage::registry('rating_data')->getRatingCodes()) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php index 192c4cc8e3a..df49a820413 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Creditmemo/Grid.php @@ -148,7 +148,7 @@ protected function _prepareMassaction() */ public function getRowUrl($row) { - if (!Mage::getSingleton('admin/session')->isAllowed('sales/order/creditmemo')) { + if (!$this->getAdminSession()->isAllowed('sales/order/creditmemo')) { return false; } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php index 9f5579a3afb..d7fad02d593 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php @@ -150,7 +150,7 @@ protected function _prepareMassaction() */ public function getRowUrl($row) { - if (!Mage::getSingleton('admin/session')->isAllowed('sales/order/invoice')) { + if (!$this->getAdminSession()->isAllowed('sales/order/invoice')) { return false; } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php index 7c3cc555096..220cb0fa257 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php @@ -461,7 +461,7 @@ public function canEditQty() public function canCapture() { - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/capture')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/capture')) { return $this->getInvoice()->canCapture(); } return false; diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order.php index ae933e6467f..e207c41ede9 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order.php @@ -28,7 +28,7 @@ public function __construct() $this->_headerText = Mage::helper('sales')->__('Orders'); $this->_addButtonLabel = Mage::helper('sales')->__('Create New Order'); parent::__construct(); - if (!Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/create')) { + if (!$this->getAdminSession()->isAllowed('sales/order/actions/create')) { $this->_removeButton('add'); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php index f22fda88e61..7d13e6f68f4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create.php @@ -73,7 +73,7 @@ public function __construct() */ protected function _isCanCancel() { - return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel'); + return $this->getAdminSession()->isAllowed('sales/order/actions/cancel'); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php index f8807b66350..224ca2fe4c0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Creditmemo/View.php @@ -221,6 +221,6 @@ public function updateBackButtonUrl($flag) */ public function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/' . $action); + return $this->getAdminSession()->isAllowed('sales/order/actions/' . $action); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php index 0a741c51538..a4cef23d255 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php @@ -116,7 +116,7 @@ protected function _prepareColumns() 'options' => Mage::getSingleton('sales/order_config')->getStatuses(), ]); - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/view')) { $this->addColumn( 'action', [ @@ -179,21 +179,21 @@ protected function _prepareMassaction() $this->getMassactionBlock()->setFormFieldName('order_ids'); $this->getMassactionBlock()->setUseSelectAll(false); - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/cancel')) { $this->getMassactionBlock()->addItem(MassAction::CANCEL_ORDER, [ 'label' => Mage::helper('sales')->__('Cancel'), 'url' => $this->getUrl('*/sales_order/massCancel'), ]); } - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/hold')) { $this->getMassactionBlock()->addItem(MassAction::HOLD_ORDER, [ 'label' => Mage::helper('sales')->__('Hold'), 'url' => $this->getUrl('*/sales_order/massHold'), ]); } - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/unhold')) { $this->getMassactionBlock()->addItem(MassAction::UNHOLD_ORDER, [ 'label' => Mage::helper('sales')->__('Unhold'), 'url' => $this->getUrl('*/sales_order/massUnhold'), @@ -234,7 +234,7 @@ protected function _prepareMassaction() */ public function getRowUrl($row) { - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/view')) { return $this->getUrl('*/sales_order/view', ['order_id' => $row->getId()]); } return false; diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php index 4953077efc5..248a8a93bd7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/Create/Items.php @@ -182,7 +182,7 @@ public function canEditQty() */ public function isCaptureAllowed() { - return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/capture'); + return $this->getAdminSession()->isAllowed('sales/order/actions/capture'); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php index 6025ae6bc2f..c5ecb2de739 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Invoice/View.php @@ -38,7 +38,7 @@ public function __construct() $this->_objectId = 'invoice_id'; $this->_controller = 'sales_order_invoice'; $this->_mode = 'view'; - $this->_session = Mage::getSingleton('admin/session'); + $this->_session = $this->getAdminSession(); parent::__construct(); diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php index 810aa208fc5..2bab6a6666f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View.php @@ -36,7 +36,7 @@ public function __construct() $this->_removeButton('reset'); $this->_removeButton('delete'); - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/emails')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/emails')) { $this->_updateButton('save', 'label', Mage::helper('sales')->__('Send Tracking Information')); $this->_updateButton( 'save', diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php index 7218d8cc256..9d6e7fc66df 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php @@ -341,7 +341,7 @@ public function getVoidPaymentUrl() */ protected function _isAllowedAction($action) { - return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/' . $action); + return $this->getAdminSession()->isAllowed('sales/order/actions/' . $action); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php index b8213637082..4d38300cc61 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php @@ -58,7 +58,7 @@ public function getOrder() public function canAddComment() { - return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/comment') && + return $this->getAdminSession()->isAllowed('sales/order/actions/comment') && $this->getOrder()->canComment(); } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php index ddc33164b6e..7d13f2f73a0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Info.php @@ -68,7 +68,7 @@ public function getCustomerGroupName() public function getCustomerViewUrl() { - if (!Mage::getSingleton('admin/session')->isAllowed('customer/manage')) { + if (!$this->getAdminSession()->isAllowed('customer/manage')) { return false; } if ($this->getOrder()->getCustomerIsGuest() || !$this->getOrder()->getCustomerId()) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php index aa5c2847643..07bbd740012 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Creditmemos.php @@ -132,7 +132,7 @@ public function getTabTitle() public function canShowTab() { - return Mage::getSingleton('admin/session')->isAllowed('sales/creditmemo'); + return $this->getAdminSession()->isAllowed('sales/creditmemo'); } public function isHidden() diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php index 4f577cafe0b..241cfcc7a59 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Invoices.php @@ -133,7 +133,7 @@ public function getTabTitle() public function canShowTab() { - return Mage::getSingleton('admin/session')->isAllowed('sales/invoice'); + return $this->getAdminSession()->isAllowed('sales/invoice'); } public function isHidden() diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php index 798eddebea6..18ed4e5df7b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Shipments.php @@ -121,7 +121,7 @@ public function canShowTab() if ($this->getOrder()->getIsVirtual()) { return false; } - return Mage::getSingleton('admin/session')->isAllowed('sales/shipment'); + return $this->getAdminSession()->isAllowed('sales/shipment'); } public function isHidden() diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php index 0427773601a..acaf9a0d1b6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Tab/Transactions.php @@ -69,7 +69,7 @@ public function getTabTitle() */ public function canShowTab() { - return Mage::getSingleton('admin/session')->isAllowed('sales/transactions'); + return $this->getAdminSession()->isAllowed('sales/transactions'); } /** @@ -79,6 +79,6 @@ public function canShowTab() */ public function isHidden() { - return !Mage::getSingleton('admin/session')->isAllowed('sales/transactions/fetch'); + return !$this->getAdminSession()->isAllowed('sales/transactions/fetch'); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php index adaecc24401..95e7b8b30ef 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Shipment/Grid.php @@ -130,7 +130,7 @@ protected function _prepareColumns() */ public function getRowUrl($row) { - if (!Mage::getSingleton('admin/session')->isAllowed('sales/order/shipment')) { + if (!$this->getAdminSession()->isAllowed('sales/order/shipment')) { return false; } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php index 62147af4f3e..8c7b003889e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Detail.php @@ -46,7 +46,7 @@ public function __construct() 'class' => 'back', ]); - if (Mage::getSingleton('admin/session')->isAllowed('sales/transactions/fetch') + if ($this->getAdminSession()->isAllowed('sales/transactions/fetch') && $this->_txn->getOrderPaymentObject()->getMethodInstance()->canFetchTransactionInfo() ) { $this->_addButton('fetch', [ diff --git a/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php index be8d725f66b..a8691403fe5 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Account/Edit/Form.php @@ -24,7 +24,7 @@ class Mage_Adminhtml_Block_System_Account_Edit_Form extends Mage_Adminhtml_Block { protected function _prepareForm() { - $userId = Mage::getSingleton('admin/session')->getUser()->getId(); + $userId = $this->getAdminSession()->getUser()->getId(); $user = Mage::getModel('admin/user') ->load($userId); $user->unsetData('password'); diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php index d627fa8a0d5..108d01488b1 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form/Fieldset.php @@ -187,7 +187,7 @@ protected function _getCollapseState($element) if ($element->getExpanded() !== null) { return 1; } - $extra = Mage::getSingleton('admin/session')->getUser()->getExtra(); + $extra = $this->getAdminSession()->getUser()->getExtra(); return $extra['configState'][$element->getId()] ?? false; } } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php index ba75eeec702..dcd1f8ffc3d 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php @@ -308,7 +308,7 @@ public function checkSectionPermissions($code = null) } if (!$permissions) { - $permissions = Mage::getSingleton('admin/session'); + $permissions = $this->getAdminSession(); } $showTab = false; diff --git a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php index 5db413617e0..3d0015edb97 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Convert/Profile/Run.php @@ -136,7 +136,7 @@ public function getProfile() */ public function getFormKey() { - return Mage::getSingleton('core/session')->getFormKey(); + return $this->getCoreSession()->getFormKey(); } /** * Return batch model and initialize it if need diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php index c3cfbd56cf9..23d98299361 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Matrix.php @@ -29,8 +29,8 @@ public function __construct() protected function _prepareLayout() { - $newRates = Mage::getSingleton('adminhtml/session')->getRates(); - Mage::getSingleton('adminhtml/session')->unsetData('rates'); + $newRates = $this->getAdminhtmlSession()->getRates(); + $this->getAdminhtmlSession()->unsetData('rates'); $currencyModel = Mage::getModel('directory/currency'); $currencies = $currencyModel->getConfigAllowCurrencies(); diff --git a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php index d83323270ba..2957fa3d6a3 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Currency/Rate/Services.php @@ -45,7 +45,7 @@ protected function _prepareLayout() ->setOptions(Mage::getModel('adminhtml/system_config_source_currency_service')->toOptionArray(0)) ->setId('rate_services') ->setName('rate_services') - ->setValue(Mage::getSingleton('adminhtml/session')->getCurrencyRateService(true)) + ->setValue($this->getAdminhtmlSession()->getCurrencyRateService(true)) ->setTitle(Mage::helper('adminhtml')->__('Import Service')), ); diff --git a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php index e04dd61f1f6..4ad10748fc0 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Design/Edit/Tab/General.php @@ -69,7 +69,7 @@ protected function _prepareForm() //'required' => true, ]); - $formData = Mage::getSingleton('adminhtml/session')->getDesignData(true); + $formData = $this->getAdminhtmlSession()->getDesignData(true); if (!$formData) { $formData = Mage::registry('design')->getData(); } else { diff --git a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php index 62ac731cc09..2da7eb43d8a 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Email/Template/Edit/Form.php @@ -137,7 +137,7 @@ protected function _prepareForm() $form->addValues($this->getEmailTemplate()->getData()); } - if ($values = Mage::getSingleton('adminhtml/session')->getData('email_template_form_data', true)) { + if ($values = $this->getAdminhtmlSession()->getData('email_template_form_data', true)) { $form->setValues($values); } diff --git a/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php b/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php index b6f50a4f178..6377805a164 100644 --- a/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php @@ -26,7 +26,7 @@ class Mage_Adminhtml_Block_System_Store_Edit extends Mage_Adminhtml_Block_Widget public function __construct() { $backupAvailable = - Mage::getSingleton('admin/session')->isAllowed('system/tools/backup') + $this->getAdminSession()->isAllowed('system/tools/backup') && $this->isModuleEnabled('Mage_Backup') && !Mage::getStoreConfigFlag('advanced/modules_disable_output/Mage_Backup'); @@ -115,7 +115,7 @@ public function _getDeleteUrl($storeType, $backupAvailable = false) '*/*/delete' . $storeType . 'Post', [ 'item_id' => Mage::registry('store_data')->getId(), - 'form_key' => Mage::getSingleton('core/session')->getFormKey(), + 'form_key' => $this->getCoreSession()->getFormKey(), ], ); } diff --git a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php index 7ed5c06caca..fc26b67c163 100644 --- a/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Tag/Edit/Form.php @@ -55,7 +55,7 @@ protected function _prepareForm() $fieldset->addField('form_key', 'hidden', [ 'name' => 'form_key', - 'value' => Mage::getSingleton('core/session')->getFormKey(), + 'value' => $this->getCoreSession()->getFormKey(), ]); $fieldset->addField('store_id', 'hidden', [ @@ -91,13 +91,13 @@ protected function _prepareForm() 'after_element_html' => ' ' . Mage::helper('tag')->__('[STORE VIEW]'), ]); - if (!$model->getId() && !Mage::getSingleton('adminhtml/session')->getTagData()) { + if (!$model->getId() && !$this->getAdminhtmlSession()->getTagData()) { $model->setStatus(Mage_Tag_Model_Tag::STATUS_APPROVED); } - if (Mage::getSingleton('adminhtml/session')->getTagData()) { - $form->addValues(Mage::getSingleton('adminhtml/session')->getTagData()); - Mage::getSingleton('adminhtml/session')->setTagData(null); + if ($this->getAdminhtmlSession()->getTagData()) { + $form->addValues($this->getAdminhtmlSession()->getTagData()); + $this->getAdminhtmlSession()->setTagData(null); } else { $form->addValues($model->getData()); } diff --git a/app/code/core/Mage/Adminhtml/Block/Template.php b/app/code/core/Mage/Adminhtml/Block/Template.php index 63314a08acc..071768fbb7f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Template.php +++ b/app/code/core/Mage/Adminhtml/Block/Template.php @@ -37,7 +37,7 @@ protected function _getUrlModelClass() */ public function getFormKey() { - return Mage::getSingleton('core/session')->getFormKey(); + return $this->getCoreSession()->getFormKey(); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php index 3ee86ba7873..36316d9da55 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php @@ -61,7 +61,7 @@ protected function _prepareForm() 'options' => $model->getOptions(), 'description' => $model->getDescription(), ]; - if ($sessionData = Mage::getSingleton('adminhtml/session')->getData('urlrewrite_data', true)) { + if ($sessionData = $this->getAdminhtmlSession()->getData('urlrewrite_data', true)) { foreach (array_keys($formValues) as $key) { if (isset($sessionData[$key])) { $formValues[$key] = $sessionData[$key]; diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index 8fd1fb1f136..35d19ded42e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -1479,7 +1479,7 @@ public function getAbsoluteGridUrl($params = []) */ public function getParam($paramName, $default = null) { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $sessionParamName = $this->getId() . $paramName; if ($this->getRequest()->has($paramName)) { $param = $this->getRequest()->getParam($paramName); @@ -1508,7 +1508,7 @@ public function setSaveParametersInSession($flag) public function resetSavedParametersInSession() { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $params = [ $this->_varNameLimit, diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php index cfa4e93ec5e..f5bf3f7eb5b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php @@ -206,7 +206,7 @@ protected function _beforeToHtml() Mage::dispatchEvent('adminhtml_block_widget_tabs_html_before', ['block' => $this]); if ($activeTab = $this->getRequest()->getParam('active_tab')) { $this->setActiveTab($activeTab); - } elseif ($activeTabId = Mage::getSingleton('admin/session')->getActiveTabId()) { + } elseif ($activeTabId = $this->getAdminSession()->getActiveTabId()) { $this->_setActiveTab($activeTabId); } diff --git a/app/code/core/Mage/Adminhtml/Controller/Action.php b/app/code/core/Mage/Adminhtml/Controller/Action.php index 2c84c954b55..cd260bde1fe 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Action.php +++ b/app/code/core/Mage/Adminhtml/Controller/Action.php @@ -78,17 +78,17 @@ class Mage_Adminhtml_Controller_Action extends Mage_Core_Controller_Varien_Actio */ protected function _isAllowed() { - return Mage::getSingleton('admin/session')->isAllowed(static::ADMIN_RESOURCE); + return $this->getAdminSession()->isAllowed(static::ADMIN_RESOURCE); } /** - * Retrieve adminhtml session model object - * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ protected function _getSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } /** @@ -175,7 +175,7 @@ public function preDispatch() $isValidFormKey = true; $isValidSecretKey = true; $keyErrorMsg = ''; - if (Mage::getSingleton('admin/session')->isLoggedIn()) { + if ($this->getAdminSession()->isLoggedIn()) { if ($this->getRequest()->isPost() || $this->_checkIsForcedFormKeyAction()) { $isValidFormKey = $this->_validateFormKey(); $keyErrorMsg = Mage::helper('adminhtml')->__('Invalid Form Key. Please refresh the page.'); @@ -194,9 +194,9 @@ public function preDispatch() ])); } else { if (!$isValidFormKey) { - Mage::getSingleton('adminhtml/session')->addError($keyErrorMsg); + $this->getAdminhtmlSession()->addError($keyErrorMsg); } - $this->_redirect(Mage::getSingleton('admin/session')->getUser()->getStartupPageUrl()); + $this->_redirect($this->getAdminSession()->getUser()->getStartupPageUrl()); } return $this; } @@ -218,8 +218,8 @@ public function preDispatch() //$this->_checkUrlSettings(); $this->setFlag('', self::FLAG_IS_URLS_CHECKED, true); } - if (is_null(Mage::getSingleton('adminhtml/session')->getLocale())) { - Mage::getSingleton('adminhtml/session')->setLocale(Mage::app()->getLocale()->getLocaleCode()); + if (is_null($this->getAdminhtmlSession()->getLocale())) { + $this->getAdminhtmlSession()->setLocale(Mage::app()->getLocale()->getLocaleCode()); } return $this; @@ -281,7 +281,7 @@ protected function _checkUrlSettings() public function deniedAction() { $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden'); - if (!Mage::getSingleton('admin/session')->isLoggedIn()) { + if (!$this->getAdminSession()->isLoggedIn()) { $this->_redirect('*/index/login'); return; } @@ -292,7 +292,7 @@ public function deniedAction() public function loadLayout($ids = null, $generateBlocks = true, $generateXml = true) { parent::loadLayout($ids, $generateBlocks, $generateXml); - $this->_initLayoutMessages('adminhtml/session'); + $this->_initLayoutMessages($this->getAdminSessionStorage()); return $this; } @@ -373,7 +373,7 @@ protected function _redirect($path, $arguments = []) protected function _forward($action, $controller = null, $module = null, ?array $params = null) { $this->_getSession()->setIsUrlNotice($this->getFlag('', self::FLAG_IS_URLS_CHECKED)); - return parent::_forward($action, $controller, $module, $params); + parent::_forward($action, $controller, $module, $params); } /** @@ -412,11 +412,11 @@ protected function _validateSecretKey() * * @param string $password - current password * - * @return mixed - returns true or array of errors + * @return array|true - returns true or array of errors */ protected function _validateCurrentPassword($password) { - $user = Mage::getSingleton('admin/session')->getUser(); + $user = $this->getAdminSession()->getUser(); return $user->validateCurrentPassword($password); } diff --git a/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php b/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php index 754eecb0490..28519fd9969 100644 --- a/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php @@ -37,7 +37,7 @@ abstract class Mage_Adminhtml_Controller_Report_Abstract extends Mage_Adminhtml_ protected function _getSession() { if (is_null($this->_adminSession)) { - $this->_adminSession = Mage::getSingleton('admin/session'); + $this->_adminSession = $this->getAdminSession(); } return $this->_adminSession; } @@ -108,7 +108,7 @@ protected function _showLastExecutionTime($flagCode, $refreshCode) $refreshStatsLink = $this->getUrl('*/report_statistics'); $directRefreshLink = $this->getUrl('*/report_statistics/refreshRecent', ['code' => $refreshCode]); - Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('adminhtml')->__('Last updated: %s. To refresh last day\'s statistics, click here.', $updatedAt, $refreshStatsLink, $directRefreshLink)); + $this->getAdminhtmlSession()->addNotice(Mage::helper('adminhtml')->__('Last updated: %s. To refresh last day\'s statistics, click here.', $updatedAt, $refreshStatsLink, $directRefreshLink)); return $this; } } diff --git a/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php b/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php index d4c9440fc61..faec4725fac 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Helper/Catalog/Product/Edit/Action/Attribute.php @@ -73,8 +73,7 @@ public function getProducts() */ public function getProductIds() { - /** @var Mage_Adminhtml_Model_Session $session */ - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if ($this->_getRequest()->isPost() && strtolower($this->_getRequest()->getActionName()) === 'edit') { $session->setProductIds($this->_getRequest()->getParam('product', null)); diff --git a/app/code/core/Mage/Adminhtml/Helper/Data.php b/app/code/core/Mage/Adminhtml/Helper/Data.php index c2e04803818..a9867f76bdf 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Data.php +++ b/app/code/core/Mage/Adminhtml/Helper/Data.php @@ -91,8 +91,8 @@ public static function getUrl($route = '', $params = []) */ public function getCurrentUserId() { - if (Mage::getSingleton('admin/session')->getUser()) { - return Mage::getSingleton('admin/session')->getUser()->getId(); + if ($this->getAdminSession()->getUser()) { + return $this->getAdminSession()->getUser()->getId(); } return false; } diff --git a/app/code/core/Mage/Adminhtml/Helper/Rss.php b/app/code/core/Mage/Adminhtml/Helper/Rss.php index bfc7a66c9a7..5c0b43c4666 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Rss.php +++ b/app/code/core/Mage/Adminhtml/Helper/Rss.php @@ -31,7 +31,7 @@ class Mage_Adminhtml_Helper_Rss extends Mage_Core_Helper_Abstract */ public function authAdmin($path) { - $session = Mage::getSingleton('rss/session'); + $session = $this->getRssSession(); if ($session->isAdminLoggedIn()) { return; } diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php index 0effd78b210..d0c7a11e216 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php +++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php @@ -37,6 +37,8 @@ */ class Mage_Adminhtml_Model_Config_Data extends Varien_Object { + use Mage_Core_Trait_Session; + public const SCOPE_DEFAULT = 'default'; public const SCOPE_WEBSITES = 'websites'; public const SCOPE_STORES = 'stores'; @@ -259,7 +261,7 @@ public function extendConfig($path, $full = true, $oldConfig = []) protected function _isSectionAllowed($section) { try { - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); $resourceLookup = "admin/system/config/{$section}"; if ($session->getData('acl') instanceof Mage_Admin_Model_Acl) { return $session->isAllowed( diff --git a/app/code/core/Mage/Adminhtml/Model/Observer.php b/app/code/core/Mage/Adminhtml/Model/Observer.php index 79fa459b9b1..8e86c4610eb 100644 --- a/app/code/core/Mage/Adminhtml/Model/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Observer.php @@ -20,12 +20,12 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Model_Observer +class Mage_Adminhtml_Model_Observer extends Mage_Core_Model_Observer { public function bindLocale($observer) { if ($locale = $observer->getEvent()->getLocale()) { - if ($choosedLocale = Mage::getSingleton('adminhtml/session')->getLocale()) { + if ($choosedLocale = $this->getAdminhtmlSession()->getLocale()) { $locale->setLocaleCode($choosedLocale); } } diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order.php index 024a571c9ac..d89252252cf 100644 --- a/app/code/core/Mage/Adminhtml/Model/Sales/Order.php +++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order.php @@ -22,14 +22,18 @@ */ class Mage_Adminhtml_Model_Sales_Order { + use Mage_Core_Trait_Session; + /** * Retrieve adminhtml session singleton * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ protected function _getSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } public function checkRelation(Mage_Sales_Model_Order $order) @@ -39,7 +43,7 @@ public function checkRelation(Mage_Sales_Model_Order $order) */ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId()); if (!$customer->getId()) { - $this->_getSession()->addNotice( + $this->getAdminhtmlSession()->addNotice( Mage::helper('adminhtml')->__(' The customer does not exist in the system anymore.'), ); } @@ -59,7 +63,7 @@ public function checkRelation(Mage_Sales_Model_Order $order) $hasBadItems = false; foreach ($order->getAllItems() as $item) { if (!$productCollection->getItemById($item->getProductId())) { - $this->_getSession()->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('adminhtml')->__( 'The item %s (SKU %s) does not exist in the catalog anymore.', $item->getName(), @@ -70,7 +74,7 @@ public function checkRelation(Mage_Sales_Model_Order $order) } } if ($hasBadItems) { - $this->_getSession()->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('adminhtml')->__('Some of the ordered items do not exist in the catalog anymore and will be removed if you try to edit the order.'), ); } diff --git a/app/code/core/Mage/Adminhtml/Model/Session.php b/app/code/core/Mage/Adminhtml/Model/Session.php index a347ffa06ba..c5b4f2237aa 100644 --- a/app/code/core/Mage/Adminhtml/Model/Session.php +++ b/app/code/core/Mage/Adminhtml/Model/Session.php @@ -20,6 +20,8 @@ * @category Mage * @package Mage_Adminhtml * + * @method string getCommentText(bool $value) + * @method $this setCommentText(string $value) * @method array|string getProductIds() * @method $this setProductIds(array|string $value) */ diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php index 7eac2f0a9c4..b5b218f030e 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Admin/Observer.php @@ -18,7 +18,7 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Model_System_Config_Backend_Admin_Observer +class Mage_Adminhtml_Model_System_Config_Backend_Admin_Observer extends Mage_Core_Model_Observer { /** * Log out user and redirect him to new admin custom url @@ -32,8 +32,7 @@ public function afterCustomUrlChanged($observer) return; } - /** @var Mage_Admin_Model_Session $adminSession */ - $adminSession = Mage::getSingleton('admin/session'); + $adminSession = $this->getAdminSession(); $adminSession->unsetAll(); $adminSession->getCookie()->delete($adminSession->getSessionName()); diff --git a/app/code/core/Mage/Adminhtml/Model/Url.php b/app/code/core/Mage/Adminhtml/Model/Url.php index 431ae2f2f6c..2d37dc2b74c 100644 --- a/app/code/core/Mage/Adminhtml/Model/Url.php +++ b/app/code/core/Mage/Adminhtml/Model/Url.php @@ -108,7 +108,7 @@ public function getUrl($routePath = null, $routeParams = null) */ public function getSecretKey($controller = null, $action = null) { - $salt = Mage::getSingleton('core/session')->getFormKey(); + $salt = $this->getCoreSession()->getFormKey(); $p = explode('/', trim($this->getRequest()->getOriginalPathInfo(), '/')); if (!$controller) { diff --git a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php index a46ef0926e3..105fd1cfbb5 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Api/RoleController.php @@ -127,9 +127,9 @@ public function deleteAction() try { Mage::getModel('api/roles')->load($rid)->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The role has been deleted.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The role has been deleted.')); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while deleting this role.')); + $this->getAdminhtmlSession()->addError($this->__('An error occurred while deleting this role.')); } $this->_redirect('*/*/'); @@ -137,10 +137,10 @@ public function deleteAction() public function saveRoleAction() { - $rid = $this->getRequest()->getParam('role_id', false); + $rid = $this->getRequest()->getParam('role_id', false); $role = Mage::getModel('api/roles')->load($rid); if (!$role->getId() && $rid) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This Role no longer exists')); + $this->getAdminhtmlSession()->addError($this->__('This Role no longer exists')); $this->_redirect('*/*/'); return; } @@ -193,9 +193,9 @@ public function saveRoleAction() } $rid = $role->getId(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The role has been saved.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The role has been saved.')); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this role.')); + $this->getAdminhtmlSession()->addError($this->__('An error occurred while saving this role.')); } $this->_redirect('*/*/editrole', ['rid' => $rid]); diff --git a/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php index a92e73c277d..697ff15755f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php @@ -76,7 +76,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This user no longer exists.')); $this->_redirect('*/*/'); return; } @@ -85,7 +85,7 @@ public function editAction() $this->_title($model->getId() ? $model->getName() : $this->__('New User')); // Restore previously entered form data from session - $data = Mage::getSingleton('adminhtml/session')->getUserData(true); + $data = $this->getAdminhtmlSession()->getUserData(true); if (!empty($data)) { $model->setData($data); } @@ -115,7 +115,7 @@ public function saveAction() $id = $this->getRequest()->getPost('user_id', false); $model = Mage::getModel('api/user')->load($id); if (!$model->getId() && $id) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This user no longer exists.')); $this->_redirect('*/*/'); return; } @@ -167,13 +167,13 @@ public function saveAction() $model->setRoleIds($rs)->setRoleUserId($model->getUserId())->saveRelations(); } } - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been saved.')); - Mage::getSingleton('adminhtml/session')->setUserData(false); + $this->getAdminhtmlSession()->addSuccess($this->__('The user has been saved.')); + $this->getAdminhtmlSession()->setUserData(false); $this->_redirect('*/*/edit', ['user_id' => $model->getUserId()]); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setUserData($data); + $this->getAdminhtmlSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->setUserData($data); $this->_redirect('*/*/edit', ['user_id' => $model->getUserId()]); return; } @@ -202,16 +202,16 @@ public function deleteAction() try { $model = Mage::getModel('api/user')->load($id); $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been deleted.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The user has been deleted.')); $this->_redirect('*/*/'); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', ['user_id' => $id]); return; } } - Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find a user to delete.')); + $this->getAdminhtmlSession()->addError($this->__('Unable to find a user to delete.')); $this->_redirect('*/*/'); } diff --git a/app/code/core/Mage/Adminhtml/controllers/CacheController.php b/app/code/core/Mage/Adminhtml/controllers/CacheController.php index 08fce26bdb7..771498fc640 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CacheController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CacheController.php @@ -30,10 +30,12 @@ class Mage_Adminhtml_CacheController extends Mage_Adminhtml_Controller_Action * Retrieve session model * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ protected function _getSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } /** diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php index a38e1bd1aa5..ae7b0332ee9 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php @@ -63,7 +63,7 @@ protected function _initCategory($getRootInstead = false) } if ($activeTabId = (string) $this->getRequest()->getParam('active_tab_id')) { - Mage::getSingleton('admin/session')->setActiveTabId($activeTabId); + $this->getAdminSession()->setActiveTabId($activeTabId); } Mage::register('category', $category); @@ -84,7 +84,7 @@ public function indexAction() */ public function addAction() { - Mage::getSingleton('admin/session')->unsActiveTabId(); + $this->getAdminSession()->unsActiveTabId(); $this->_forward('edit'); } @@ -98,8 +98,7 @@ public function editAction() $storeId = (int) $this->getRequest()->getParam('store'); $parentId = (int) $this->getRequest()->getParam('parent'); - $prevStoreId = Mage::getSingleton('admin/session') - ->getLastViewedStore(true); + $prevStoreId = $this->getAdminSession()->getLastViewedStore(true); if (!empty($prevStoreId) && !$this->getRequest()->getQuery('isAjax')) { $params['store'] = $prevStoreId; @@ -107,8 +106,7 @@ public function editAction() } $categoryId = (int) $this->getRequest()->getParam('id'); - $prevCategoryId = Mage::getSingleton('admin/session') - ->getLastEditedCategory(true); + $prevCategoryId = $this->getAdminSession()->getLastEditedCategory(true); if ($prevCategoryId && !$this->getRequest()->getQuery('isAjax') @@ -137,7 +135,7 @@ public function editAction() /** * Check if we have data in session (if duering category save was exceprion) */ - $data = Mage::getSingleton('adminhtml/session')->getCategoryData(true); + $data = $this->getAdminhtmlSession()->getCategoryData(true); if (isset($data['general'])) { $category->addData($data['general']); } @@ -150,7 +148,7 @@ public function editAction() $breadcrumbsPath = $category->getPath(); if (empty($breadcrumbsPath)) { // but if no category, and it is deleted - prepare breadcrumbs from path, saved in session - $breadcrumbsPath = Mage::getSingleton('admin/session')->getDeletedPath(true); + $breadcrumbsPath = $this->getAdminSession()->getDeletedPath(true); if (!empty($breadcrumbsPath)) { $breadcrumbsPath = explode('/', $breadcrumbsPath); // no need to get parent breadcrumbs if deleting category level 1 @@ -163,10 +161,8 @@ public function editAction() } } - Mage::getSingleton('admin/session') - ->setLastViewedStore($this->getRequest()->getParam('store')); - Mage::getSingleton('admin/session') - ->setLastEditedCategory($category->getId()); + $this->getAdminSession()->setLastViewedStore($this->getRequest()->getParam('store')); + $this->getAdminSession()->setLastEditedCategory($category->getId()); $this->loadLayout(); $eventResponse = new Varien_Object([ @@ -231,9 +227,9 @@ public function wysiwygAction() public function categoriesJsonAction() { if ($this->getRequest()->getParam('expand_all')) { - Mage::getSingleton('admin/session')->setIsTreeWasExpanded(true); + $this->getAdminSession()->setIsTreeWasExpanded(true); } else { - Mage::getSingleton('admin/session')->setIsTreeWasExpanded(false); + $this->getAdminSession()->setIsTreeWasExpanded(false); } if ($categoryId = (int) $this->getRequest()->getPost('id')) { $this->getRequest()->setParam('id', $categoryId); @@ -341,7 +337,7 @@ public function saveAction() $category->unsetData('use_post_data_config'); $category->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('The category has been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('catalog')->__('The category has been saved.')); $refreshTree = 'true'; } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()) @@ -395,16 +391,16 @@ public function deleteAction() $category = Mage::getModel('catalog/category')->load($id); Mage::dispatchEvent('catalog_controller_category_delete', ['category' => $category]); - Mage::getSingleton('admin/session')->setDeletedPath($category->getPath()); + $this->getAdminSession()->setDeletedPath($category->getPath()); $category->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('The category has been deleted.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('catalog')->__('The category has been deleted.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->getResponse()->setRedirect($this->getUrl('*/*/edit', ['_current' => true])); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('An error occurred while trying to delete the category.')); + $this->getAdminhtmlSession()->addError(Mage::helper('catalog')->__('An error occurred while trying to delete the category.')); $this->getResponse()->setRedirect($this->getUrl('*/*/edit', ['_current' => true])); return; } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php index 18280d329cd..d0a935c3386 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php @@ -257,7 +257,7 @@ public function validateAction() $response->setMessage($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s) attributes.')); - $this->_initLayoutMessages('adminhtml/session'); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php index 40e1487c5f4..84fc083301e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php @@ -95,7 +95,7 @@ public function editAction() $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalog')->__('This attribute no longer exists'), ); $this->_redirect('*/*/'); @@ -104,7 +104,7 @@ public function editAction() // entity type check if ($model->getEntityTypeId() != $this->_entityTypeId) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalog')->__('This attribute cannot be edited.'), ); $this->_redirect('*/*/'); @@ -113,7 +113,7 @@ public function editAction() } // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getAttributeData(true); + $data = $this->getAdminhtmlSession()->getAttributeData(true); if (!empty($data)) { $model->addData($data); } @@ -146,10 +146,10 @@ public function validateAction() ->loadByCode($this->_entityTypeId, $attributeCode); if ($attribute->getId() && !$attributeId) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalog')->__('Attribute with the same code already exists'), ); - $this->_initLayoutMessages('adminhtml/session'); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } @@ -194,8 +194,7 @@ public function saveAction() { $data = $this->getRequest()->getPost(); if ($data) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $redirectBack = $this->getRequest()->getParam('back', false); /** @var Mage_Catalog_Model_Entity_Attribute $model */ @@ -347,7 +346,7 @@ public function deleteAction() // entity type check $model->load($id); if ($model->getEntityTypeId() != $this->_entityTypeId || !$model->getIsUserDefined()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalog')->__('This attribute cannot be deleted.'), ); $this->_redirect('*/*/'); @@ -356,18 +355,18 @@ public function deleteAction() try { $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('catalog')->__('The product attribute has been deleted.'), ); $this->_redirect('*/*/'); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', ['attribute_id' => $this->getRequest()->getParam('attribute_id')]); return; } } - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalog')->__('Unable to find an attribute to delete.'), ); $this->_redirect('*/*/'); diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php index 32c30fcba0f..375e2672563 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GroupController.php @@ -35,12 +35,12 @@ public function saveAction() ->setAttributeSetId($this->getRequest()->getParam('attribute_set_id')); if ($model->itemExists()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('A group with the same name already exists.')); + $this->getAdminhtmlSession()->addError(Mage::helper('catalog')->__('A group with the same name already exists.')); } else { try { $model->save(); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('An error occurred while saving this group.')); + $this->getAdminhtmlSession()->addError(Mage::helper('catalog')->__('An error occurred while saving this group.')); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php index 1e35616e11e..8d74cde1495 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php @@ -125,7 +125,7 @@ public function saveAction() { if (($data = $this->getRequest()->getPost()) && ($reviewId = $this->getRequest()->getParam('id'))) { $review = Mage::getModel('review/review')->load($reviewId); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if (!$review->getId()) { $session->addError(Mage::helper('catalog')->__('The review was removed by another user or does not exist.')); } else { @@ -171,7 +171,7 @@ public function saveAction() public function deleteAction() { $reviewId = $this->getRequest()->getParam('id', false); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); try { Mage::getModel('review/review')->setId($reviewId) @@ -197,7 +197,7 @@ public function deleteAction() public function massDeleteAction() { $reviewsIds = $this->getRequest()->getParam('reviews'); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if (!is_array($reviewsIds)) { $session->addError(Mage::helper('adminhtml')->__('Please select review(s).')); @@ -207,7 +207,7 @@ public function massDeleteAction() $model = Mage::getModel('review/review')->load($reviewId); $model->delete(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) have been deleted.', count($reviewsIds)), ); } catch (Mage_Core_Exception $e) { @@ -223,7 +223,7 @@ public function massDeleteAction() public function massUpdateStatusAction() { $reviewsIds = $this->getRequest()->getParam('reviews'); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if (!is_array($reviewsIds)) { $session->addError(Mage::helper('adminhtml')->__('Please select review(s).')); @@ -253,12 +253,12 @@ public function massUpdateStatusAction() public function massVisibleInAction() { $reviewsIds = $this->getRequest()->getParam('reviews'); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if (!is_array($reviewsIds)) { $session->addError(Mage::helper('adminhtml')->__('Please select review(s).')); } else { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); /** @var Mage_Adminhtml_Model_Session $session */ try { $stores = $this->getRequest()->getParam('stores'); @@ -311,7 +311,7 @@ public function jsonProductInfoAction() public function postAction() { $productId = $this->getRequest()->getParam('product_id', false); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if ($data = $this->getRequest()->getPost()) { if (Mage::app()->isSingleStoreMode()) { @@ -375,9 +375,9 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'pending': - return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/pending'); + return $this->getAdminSession()->isAllowed('catalog/reviews_ratings/reviews/pending'); default: - return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/all'); + return $this->getAdminSession()->isAllowed('catalog/reviews_ratings/reviews/all'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php index 9e473575663..171ef4ffd95 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php @@ -142,12 +142,12 @@ public function saveAction() $model->initFromSkeleton($this->getRequest()->getParam('skeleton_set')); } $model->save(); - $this->_getSession()->addSuccess(Mage::helper('catalog')->__('The attribute set has been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('catalog')->__('The attribute set has been saved.')); } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError($e->getMessage()); + $this->getAdminSession()->addError($e->getMessage()); $hasError = true; } catch (Exception $e) { - $this->_getSession()->addException( + $this->getAdminhtmlSession()->addException( $e, Mage::helper('catalog')->__('An error occurred while saving the attribute set.'), ); @@ -163,7 +163,7 @@ public function saveAction() } else { $response = []; if ($hasError) { - $this->_initLayoutMessages('adminhtml/session'); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $response['error'] = 1; $response['message'] = $this->getLayout()->getMessagesBlock()->getGroupedHtml(); } else { @@ -199,10 +199,10 @@ public function deleteAction() ->setId($setId) ->delete(); - $this->_getSession()->addSuccess($this->__('The attribute set has been removed.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The attribute set has been removed.')); $this->getResponse()->setRedirect($this->getUrl('*/*/')); } catch (Exception $e) { - $this->_getSession()->addError($this->__('An error occurred while deleting this set.')); + $this->getAdminhtmlSession()->addError($this->__('An error occurred while deleting this set.')); $this->_redirectReferer(); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php index e8a68682eae..bbe0856448d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php @@ -560,7 +560,7 @@ public function validateAction() $response->setMessage($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); - $this->_initLayoutMessages('adminhtml/session'); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } @@ -1100,8 +1100,8 @@ public function quickCreateAction() $product->validate(); $product->save(); $result['product_id'] = $product->getId(); - $this->_getSession()->addSuccess(Mage::helper('catalog')->__('The product has been created.')); - $this->_initLayoutMessages('adminhtml/session'); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('catalog')->__('The product has been created.')); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $result['messages'] = $this->getLayout()->getMessagesBlock()->getGroupedHtml(); } catch (Mage_Core_Exception $e) { $result['error'] = [ @@ -1128,7 +1128,7 @@ public function quickCreateAction() */ public function showUpdateResultAction() { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if ($session->hasCompositeProductResult() && $session->getCompositeProductResult() instanceof Varien_Object) { /** @var Mage_Adminhtml_Helper_Catalog_Product_Composite $helper */ $helper = Mage::helper('adminhtml/catalog_product_composite'); diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php index 5f99d98d68d..aa3d8f97b1b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/SearchController.php @@ -60,14 +60,14 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('This search no longer exists.')); + $this->getAdminhtmlSession()->addError(Mage::helper('catalog')->__('This search no longer exists.')); $this->_redirect('*/*'); return; } } // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getPageData(true); + $data = $this->getAdminhtmlSession()->getPageData(true); if (!empty($data)) { $model->addData($data); } @@ -154,16 +154,16 @@ public function deleteAction() $model = Mage::getModel('catalogsearch/query'); $model->setId($id); $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('The search was deleted.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('catalog')->__('The search was deleted.')); $this->_redirect('*/*/'); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', ['id' => $this->getRequest()->getParam('id')]); return; } } - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Unable to find a search term to delete.')); + $this->getAdminhtmlSession()->addError(Mage::helper('catalog')->__('Unable to find a search term to delete.')); $this->_redirect('*/*/'); } @@ -171,18 +171,18 @@ public function massDeleteAction() { $searchIds = $this->getRequest()->getParam('search'); if (!is_array($searchIds)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select catalog searches.')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Please select catalog searches.')); } else { try { foreach ($searchIds as $searchId) { $model = Mage::getModel('catalogsearch/query')->load($searchId); $model->delete(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) were deleted', count($searchIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php b/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php index 01ecf35725f..6b177caacff 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Checkout/AgreementController.php @@ -64,7 +64,7 @@ public function editAction() if ($id) { $agreementModel->load($id); if (!$agreementModel->getId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('checkout')->__('This condition no longer exists.'), ); $this->_redirect('*/*/'); @@ -74,7 +74,7 @@ public function editAction() $this->_title($agreementModel->getId() ? $agreementModel->getName() : $this->__('New Condition')); - $data = Mage::getSingleton('adminhtml/session')->getAgreementData(true); + $data = $this->getAdminhtmlSession()->getAgreementData(true); if (!empty($data)) { $agreementModel->setData($data); } @@ -96,17 +96,17 @@ public function saveAction() try { $model->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('checkout')->__('The condition has been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('checkout')->__('The condition has been saved.')); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('An error occurred while saving this condition.')); + $this->getAdminhtmlSession()->addError(Mage::helper('checkout')->__('An error occurred while saving this condition.')); } - Mage::getSingleton('adminhtml/session')->setAgreementData($postData); + $this->getAdminhtmlSession()->setAgreementData($postData); $this->_redirectReferer(); } } @@ -117,7 +117,7 @@ public function deleteAction() $model = Mage::getSingleton('checkout/agreement') ->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('This condition no longer exists.')); + $this->getAdminhtmlSession()->addError(Mage::helper('checkout')->__('This condition no longer exists.')); $this->_redirect('*/*/'); return; } @@ -125,14 +125,14 @@ public function deleteAction() try { $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('checkout')->__('The condition has been deleted')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('checkout')->__('The condition has been deleted')); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('checkout')->__('An error occurred while deleting this condition.')); + $this->getAdminhtmlSession()->addError(Mage::helper('checkout')->__('An error occurred while deleting this condition.')); } $this->_redirectReferer(); diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php index 10399620dd2..03d7d8e2240 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php @@ -90,7 +90,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists.')); + $this->getAdminhtmlSession()->addError(Mage::helper('cms')->__('This block no longer exists.')); $this->_redirect('*/*/'); return; } @@ -99,7 +99,7 @@ public function editAction() $this->_title($model->getId() ? $model->getTitle() : $this->__('New Block')); // 3. Set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getFormData(true); + $data = $this->getAdminhtmlSession()->getFormData(true); if (!empty($data)) { $model->setData($data); } @@ -123,7 +123,7 @@ public function saveAction() $id = $this->getRequest()->getParam('block_id'); $model = Mage::getModel('cms/block')->load($id); if (!$model->getId() && $id) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists.')); + $this->getAdminhtmlSession()->addError(Mage::helper('cms')->__('This block no longer exists.')); $this->_redirect('*/*/'); return; } @@ -137,9 +137,9 @@ public function saveAction() // save the data $model->save(); // display success message - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('The block has been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('cms')->__('The block has been saved.')); // clear previously saved data from session - Mage::getSingleton('adminhtml/session')->setFormData(false); + $this->getAdminhtmlSession()->setFormData(false); // check if 'Save and Continue' if ($this->getRequest()->getParam('back')) { @@ -151,9 +151,9 @@ public function saveAction() return; } catch (Exception $e) { // display error message - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); // save data in session - Mage::getSingleton('adminhtml/session')->setFormData($data); + $this->getAdminhtmlSession()->setFormData($data); // redirect to edit form $this->_redirect('*/*/edit', ['block_id' => $this->getRequest()->getParam('block_id')]); return; @@ -177,20 +177,20 @@ public function deleteAction() $title = $model->getTitle(); $model->delete(); // display success message - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('The block has been deleted.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('cms')->__('The block has been deleted.')); // go to grid $this->_redirect('*/*/'); return; } catch (Exception $e) { // display error message - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); // go back to edit form $this->_redirect('*/*/edit', ['block_id' => $id]); return; } } // display error message - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a block to delete.')); + $this->getAdminhtmlSession()->addError(Mage::helper('cms')->__('Unable to find a block to delete.')); // go to grid $this->_redirect('*/*/'); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php index 261520af044..c721a357db1 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php @@ -77,7 +77,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('cms')->__('This page no longer exists.'), ); $this->_redirect('*/*/'); @@ -88,7 +88,7 @@ public function editAction() $this->_title($model->getId() ? $model->getTitle() : $this->__('New Page')); // 3. Set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getFormData(true); + $data = $this->getAdminhtmlSession()->getFormData(true); if (!empty($data)) { $data['store_id'] = $data['stores']; $model->setData($data); @@ -140,11 +140,11 @@ public function saveAction() $model->save(); // display success message - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('cms')->__('The page has been saved.'), ); // clear previously saved data from session - Mage::getSingleton('adminhtml/session')->setFormData(false); + $this->getAdminhtmlSession()->setFormData(false); // check if 'Save and Continue' if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', ['page_id' => $model->getId(), '_current' => true]); @@ -184,7 +184,7 @@ public function deleteAction() $title = $model->getTitle(); $model->delete(); // display success message - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('cms')->__('The page has been deleted.'), ); // go to grid @@ -194,14 +194,14 @@ public function deleteAction() } catch (Exception $e) { Mage::dispatchEvent('adminhtml_cmspage_on_delete', ['title' => $title, 'status' => 'fail']); // display error message - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); // go back to edit form $this->_redirect('*/*/edit', ['page_id' => $id]); return; } } // display error message - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a page to delete.')); + $this->getAdminhtmlSession()->addError(Mage::helper('cms')->__('Unable to find a page to delete.')); // go to grid $this->_redirect('*/*/'); } @@ -226,11 +226,11 @@ protected function _isAllowed() switch ($action) { case 'new': case 'save': - return Mage::getSingleton('admin/session')->isAllowed('cms/page/save'); + return $this->getAdminSession()->isAllowed('cms/page/save'); case 'delete': - return Mage::getSingleton('admin/session')->isAllowed('cms/page/delete'); + return $this->getAdminSession()->isAllowed('cms/page/delete'); default: - return Mage::getSingleton('admin/session')->isAllowed('cms/page'); + return $this->getAdminSession()->isAllowed('cms/page'); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php index 00abbb210b4..7480817537c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Cart/Product/Composite/CartController.php @@ -139,7 +139,7 @@ public function updateAction() } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); - Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult); + $this->getAdminhtmlSession()->setCompositeProductResult($updateResult); $this->_redirect('*/catalog_product/showUpdateResult'); return $this; diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php index 47d6167e0cc..a20fa3fa8e5 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php @@ -122,12 +122,12 @@ public function saveAction() } $customerGroup->setTaxClassId($taxClass)->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('The customer group has been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('customer')->__('The customer group has been saved.')); $this->getResponse()->setRedirect($this->getUrl('*/customer_group')); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setCustomerGroupData($customerGroup->getData()); + $this->getAdminhtmlSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->setCustomerGroupData($customerGroup->getData()); $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', ['id' => $id])); return; } @@ -146,11 +146,11 @@ public function deleteAction() try { $customerGroup->load($id); $customerGroup->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('The customer group has been deleted.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('customer')->__('The customer group has been deleted.')); $this->getResponse()->setRedirect($this->getUrl('*/customer_group')); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', ['id' => $id])); return; } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php index 08d3bb739f3..41557d81020 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Wishlist/Product/Composite/WishlistController.php @@ -124,7 +124,7 @@ public function updateAction() $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); - Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult); + $this->getAdminhtmlSession()->setCompositeProductResult($updateResult); $this->_redirect('*/catalog_product/showUpdateResult'); return false; diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php index 7e6e7b9d216..0564d8b2dc0 100644 --- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php @@ -111,7 +111,7 @@ public function editAction() $customer = Mage::registry('current_customer'); // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getCustomerData(true); + $data = $this->getAdminhtmlSession()->getCustomerData(true); // restore data from SESSION if ($data) { @@ -180,9 +180,9 @@ public function deleteAction() try { $customer->load($customer->getId()); $customer->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The customer has been deleted.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('The customer has been deleted.')); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } $this->_redirect('*/customer'); @@ -314,7 +314,7 @@ public function saveAction() } } - if (Mage::getSingleton('admin/session')->isAllowed('newsletter/subscriber') + if ($this->getAdminSession()->isAllowed('newsletter/subscriber') && !$customer->getConfirmation() ) { $customer->setIsSubscribed(isset($data['subscription'])); @@ -374,7 +374,7 @@ public function saveAction() $customer->sendPasswordLinkEmail($isNewCustomer); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('The customer has been saved.'), ); Mage::dispatchEvent('adminhtml_customer_save_after', [ @@ -676,7 +676,7 @@ public function validateAction() } if ($response->getError()) { - $this->_initLayoutMessages('adminhtml/session'); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } @@ -687,7 +687,7 @@ public function massSubscribeAction() { $customersIds = $this->getRequest()->getParam('customer'); if (!is_array($customersIds)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); } else { try { foreach ($customersIds as $customerId) { @@ -697,11 +697,11 @@ public function massSubscribeAction() // phpcs:ignore Ecg.Performance.Loop.ModelLSD $customer->save(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) were updated.', count($customersIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } $this->_redirect('*/*/index'); @@ -711,7 +711,7 @@ public function massUnsubscribeAction() { $customersIds = $this->getRequest()->getParam('customer'); if (!is_array($customersIds)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); } else { try { foreach ($customersIds as $customerId) { @@ -721,11 +721,11 @@ public function massUnsubscribeAction() // phpcs:ignore Ecg.Performance.Loop.ModelLSD $customer->save(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) were updated.', count($customersIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } @@ -736,7 +736,7 @@ public function massDeleteAction() { $customersIds = $this->getRequest()->getParam('customer'); if (!is_array($customersIds)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); } else { try { $customer = Mage::getModel('customer/customer'); @@ -747,11 +747,11 @@ public function massDeleteAction() // phpcs:ignore Ecg.Performance.Loop.ModelLSD ->delete(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) were deleted.', count($customersIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } @@ -762,7 +762,7 @@ public function massAssignGroupAction() { $customersIds = $this->getRequest()->getParam('customer'); if (!is_array($customersIds)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Please select customer(s).')); } else { try { foreach ($customersIds as $customerId) { @@ -772,11 +772,11 @@ public function massAssignGroupAction() // phpcs:ignore Ecg.Performance.Loop.ModelLSD $customer->save(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) were updated.', count($customersIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/IndexController.php b/app/code/core/Mage/Adminhtml/controllers/IndexController.php index 121305613f8..7e121ef5283 100644 --- a/app/code/core/Mage/Adminhtml/controllers/IndexController.php +++ b/app/code/core/Mage/Adminhtml/controllers/IndexController.php @@ -30,7 +30,7 @@ class Mage_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action */ protected function _outTemplate($tplName, $data = []) { - $this->_initLayoutMessages('adminhtml/session'); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $block = $this->getLayout()->createBlock('adminhtml/template')->setTemplate("$tplName.phtml"); foreach ($data as $index => $value) { $block->assign($index, $value); @@ -46,7 +46,7 @@ protected function _outTemplate($tplName, $data = []) */ public function indexAction() { - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); $url = $session->getUser()->getStartupPageUrl(); if ($session->isFirstPageAfterLogin()) { // retain the "first page after login" value in session (before redirect) @@ -60,7 +60,7 @@ public function indexAction() */ public function loginAction() { - if (Mage::getSingleton('admin/session')->isLoggedIn()) { + if ($this->getAdminSession()->isLoggedIn()) { $this->_redirect('*'); return; } @@ -76,8 +76,7 @@ public function loginAction() */ public function logoutAction() { - /** @var Mage_Admin_Model_Session $adminSession */ - $adminSession = Mage::getSingleton('admin/session'); + $adminSession = $this->getAdminSession(); $adminSession->unsetAll(); $adminSession->getCookie()->delete($adminSession->getSessionName()); $adminSession->addSuccess(Mage::helper('adminhtml')->__('You have logged out.')); @@ -93,7 +92,7 @@ public function globalSearchAction() $searchModules = Mage::getConfig()->getNode('adminhtml/global_search'); $items = []; - if (!Mage::getStoreConfigFlag('admin/global_search/enable') || !Mage::getSingleton('admin/session')->isAllowed('admin/global_search')) { + if (!Mage::getStoreConfigFlag('admin/global_search/enable') || !$this->getAdminSession()->isAllowed('admin/global_search')) { $items[] = [ 'id' => 'error', 'type' => Mage::helper('adminhtml')->__('Error'), @@ -115,7 +114,7 @@ public function globalSearchAction() $limit = $this->getRequest()->getParam('limit', 10); $query = $this->getRequest()->getParam('query', ''); foreach ($searchModules->children() as $searchConfig) { - if ($searchConfig->acl && !Mage::getSingleton('admin/session')->isAllowed($searchConfig->acl)) { + if ($searchConfig->acl && !$this->getAdminSession()->isAllowed($searchConfig->acl)) { continue; } @@ -166,7 +165,7 @@ public function changeLocaleAction() { $locale = $this->getRequest()->getParam('locale'); if ($locale) { - Mage::getSingleton('adminhtml/session')->setLocale($locale); + $this->getAdminhtmlSession()->setLocale($locale); } $this->_redirectReferer(); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php index caefd6df9b3..ab879938c0b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/ProblemController.php @@ -38,7 +38,7 @@ public function indexAction() } $this->getLayout()->getMessagesBlock()->setMessages( - Mage::getSingleton('adminhtml/session')->getMessages(true), + $this->getAdminhtmlSession()->getMessages(true), ); $this->loadLayout(); @@ -70,7 +70,7 @@ public function gridAction() $collection->walk('unsubscribe'); } - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addSuccess(Mage::helper('newsletter')->__('Selected problem subscribers have been unsubscribed.')); } @@ -87,10 +87,10 @@ public function gridAction() $collection->walk('delete'); } - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addSuccess(Mage::helper('newsletter')->__('Selected problems have been deleted.')); } - $this->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('adminhtml/session')->getMessages(true)); + $this->getLayout()->getMessagesBlock()->setMessages($this->getAdminhtmlSession()->getMessages(true)); $grid = $this->getLayout()->createBlock('adminhtml/newsletter_problem_grid'); $this->getResponse()->setBody($grid->toHtml()); diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php index 60fc647a0c6..45634f32682 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/SubscriberController.php @@ -102,18 +102,18 @@ public function massUnsubscribeAction() { $subscribersIds = $this->getRequest()->getParam('subscriber'); if (!is_array($subscribersIds)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('newsletter')->__('Please select subscriber(s)')); + $this->getAdminhtmlSession()->addError(Mage::helper('newsletter')->__('Please select subscriber(s)')); } else { try { foreach ($subscribersIds as $subscriberId) { $subscriber = Mage::getModel('newsletter/subscriber')->load($subscriberId); $subscriber->unsubscribe(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) were updated', count($subscribersIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } @@ -124,18 +124,18 @@ public function massDeleteAction() { $subscribersIds = $this->getRequest()->getParam('subscriber'); if (!is_array($subscribersIds)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('newsletter')->__('Please select subscriber(s)')); + $this->getAdminhtmlSession()->addError(Mage::helper('newsletter')->__('Please select subscriber(s)')); } else { try { foreach ($subscribersIds as $subscriberId) { $subscriber = Mage::getModel('newsletter/subscriber')->load($subscriberId); $subscriber->delete(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('Total of %d record(s) were deleted', count($subscribersIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php index 1556793705d..f0574ac37c1 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Newsletter/TemplateController.php @@ -28,8 +28,7 @@ class Mage_Adminhtml_Newsletter_TemplateController extends Mage_Adminhtml_Contro */ protected function _isAllowed() { - return Mage::getSingleton('admin/session') - ->isAllowed('newsletter/template'); + return $this->getAdminSession()->isAllowed('newsletter/template'); } /** diff --git a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php index 8da12e14ff4..60c86885081 100644 --- a/app/code/core/Mage/Adminhtml/controllers/NotificationController.php +++ b/app/code/core/Mage/Adminhtml/controllers/NotificationController.php @@ -36,7 +36,7 @@ public function indexAction() public function markAsReadAction() { if ($id = $this->getRequest()->getParam('id')) { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $model = Mage::getModel('adminnotification/inbox') ->load($id); @@ -64,7 +64,7 @@ public function markAsReadAction() public function massMarkAsReadAction() { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $ids = $this->getRequest()->getParam('notification'); if (!is_array($ids)) { $session->addError(Mage::helper('adminnotification')->__('Please select messages.')); @@ -93,7 +93,7 @@ public function massMarkAsReadAction() public function removeAction() { if ($id = $this->getRequest()->getParam('id')) { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $model = Mage::getModel('adminnotification/inbox') ->load($id); @@ -120,7 +120,7 @@ public function removeAction() public function massRemoveAction() { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $ids = $this->getRequest()->getParam('notification'); if (!is_array($ids)) { $session->addError(Mage::helper('adminnotification')->__('Please select messages.')); @@ -166,6 +166,6 @@ protected function _isAllowed() default: $acl = 'system/adminnotification/show_list'; } - return Mage::getSingleton('admin/session')->isAllowed($acl); + return $this->getAdminSession()->isAllowed($acl); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/BlockController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/BlockController.php index 1a311d0c98d..00d123faa8d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/BlockController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/BlockController.php @@ -80,7 +80,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This block no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This block no longer exists.')); $this->_redirect('*/*/'); return; } @@ -89,7 +89,7 @@ public function editAction() $this->_title($model->getId() ? $model->getBlockName() : $this->__('New Block')); // Restore previously entered form data from session - $data = Mage::getSingleton('adminhtml/session')->getUserData(true); + $data = $this->getAdminhtmlSession()->getUserData(true); if (!empty($data)) { $model->setData($data); } @@ -121,7 +121,7 @@ public function saveAction() $id = (int) $this->getRequest()->getParam('block_id'); $model = Mage::getModel('admin/block')->load($id); if (!$model->getId() && $id) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This block no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This block no longer exists.')); $this->_redirect('*/*/'); return; } @@ -133,26 +133,26 @@ public function saveAction() $result = $model->validate(); if (is_array($result)) { - Mage::getSingleton('adminhtml/session')->setUserData($data); + $this->getAdminhtmlSession()->setUserData($data); foreach ($result as $message) { - Mage::getSingleton('adminhtml/session')->addError($message); + $this->getAdminhtmlSession()->addError($message); } $this->_redirect('*/*/edit', ['block_id' => $id]); return $this; } try { $model->save(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The block has been saved.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The block has been saved.')); // clear previously saved data from session - Mage::getSingleton('adminhtml/session')->setFormData(false); + $this->getAdminhtmlSession()->setFormData(false); $this->_redirect('*/*/'); return; } catch (Exception $e) { // display error message - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); // save data in session - Mage::getSingleton('adminhtml/session')->setFormData($data); + $this->getAdminhtmlSession()->setFormData($data); // redirect to edit form $this->_redirect('*/*/edit', ['block_id' => $id]); return; @@ -172,16 +172,16 @@ public function deleteAction() $model = Mage::getModel('admin/block'); $model->setId($id); $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Block has been deleted.')); + $this->getAdminhtmlSession()->addSuccess($this->__('Block has been deleted.')); $this->_redirect('*/*/'); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', ['block_id' => $id]); return; } } - Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find a block to delete.')); + $this->getAdminhtmlSession()->addError($this->__('Unable to find a block to delete.')); $this->_redirect('*/*/'); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php index ba5dea8076b..b5b94edb238 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/RoleController.php @@ -138,7 +138,7 @@ public function deleteAction() { $role = $this->_initRole('role_id'); if (!$role->getId()) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This Role no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This Role no longer exists.')); $this->_redirect('*/*/'); return; } @@ -156,20 +156,20 @@ public function deleteAction() return; } - $currentUser = Mage::getModel('admin/user')->setId(Mage::getSingleton('admin/session')->getUser()->getId()); + $currentUser = Mage::getModel('admin/user')->setId($this->getAdminSession()->getUser()->getId()); if (in_array($role->getId(), $currentUser->getRoles())) { - Mage::getSingleton('adminhtml/session')->addError($this->__('Self-assigned roles cannot be deleted.')); + $this->getAdminhtmlSession()->addError($this->__('Self-assigned roles cannot be deleted.')); $this->_redirect('*/*/editrole', ['rid' => $role->getId()]); return; } try { $role->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The role has been deleted.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The role has been deleted.')); } catch (Exception $e) { Mage::logException($e); - Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while deleting this role.')); + $this->getAdminhtmlSession()->addError($this->__('An error occurred while deleting this role.')); } $this->_redirect('*/*/'); @@ -197,7 +197,7 @@ public function saveRoleAction() $role = $this->_initRole('role_id'); if (!$role->getId() && $rid) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This Role no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This Role no longer exists.')); $this->_redirect('*/*/'); return; } @@ -240,12 +240,12 @@ public function saveRoleAction() $this->_addUserToRole($nRuid, $role->getId()); } - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The role has been successfully saved.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The role has been successfully saved.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { Mage::logException($e); - Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this role.')); + $this->getAdminhtmlSession()->addError($this->__('An error occurred while saving this role.')); } $this->_redirect('*/*/'); @@ -335,12 +335,12 @@ public function refreshRolesAction() $user->getResource()->saveReloadAclFlag($user, 1); } - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The roles have been refreshed.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The roles have been refreshed.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { Mage::logException($e); - Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while refreshing roles.')); + $this->getAdminhtmlSession()->addError($this->__('An error occurred while refreshing roles.')); } $this->_redirect('*/*/'); diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php index 85ede974f4d..6e87549e51c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php @@ -76,7 +76,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This user no longer exists.')); $this->_redirect('*/*/'); return; } @@ -85,7 +85,7 @@ public function editAction() $this->_title($model->getId() ? $model->getName() : $this->__('New User')); // Restore previously entered form data from session - $data = Mage::getSingleton('adminhtml/session')->getUserData(true); + $data = $this->getAdminhtmlSession()->getUserData(true); if (!empty($data)) { $model->setData($data); } @@ -106,6 +106,11 @@ public function editAction() $this->renderLayout(); } + /** + * @return $this|void + * @throws Throwable + * @throws Zend_Validate_Exception + */ public function saveAction() { if ($data = $this->getRequest()->getPost()) { @@ -114,7 +119,7 @@ public function saveAction() // @var $isNew flag for detecting new admin user creation. $isNew = !$model->getId() ? true : false; if (!$model->getId() && $id) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This user no longer exists.')); $this->_redirect('*/*/'); return; } @@ -141,9 +146,9 @@ public function saveAction() $result = $model->validate(); } if (is_array($result)) { - Mage::getSingleton('adminhtml/session')->setUserData($data); + $this->getAdminhtmlSession()->setUserData($data); foreach ($result as $message) { - Mage::getSingleton('adminhtml/session')->addError($message); + $this->getAdminhtmlSession()->addError($message); } $this->_redirect('*/*/edit', ['_current' => true]); return $this; @@ -163,13 +168,13 @@ public function saveAction() ->saveRelations(); } } - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been saved.')); - Mage::getSingleton('adminhtml/session')->setUserData(false); + $this->getAdminhtmlSession()->addSuccess($this->__('The user has been saved.')); + $this->getAdminhtmlSession()->setUserData(false); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setUserData($data); + $this->getAdminhtmlSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->setUserData($data); $this->_redirect('*/*/edit', ['user_id' => $model->getUserId()]); return; } @@ -194,11 +199,11 @@ public function deleteAction() return; } - $currentUser = Mage::getSingleton('admin/session')->getUser(); + $currentUser = $this->getAdminSession()->getUser(); if ($id = $this->getRequest()->getParam('user_id')) { if ($currentUser->getId() == $id) { - Mage::getSingleton('adminhtml/session')->addError($this->__('You cannot delete your own account.')); + $this->getAdminhtmlSession()->addError($this->__('You cannot delete your own account.')); $this->_redirect('*/*/edit', ['user_id' => $id]); return; } @@ -206,16 +211,16 @@ public function deleteAction() $model = Mage::getModel('admin/user'); $model->setId($id); $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been deleted.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The user has been deleted.')); $this->_redirect('*/*/'); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', ['user_id' => $this->getRequest()->getParam('user_id')]); return; } } - Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find a user to delete.')); + $this->getAdminhtmlSession()->addError($this->__('Unable to find a user to delete.')); $this->_redirect('*/*/'); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Permissions/VariableController.php b/app/code/core/Mage/Adminhtml/controllers/Permissions/VariableController.php index 140136408b5..41b005e8554 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Permissions/VariableController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Permissions/VariableController.php @@ -79,7 +79,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This variable no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This variable no longer exists.')); $this->_redirect('*/*/'); return; } @@ -88,7 +88,7 @@ public function editAction() $this->_title($model->getId() ? $model->getVariableName() : $this->__('New Variable')); // Restore previously entered form data from session - $data = Mage::getSingleton('adminhtml/session')->getUserData(true); + $data = $this->getAdminhtmlSession()->getUserData(true); if (!empty($data)) { $model->setData($data); } @@ -120,7 +120,7 @@ public function saveAction() $id = (int) $this->getRequest()->getParam('variable_id'); $model = Mage::getModel('admin/variable')->load($id); if (!$model->getId() && $id) { - Mage::getSingleton('adminhtml/session')->addError($this->__('This variable no longer exists.')); + $this->getAdminhtmlSession()->addError($this->__('This variable no longer exists.')); $this->_redirect('*/*/'); return; } @@ -132,26 +132,26 @@ public function saveAction() $result = $model->validate(); if (is_array($result)) { - Mage::getSingleton('adminhtml/session')->setUserData($data); + $this->getAdminhtmlSession()->setUserData($data); foreach ($result as $message) { - Mage::getSingleton('adminhtml/session')->addError($message); + $this->getAdminhtmlSession()->addError($message); } $this->_redirect('*/*/edit', ['variable_id' => $id]); return $this; } try { $model->save(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The variable has been saved.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The variable has been saved.')); // clear previously saved data from session - Mage::getSingleton('adminhtml/session')->setFormData(false); + $this->getAdminhtmlSession()->setFormData(false); $this->_redirect('*/*/'); return; } catch (Exception $e) { // display error message - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); // save data in session - Mage::getSingleton('adminhtml/session')->setFormData($data); + $this->getAdminhtmlSession()->setFormData($data); // redirect to edit form $this->_redirect('*/*/edit', ['variable_id' => $id]); return; @@ -171,16 +171,16 @@ public function deleteAction() $model = Mage::getModel('admin/variable'); $model->setId($id); $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Variable has been deleted.')); + $this->getAdminhtmlSession()->addSuccess($this->__('Variable has been deleted.')); $this->_redirect('*/*/'); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', ['variable_id' => $id]); return; } } - Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find a variable to delete.')); + $this->getAdminhtmlSession()->addError($this->__('Unable to find a variable to delete.')); $this->_redirect('*/*/'); } diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php index c27fe2c321d..8565107b597 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php @@ -63,7 +63,7 @@ public function indexAction() $dirtyRules = Mage::getModel('catalogrule/flag')->loadSelf(); if ($dirtyRules->getState()) { - Mage::getSingleton('adminhtml/session')->addNotice($this->getDirtyRulesNoticeMessage()); + $this->getAdminhtmlSession()->addNotice($this->getDirtyRulesNoticeMessage()); } $this->_initAction() @@ -89,7 +89,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getRuleId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalogrule')->__('This rule no longer exists.'), ); $this->_redirect('*/*'); @@ -100,7 +100,7 @@ public function editAction() $this->_title($model->getRuleId() ? $model->getName() : $this->__('New Rule')); // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getPageData(true); + $data = $this->getAdminhtmlSession()->getPageData(true); if (!empty($data)) { $model->addData($data); } @@ -159,14 +159,14 @@ public function saveAction() $model->loadPost($data); - Mage::getSingleton('adminhtml/session')->setPageData($model->getData()); + $this->getAdminhtmlSession()->setPageData($model->getData()); $model->save(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('catalogrule')->__('The rule has been saved.'), ); - Mage::getSingleton('adminhtml/session')->setPageData(false); + $this->getAdminhtmlSession()->setPageData(false); if ($autoApply) { $this->getRequest()->setParam('rule_id', $model->getId()); $this->_forward('applyRules'); @@ -182,13 +182,13 @@ public function saveAction() } return; } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - $this->_getSession()->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalogrule')->__('An error occurred while saving the rule data. Please review the log and try again.'), ); Mage::logException($e); - Mage::getSingleton('adminhtml/session')->setPageData($data); + $this->getAdminhtmlSession()->setPageData($data); $this->_redirect('*/*/edit', ['id' => $this->getRequest()->getParam('rule_id')]); return; } @@ -203,7 +203,7 @@ public function deleteAction() $model = Mage::getModel('catalogrule/rule'); $model->load($id); if (!$model->getRuleId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalogrule')->__('Unable to find a rule to delete.'), ); $this->_redirect('*/*/'); @@ -213,7 +213,7 @@ public function deleteAction() Mage::getModel('catalogrule/flag')->loadSelf() ->setState(1) ->save(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('catalogrule')->__('The rule has been deleted.'), ); $this->_redirect('*/*/'); @@ -229,7 +229,7 @@ public function deleteAction() return; } } - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalogrule')->__('Unable to find a rule to delete.'), ); $this->_redirect('*/*/'); diff --git a/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php b/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php index c13898a68a0..de5375b3ff4 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php @@ -84,7 +84,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getRuleId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('salesrule')->__('This rule no longer exists.'), ); $this->_redirect('*/*'); @@ -95,7 +95,7 @@ public function editAction() $this->_title($model->getRuleId() ? $model->getName() : $this->__('New Rule')); // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getPageData(true); + $data = $this->getAdminhtmlSession()->getPageData(true); if (!empty($data)) { $model->addData($data); } @@ -145,7 +145,7 @@ public function saveAction() } } - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $validateResult = $model->validateData(new Varien_Object($data)); if ($validateResult !== true) { @@ -199,7 +199,7 @@ public function saveAction() Mage::helper('catalogrule')->__('An error occurred while saving the rule data. Please review the log and try again.'), ); Mage::logException($e); - Mage::getSingleton('adminhtml/session')->setPageData($data); + $this->getAdminhtmlSession()->setPageData($data); $this->_redirect('*/*/edit', ['id' => $this->getRequest()->getParam('rule_id')]); return; } @@ -215,7 +215,7 @@ public function deleteAction() $model->load($id); if (!$model->getRuleId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalogrule')->__('Unable to find a rule to delete.'), ); $this->_redirect('*/*/'); @@ -223,15 +223,15 @@ public function deleteAction() } $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('salesrule')->__('The rule has been deleted.'), ); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - $this->_getSession()->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('catalogrule')->__('An error occurred while deleting the rule. Please review the log and try again.'), ); Mage::logException($e); @@ -239,7 +239,7 @@ public function deleteAction() return; } } - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('salesrule')->__('Unable to find a rule to delete.'), ); $this->_redirect('*/*/'); @@ -419,8 +419,8 @@ public function generateAction() $generator->setData($data); $generator->generatePool(); $generated = $generator->getGeneratedCount(); - $this->_getSession()->addSuccess(Mage::helper('salesrule')->__('%s Coupon(s) have been generated', $generated)); - $this->_initLayoutMessages('adminhtml/session'); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('salesrule')->__('%s Coupon(s) have been generated', $generated)); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $result['messages'] = $this->getLayout()->getMessagesBlock()->getGroupedHtml(); } } catch (Mage_Core_Exception $e) { diff --git a/app/code/core/Mage/Adminhtml/controllers/RatingController.php b/app/code/core/Mage/Adminhtml/controllers/RatingController.php index 1d1d8c628cb..29c57feab8d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/RatingController.php +++ b/app/code/core/Mage/Adminhtml/controllers/RatingController.php @@ -106,14 +106,14 @@ public function saveAction() } } - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The rating has been saved.')); - Mage::getSingleton('adminhtml/session')->setRatingData(false); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('The rating has been saved.')); + $this->getAdminhtmlSession()->setRatingData(false); $this->_redirect('*/*/'); return; } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setRatingData($this->getRequest()->getPost()); + $this->getAdminhtmlSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->setRatingData($this->getRequest()->getPost()); $this->_redirect('*/*/edit', ['id' => $this->getRequest()->getParam('id')]); return; } @@ -129,10 +129,10 @@ public function deleteAction() /** @var Mage_Rating_Model_Rating $model */ $model->load($this->getRequest()->getParam('id')) ->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The rating has been deleted.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('The rating has been deleted.')); $this->_redirect('*/*/'); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/*/edit', ['id' => $this->getRequest()->getParam('id')]); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php index a50a6635458..92d705bbfb7 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/CustomerController.php @@ -161,13 +161,13 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'accounts': - return Mage::getSingleton('admin/session')->isAllowed('report/customers/accounts'); + return $this->getAdminSession()->isAllowed('report/customers/accounts'); case 'orders': - return Mage::getSingleton('admin/session')->isAllowed('report/customers/orders'); + return $this->getAdminSession()->isAllowed('report/customers/orders'); case 'totals': - return Mage::getSingleton('admin/session')->isAllowed('report/customers/totals'); + return $this->getAdminSession()->isAllowed('report/customers/totals'); default: - return Mage::getSingleton('admin/session')->isAllowed('report/customers'); + return $this->getAdminSession()->isAllowed('report/customers'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php index 9fd41dc2462..556ced631e3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ProductController.php @@ -244,13 +244,13 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'viewed': - return Mage::getSingleton('admin/session')->isAllowed('report/products/viewed'); + return $this->getAdminSession()->isAllowed('report/products/viewed'); case 'sold': - return Mage::getSingleton('admin/session')->isAllowed('report/products/sold'); + return $this->getAdminSession()->isAllowed('report/products/sold'); case 'lowstock': - return Mage::getSingleton('admin/session')->isAllowed('report/products/lowstock'); + return $this->getAdminSession()->isAllowed('report/products/lowstock'); default: - return Mage::getSingleton('admin/session')->isAllowed('report/products'); + return $this->getAdminSession()->isAllowed('report/products'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php index ccd8a0522dd..37201c95122 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ReviewController.php @@ -156,11 +156,11 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'customer': - return Mage::getSingleton('admin/session')->isAllowed('report/review/customer'); + return $this->getAdminSession()->isAllowed('report/review/customer'); case 'product': - return Mage::getSingleton('admin/session')->isAllowed('report/review/product'); + return $this->getAdminSession()->isAllowed('report/review/product'); default: - return Mage::getSingleton('admin/session')->isAllowed('report/review'); + return $this->getAdminSession()->isAllowed('report/review'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php index 9dc39d599c0..b47e1fbee59 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/ShopcartController.php @@ -150,13 +150,13 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'customer': - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart/customer'); + return $this->getAdminSession()->isAllowed('report/shopcart/customer'); case 'product': - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart/product'); + return $this->getAdminSession()->isAllowed('report/shopcart/product'); case 'abandoned': - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart/abandoned'); + return $this->getAdminSession()->isAllowed('report/shopcart/abandoned'); default: - return Mage::getSingleton('admin/session')->isAllowed('report/shopcart'); + return $this->getAdminSession()->isAllowed('report/shopcart'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php b/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php index 6115444fdb9..7fca86c5e8d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/StatisticsController.php @@ -125,11 +125,11 @@ public function refreshRecentAction() foreach ($collectionsNames as $collectionName) { Mage::getResourceModel($collectionName)->aggregate($date); } - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Recent statistics have been updated.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('Recent statistics have been updated.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to refresh recent statistics.')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Unable to refresh recent statistics.')); Mage::logException($e); } @@ -153,11 +153,11 @@ public function refreshLifetimeAction() foreach ($collectionsNames as $collectionName) { Mage::getResourceModel($collectionName)->aggregate(); } - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Lifetime statistics have been updated.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('Lifetime statistics have been updated.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to refresh lifetime statistics.')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Unable to refresh lifetime statistics.')); Mage::logException($e); } @@ -188,7 +188,7 @@ public function indexAction() protected function _getSession() { if (is_null($this->_adminSession)) { - $this->_adminSession = Mage::getSingleton('admin/session'); + $this->_adminSession = $this->getAdminSession(); } return $this->_adminSession; } diff --git a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php index 887c6d0c15c..088cb0e60ad 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Report/TagController.php @@ -277,14 +277,14 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'customer': - return Mage::getSingleton('admin/session')->isAllowed('report/tags/customer'); + return $this->getAdminSession()->isAllowed('report/tags/customer'); case 'productall': case 'product': - return Mage::getSingleton('admin/session')->isAllowed('report/tags/product'); + return $this->getAdminSession()->isAllowed('report/tags/product'); case 'popular': - return Mage::getSingleton('admin/session')->isAllowed('report/tags/popular'); + return $this->getAdminSession()->isAllowed('report/tags/popular'); default: - return Mage::getSingleton('admin/session')->isAllowed('report/tags'); + return $this->getAdminSession()->isAllowed('report/tags'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/ReportController.php b/app/code/core/Mage/Adminhtml/controllers/ReportController.php index 114ff416bdc..d59ae9cc00e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/ReportController.php +++ b/app/code/core/Mage/Adminhtml/controllers/ReportController.php @@ -74,9 +74,9 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'search': - return Mage::getSingleton('admin/session')->isAllowed('report/search'); + return $this->getAdminSession()->isAllowed('report/search'); default: - return Mage::getSingleton('admin/session')->isAllowed('report'); + return $this->getAdminSession()->isAllowed('report'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php b/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php index 78575a3dfb1..b337da2a2f0 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Rss/CatalogController.php @@ -34,7 +34,7 @@ protected function _isAllowed() } elseif ($action == 'notifystock') { $path = 'catalog/products'; } - return Mage::getSingleton('admin/session')->isAllowed($path); + return $this->getAdminSession()->isAllowed($path); } public function notifystockAction() diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php index 2d2f3f4e91c..d4bb973fd22 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Billing/AgreementController.php @@ -180,10 +180,12 @@ protected function _initCustomer() * Retrieve adminhtml session * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ protected function _getSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } /** @@ -196,12 +198,12 @@ protected function _isAllowed() case 'index': case 'grid': case 'view': - return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/view'); + return $this->getAdminSession()->isAllowed('sales/billing_agreement/actions/view'); case 'cancel': case 'delete': - return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/manage'); + return $this->getAdminSession()->isAllowed('sales/billing_agreement/actions/manage'); default: - return Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement'); + return $this->getAdminSession()->isAllowed('sales/billing_agreement'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php index c84fd6cad5e..cde421ebfc4 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreateController.php @@ -413,7 +413,7 @@ public function loadBlockAction() $this->loadLayoutUpdates()->generateLayoutXml()->generateLayoutBlocks(); $result = $this->getLayout()->getBlock('content')->toHtml(); if ($request->getParam('as_js_varname')) { - Mage::getSingleton('adminhtml/session')->setUpdateResult($result); + $this->getAdminhtmlSession()->setUpdateResult($result); $this->_redirect('*/*/showUpdateResult'); } else { $this->getResponse()->setBody($result); @@ -444,7 +444,7 @@ public function addConfiguredAction() } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); - Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult); + $this->getAdminhtmlSession()->setCompositeProductResult($updateResult); $this->_redirect('*/catalog_product/showUpdateResult'); } @@ -504,8 +504,8 @@ public function saveAction() ->createOrder(); $this->_getSession()->clear(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The order has been created.')); - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { + $this->getAdminhtmlSession()->addSuccess($this->__('The order has been created.')); + if ($this->getAdminSession()->isAllowed('sales/order/actions/view')) { $this->_redirect('*/sales_order/view', ['order_id' => $order->getId()]); } else { $this->_redirect('*/sales_order/index'); @@ -534,7 +534,7 @@ public function saveAction() */ protected function _isAllowed() { - return Mage::getSingleton('admin/session')->isAllowed($this->_getAclResourse()); + return $this->getAdminSession()->isAllowed($this->_getAclResourse()); } /** @@ -641,7 +641,7 @@ public function configureQuoteItemsAction() */ public function showUpdateResultAction() { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if ($session->hasUpdateResult() && is_scalar($session->getUpdateResult())) { $this->getResponse()->setBody($session->getUpdateResult()); $session->unsUpdateResult(); diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php index 78a5b89b17b..f9e4fc80f36 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/CreditmemoController.php @@ -29,7 +29,7 @@ protected function _getItemData() { $data = $this->getRequest()->getParam('creditmemo'); if (!$data) { - $data = Mage::getSingleton('adminhtml/session')->getFormData(true); + $data = $this->getAdminhtmlSession()->getFormData(true); } return $data['items'] ?? []; } @@ -216,7 +216,7 @@ public function newAction() $this->_title($this->__('New Memo')); } - if ($comment = Mage::getSingleton('adminhtml/session')->getCommentText(true)) { + if ($comment = $this->getAdminhtmlSession()->getCommentText(true)) { $creditmemo->setCommentText($comment); } @@ -261,7 +261,7 @@ public function saveAction() { $data = $this->getRequest()->getPost('creditmemo'); if (!empty($data['comment_text'])) { - Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']); + $this->getAdminhtmlSession()->setCommentText($data['comment_text']); } try { @@ -301,7 +301,7 @@ public function saveAction() $this->_saveCreditmemo($creditmemo); $creditmemo->sendEmail(!empty($data['send_email']), $comment); $this->_getSession()->addSuccess($this->__('The credit memo has been created.')); - Mage::getSingleton('adminhtml/session')->getCommentText(true); + $this->getAdminhtmlSession()->getCommentText(true); $this->_redirect('*/sales_order/view', ['order_id' => $creditmemo->getOrderId()]); return; } else { @@ -310,7 +310,7 @@ public function saveAction() } } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setFormData($data); + $this->getAdminhtmlSession()->setFormData($data); } catch (Exception $e) { Mage::logException($e); $this->_getSession()->addError($this->__('Cannot save the credit memo.')); diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php index decb557da1c..56bb532771a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php @@ -53,10 +53,10 @@ public function startAction() $this->_getOrderCreateModel()->initFromOrder($order); $this->_redirect('*/*'); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_redirect('*/sales_order/view', ['order_id' => $orderId]); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addException($e, $e->getMessage()); + $this->getAdminhtmlSession()->addException($e, $e->getMessage()); $this->_redirect('*/sales_order/view', ['order_id' => $orderId]); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php index 8b7dc0b97c4..923b95fc257 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php @@ -166,7 +166,7 @@ public function newAction() if ($invoice) { $this->_title($this->__('New Invoice')); - if ($comment = Mage::getSingleton('adminhtml/session')->getCommentText(true)) { + if ($comment = $this->getAdminhtmlSession()->getCommentText(true)) { $invoice->setCommentText($comment); } @@ -218,7 +218,7 @@ public function saveAction() $orderId = $this->getRequest()->getParam('order_id'); if (!empty($data['comment_text'])) { - Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']); + $this->getAdminhtmlSession()->setCommentText($data['comment_text']); } try { @@ -285,7 +285,7 @@ public function saveAction() $this->_getSession()->addError($this->__('Unable to send the shipment email.')); } } - Mage::getSingleton('adminhtml/session')->getCommentText(true); + $this->getAdminhtmlSession()->getCommentText(true); $this->_redirect('*/sales_order/view', ['order_id' => $orderId]); } else { $this->_redirect('*/*/new', ['order_id' => $orderId]); diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php index 9bad471b905..426c8fb0970 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php @@ -153,7 +153,7 @@ public function newAction() if ($shipment = $this->_initShipment()) { $this->_title($this->__('New Shipment')); - $comment = Mage::getSingleton('adminhtml/session')->getCommentText(true); + $comment = $this->getAdminhtmlSession()->getCommentText(true); if ($comment) { $shipment->setCommentText($comment); } @@ -174,7 +174,7 @@ public function saveAction() { $data = $this->getRequest()->getPost('shipment'); if (!empty($data['comment_text'])) { - Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']); + $this->getAdminhtmlSession()->setCommentText($data['comment_text']); } $shipment = $this->_initShipment(); @@ -217,9 +217,9 @@ public function saveAction() $shipmentCreatedMessage = $this->__('The shipment has been created.'); $labelCreatedMessage = $this->__('The shipping label has been created.'); - $this->_getSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage + $this->getAdminhtmlSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage); - Mage::getSingleton('adminhtml/session')->getCommentText(true); + $this->getAdminhtmlSession()->getCommentText(true); } catch (Mage_Core_Exception $e) { if ($isNeedCreateLabel) { $responseAjax->setError(true); diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php index 8c725343389..8e3f4832f34 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php @@ -684,7 +684,7 @@ protected function _isAllowed() $aclResource = 'sales/order'; break; } - return Mage::getSingleton('admin/session')->isAllowed($aclResource); + return $this->getAdminSession()->isAllowed($aclResource); } /** diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php index c80e92db326..a29cf6d658b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Sales/TransactionsController.php @@ -101,13 +101,13 @@ public function fetchAction() ->setOrder($txn->getOrder()) ->importTransactionInfo($txn); $txn->save(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('The transaction details have been updated.'), ); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('adminhtml')->__('Unable to update transaction details.'), ); Mage::logException($e); @@ -123,9 +123,9 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'fetch': - return Mage::getSingleton('admin/session')->isAllowed('sales/transactions/fetch'); + return $this->getAdminSession()->isAllowed('sales/transactions/fetch'); default: - return Mage::getSingleton('admin/session')->isAllowed('sales/transactions'); + return $this->getAdminSession()->isAllowed('sales/transactions'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/SitemapController.php b/app/code/core/Mage/Adminhtml/controllers/SitemapController.php index 472dd11c136..17e86008a2f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/SitemapController.php +++ b/app/code/core/Mage/Adminhtml/controllers/SitemapController.php @@ -102,7 +102,7 @@ public function editAction() if ($id) { $model->load($id); if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('sitemap')->__('This sitemap no longer exists.'), ); $this->_redirect('*/*/'); @@ -113,7 +113,7 @@ public function editAction() $this->_title($model->getId() ? $model->getSitemapFilename() : $this->__('New Sitemap')); // 3. Set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getFormData(true); + $data = $this->getAdminhtmlSession()->getFormData(true); if (!empty($data)) { $model->setData($data); } @@ -148,7 +148,7 @@ public function saveAction() // check filename length if (strlen($data['sitemap_filename']) > self::MAXIMUM_SITEMAP_NAME_LENGTH) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('sitemap')->__( 'Please enter a sitemap name with at most %s characters.', self::MAXIMUM_SITEMAP_NAME_LENGTH, @@ -166,10 +166,10 @@ public function saveAction() $validator->setPaths($helper->getSitemapValidPaths()); if (!$validator->isValid($path)) { foreach ($validator->getMessages() as $message) { - Mage::getSingleton('adminhtml/session')->addError($message); + $this->getAdminhtmlSession()->addError($message); } // save data in session - Mage::getSingleton('adminhtml/session')->setFormData($data); + $this->getAdminhtmlSession()->setFormData($data); // redirect to edit form $this->_redirect('*/*/edit', [ 'sitemap_id' => $this->getRequest()->getParam('sitemap_id')]); @@ -192,11 +192,11 @@ public function saveAction() // save the data $model->save(); // display success message - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('sitemap')->__('The sitemap has been saved.'), ); // clear previously saved data from session - Mage::getSingleton('adminhtml/session')->setFormData(false); + $this->getAdminhtmlSession()->setFormData(false); // check if 'Save and Continue' if ($this->getRequest()->getParam('back')) { @@ -213,9 +213,9 @@ public function saveAction() return; } catch (Exception $e) { // display error message - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); // save data in session - Mage::getSingleton('adminhtml/session')->setFormData($data); + $this->getAdminhtmlSession()->setFormData($data); // redirect to edit form $this->_redirect('*/*/edit', [ 'sitemap_id' => $this->getRequest()->getParam('sitemap_id')]); @@ -246,7 +246,7 @@ public function deleteAction() } $model->delete(); // display success message - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('sitemap')->__('The sitemap has been deleted.'), ); // go to grid @@ -254,14 +254,14 @@ public function deleteAction() return; } catch (Exception $e) { // display error message - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); // go back to edit form $this->_redirect('*/*/edit', ['sitemap_id' => $id]); return; } } // display error message - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('sitemap')->__('Unable to find a sitemap to delete.'), ); // go to grid diff --git a/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php b/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php index 75bf57e90ec..50b0a1cb22f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/AccountController.php @@ -43,7 +43,7 @@ public function indexAction() */ public function saveAction() { - $userId = Mage::getSingleton('admin/session')->getUser()->getId(); + $userId = $this->getAdminSession()->getUser()->getId(); $user = Mage::getModel('admin/user')->load($userId); $user->setId($userId) @@ -73,7 +73,7 @@ public function saveAction() } if (is_array($result)) { foreach ($result as $error) { - Mage::getSingleton('adminhtml/session')->addError($error); + $this->getAdminhtmlSession()->addError($error); } $this->getResponse()->setRedirect($this->getUrl('*/*/')); return; @@ -81,11 +81,11 @@ public function saveAction() try { $user->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The account has been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('The account has been saved.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('An error occurred while saving account.')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('An error occurred while saving account.')); } $this->getResponse()->setRedirect($this->getUrl('*/*/')); } diff --git a/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php b/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php index f5d2f4b8536..f4486d11848 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/CacheController.php @@ -32,10 +32,12 @@ class Mage_Adminhtml_System_CacheController extends Mage_Adminhtml_Controller_Ac * Retrieve session model * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ protected function _getSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } /** diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php index ff9c1c15c40..6647fe3f411 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php @@ -70,7 +70,7 @@ public function synchronizeAction() } $flag->setState(Mage_Core_Model_File_Storage_Flag::STATE_RUNNING)->save(); - Mage::getSingleton('admin/session')->setSyncProcessStopWatch(false); + $this->getAdminSession()->setSyncProcessStopWatch(false); $storage = ['type' => (int) $_REQUEST['storage']]; if (isset($_REQUEST['connection']) && !empty($_REQUEST['connection'])) { diff --git a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php index 95e3e98bb9c..533b5ff2000 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php @@ -131,7 +131,7 @@ public function editAction() */ public function saveAction() { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); /** @var Mage_Adminhtml_Model_Session $session */ $groups = $this->getRequest()->getPost('groups', []); @@ -277,7 +277,7 @@ public function exportTableratesAction() protected function _isSectionAllowed($section) { try { - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); $resourceLookup = "admin/system/config/{$section}"; if ($session->getData('acl') instanceof Mage_Admin_Model_Acl) { $resourceId = $session->getData('acl')->get($resourceLookup)->getResourceId(); @@ -306,7 +306,7 @@ protected function _isSectionAllowed($section) */ protected function _saveState($configState = []) { - $adminUser = Mage::getSingleton('admin/session')->getUser(); + $adminUser = $this->getAdminSession()->getUser(); if (is_array($configState)) { $extra = $adminUser->getExtra(); if (!is_array($extra)) { diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php b/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php index 7600ce7d1ec..e6813d60dbc 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Convert/GuiController.php @@ -82,7 +82,7 @@ public function editAction() $profile = Mage::registry('current_convert_profile'); // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getConvertProfileData(true); + $data = $this->getAdminhtmlSession()->getConvertProfileData(true); if (!empty($data)) { $profile->addData($data); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php b/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php index 1591a874d84..4beb3813a8e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Convert/ProfileController.php @@ -40,7 +40,7 @@ protected function _initProfile($idFieldName = 'id') if ($profileId) { $profile->load($profileId); if (!$profile->getId()) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( $this->__('The profile you are trying to save no longer exists'), ); $this->_redirect('*/*'); @@ -48,7 +48,7 @@ protected function _initProfile($idFieldName = 'id') } } - $profile->setAdminUserId(Mage::getSingleton('admin/session')->getUser()->getId()); + $profile->setAdminUserId($this->getAdminSession()->getUser()->getId()); Mage::register('current_convert_profile', $profile); return $this; @@ -114,7 +114,7 @@ public function editAction() $profile = Mage::registry('current_convert_profile'); // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getConvertProfileData(true); + $data = $this->getAdminhtmlSession()->getConvertProfileData(true); if (!empty($data)) { $profile->addData($data); @@ -154,11 +154,11 @@ public function deleteAction() if ($profile->getId()) { try { $profile->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('The profile has been deleted.'), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } $this->_redirect('*/*'); @@ -183,13 +183,13 @@ public function saveAction() try { $profile->save(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('The profile has been saved.'), ); } catch (Exception $e) { Mage::logException($e); - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setConvertProfileData($data); + $this->getAdminhtmlSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->setConvertProfileData($data); $this->getResponse()->setRedirect($this->getUrl('*/*/edit', ['id' => $profile->getId()])); return; } @@ -199,7 +199,7 @@ public function saveAction() $this->_redirect('*/*'); } } else { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( $this->__('Invalid POST data (please check post_max_size and upload_max_filesize settings in your php.ini file).'), ); $this->_redirect('*/*'); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php b/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php index e7db0e9aad7..5ffc8e8bc56 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php @@ -75,16 +75,16 @@ public function fetchRatesAction() $errors = $importModel->getMessages(); if (count($errors)) { foreach ($errors as $error) { - Mage::getSingleton('adminhtml/session')->addWarning($error); + $this->getAdminhtmlSession()->addWarning($error); } - Mage::getSingleton('adminhtml/session')->addWarning(Mage::helper('adminhtml')->__('All possible rates were fetched, please click on "Save" to apply')); + $this->getAdminhtmlSession()->addWarning(Mage::helper('adminhtml')->__('All possible rates were fetched, please click on "Save" to apply')); } else { - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('All rates were fetched, please click on "Save" to apply')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('All rates were fetched, please click on "Save" to apply')); } - Mage::getSingleton('adminhtml/session')->setRates($rates); + $this->getAdminhtmlSession()->setRates($rates); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } $this->_redirect('*/*/'); } @@ -99,15 +99,15 @@ public function saveRatesAction() $value = abs(Mage::getSingleton('core/locale')->getNumber($value)); $data[$currencyCode][$currencyTo] = $value; if ($value == 0) { - Mage::getSingleton('adminhtml/session')->addWarning(Mage::helper('adminhtml')->__('Invalid input data for %s => %s rate', $currencyCode, $currencyTo)); + $this->getAdminhtmlSession()->addWarning(Mage::helper('adminhtml')->__('Invalid input data for %s => %s rate', $currencyCode, $currencyTo)); } } } Mage::getModel('directory/currency')->saveRates($data); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('All valid rates have been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('All valid rates have been saved.')); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php index b120beff7c4..e1998289aea 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/DesignController.php @@ -103,9 +103,9 @@ public function saveAction() try { $design->save(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The design change has been saved.')); + $this->getAdminhtmlSession()->addSuccess($this->__('The design change has been saved.')); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addError($e->getMessage()) ->setDesignData($data); $this->_redirect('*/*/edit', ['id' => $design->getId()]); @@ -124,13 +124,13 @@ public function deleteAction() try { $design->delete(); - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addSuccess($this->__('The design change has been deleted.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addException($e, $this->__('Cannot delete the design change.')); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php b/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php index a0d7ac29b02..dc2890fbc44 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/Email/TemplateController.php @@ -116,7 +116,7 @@ public function saveAction() $template = $this->_initTemplate('id'); if (!$template->getId() && $id) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('adminhtml')->__('This Email template no longer exists.'), ); $this->_redirect('*/*/'); @@ -148,17 +148,17 @@ public function saveAction() } $template->save(); - Mage::getSingleton('adminhtml/session')->setFormData(false); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->setFormData(false); + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('The email template has been saved.'), ); $this->_redirect('*/*'); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->setData( + $this->getAdminhtmlSession()->setData( 'email_template_form_data', $this->getRequest()->getParams(), ); - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); $this->_forward('new'); } } @@ -172,7 +172,7 @@ public function deleteAction() if ($template->getId()) { try { $template->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('The email template has been deleted.'), ); $this->_redirect('*/*/'); @@ -188,7 +188,7 @@ public function deleteAction() return; } } - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('adminhtml')->__('Unable to find a Email Template to delete.'), ); $this->_redirect('*/*/'); diff --git a/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php b/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php index 921625e0b74..47a073c9578 100644 --- a/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php +++ b/app/code/core/Mage/Adminhtml/controllers/System/VariableController.php @@ -112,8 +112,8 @@ public function validateAction() $variable->addData($this->getRequest()->getPost('variable')); $result = $variable->validate(); if ($result !== true && is_string($result)) { - $this->_getSession()->addError($result); - $this->_initLayoutMessages('adminhtml/session'); + $this->getAdminhtmlSession()->addError($result); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } diff --git a/app/code/core/Mage/Adminhtml/controllers/SystemController.php b/app/code/core/Mage/Adminhtml/controllers/SystemController.php index 7af0d417ea8..0cc6512f99c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/SystemController.php +++ b/app/code/core/Mage/Adminhtml/controllers/SystemController.php @@ -40,7 +40,7 @@ public function setStoreAction() { $storeId = (int) $this->getRequest()->getParam('store'); if ($storeId) { - Mage::getSingleton('adminhtml/session')->setStoreId($storeId); + $this->getAdminhtmlSession()->setStoreId($storeId); } $this->_redirectReferer(); } diff --git a/app/code/core/Mage/Adminhtml/controllers/TagController.php b/app/code/core/Mage/Adminhtml/controllers/TagController.php index a39b5a0fcb3..15061db2175 100644 --- a/app/code/core/Mage/Adminhtml/controllers/TagController.php +++ b/app/code/core/Mage/Adminhtml/controllers/TagController.php @@ -116,12 +116,12 @@ public function editAction() } if (!($model = $this->_initTag())) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Wrong tag was specified.')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Wrong tag was specified.')); return $this->_redirect('*/*/index', ['store' => $this->getRequest()->getParam('store')]); } // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getTagData(true); + $data = $this->getAdminhtmlSession()->getTagData(true); if (!empty($data)) { $model->addData($data); } @@ -150,7 +150,7 @@ public function saveAction() $data['store'] = $postData['store_id']; if (!$model = $this->_initTag()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Wrong tag was specified.')); + $this->getAdminhtmlSession()->addError(Mage::helper('adminhtml')->__('Wrong tag was specified.')); return $this->_redirect('*/*/index', ['store' => $data['store']]); } @@ -166,8 +166,8 @@ public function saveAction() try { $model->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The tag has been saved.')); - Mage::getSingleton('adminhtml/session')->setTagData(false); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('adminhtml')->__('The tag has been saved.')); + $this->getAdminhtmlSession()->setTagData(false); if (($continue = $this->getRequest()->getParam('continue'))) { return $this->_redirect('*/tag/edit', ['tag_id' => $model->getId(), 'store' => $model->getStoreId(), 'ret' => $continue]); @@ -175,8 +175,8 @@ public function saveAction() return $this->_redirect('*/tag/' . $this->getRequest()->getParam('ret', 'index')); } } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setTagData($data); + $this->getAdminhtmlSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->setTagData($data); return $this->_redirect('*/*/edit', ['tag_id' => $model->getId(), 'store' => $model->getStoreId()]); } @@ -191,7 +191,7 @@ public function saveAction() public function deleteAction() { $model = $this->_initTag(); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); if ($model && $model->getId()) { try { @@ -277,18 +277,18 @@ public function massDeleteAction() { $tagIds = $this->getRequest()->getParam('tag'); if (!is_array($tagIds)) { - Mage::getSingleton('adminhtml/session')->addError($this->__('Please select tag(s).')); + $this->getAdminhtmlSession()->addError($this->__('Please select tag(s).')); } else { try { foreach ($tagIds as $tagId) { $tag = Mage::getModel('tag/tag')->load($tagId); $tag->delete(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( $this->__('Total of %d record(s) have been deleted.', count($tagIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } @@ -305,7 +305,7 @@ public function massStatusAction() $storeId = (int) $this->getRequest()->getParam('store', 0); if (!is_array($tagIds)) { // No products selected - Mage::getSingleton('adminhtml/session')->addError($this->__('Please select tag(s).')); + $this->getAdminhtmlSession()->addError($this->__('Please select tag(s).')); } else { try { foreach ($tagIds as $tagId) { @@ -314,11 +314,11 @@ public function massStatusAction() ->setStatus($this->getRequest()->getParam('status')); $tag->save(); } - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( $this->__('Total of %d record(s) have been updated.', count($tagIds)), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } } $ret = $this->getRequest()->getParam('ret') ? $this->getRequest()->getParam('ret') : 'index'; @@ -333,11 +333,11 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'pending': - return Mage::getSingleton('admin/session')->isAllowed('catalog/tag/pending'); + return $this->getAdminSession()->isAllowed('catalog/tag/pending'); case 'all': - return Mage::getSingleton('admin/session')->isAllowed('catalog/tag/all'); + return $this->getAdminSession()->isAllowed('catalog/tag/all'); default: - return Mage::getSingleton('admin/session')->isAllowed('catalog/tag'); + return $this->getAdminSession()->isAllowed('catalog/tag'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php index f352f2e6b7e..030984a8fad 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/CustomerController.php @@ -68,7 +68,7 @@ public function editAction() if ($classId) { $model->load($classId); if (!$model->getId() || $model->getClassType() != Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('This class no longer exists')); $this->_redirect('*/*/'); return; } @@ -76,7 +76,7 @@ public function editAction() $this->_title($model->getId() ? $model->getClassName() : $this->__('New Class')); - $data = Mage::getSingleton('adminhtml/session')->getClassData(true); + $data = $this->getAdminhtmlSession()->getClassData(true); if (!empty($data)) { $model->setData($data); } @@ -104,12 +104,12 @@ public function editAction() public function deleteAction() { $classId = $this->getRequest()->getParam('id'); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $classModel = Mage::getModel('tax/class') ->load($classId); if (!$classModel->getId() || $classModel->getClassType() != Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('This class no longer exists')); $this->_redirect('*/*/'); return; } diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php index f45fd350089..8bdabd68fde 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/Class/ProductController.php @@ -67,7 +67,7 @@ public function editAction() if ($classId) { $model->load($classId); if (!$model->getId() || $model->getClassType() != Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('tax')->__('This class no longer exists'), ); $this->_redirect('*/*/'); @@ -77,7 +77,7 @@ public function editAction() $this->_title($model->getId() ? $model->getClassName() : $this->__('New Class')); - $data = Mage::getSingleton('adminhtml/session')->getClassData(true); + $data = $this->getAdminhtmlSession()->getClassData(true); if (!empty($data)) { $model->setData($data); } @@ -103,7 +103,7 @@ public function editAction() public function deleteAction() { $classId = $this->getRequest()->getParam('id'); - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); $classModel = Mage::getModel('tax/class') ->load($classId); diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php index 266775128c7..4ccebfdcf14 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/ClassController.php @@ -36,21 +36,21 @@ public function saveAction() $classType = $model->getClassType(); $classUrl = '*/tax_class_' . strtolower($classType); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('tax')->__('The tax class has been saved.'), ); $this->_redirect($classUrl); return; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setClassData($postData); + $this->getAdminhtmlSession()->addError($e->getMessage()); + $this->getAdminhtmlSession()->setClassData($postData); $this->_redirectReferer(); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError( + $this->getAdminhtmlSession()->addError( Mage::helper('tax')->__('An error occurred while saving this tax class.'), ); - Mage::getSingleton('adminhtml/session')->setClassData($postData); + $this->getAdminhtmlSession()->setClassData($postData); $this->_redirectReferer(); } @@ -82,7 +82,7 @@ protected function _initAction() */ protected function _isAllowed() { - return Mage::getSingleton('admin/session')->isAllowed('sales/tax/classes_product') - || Mage::getSingleton('admin/session')->isAllowed('sales/tax/classes_customer'); + return $this->getAdminSession()->isAllowed('sales/tax/classes_product') + || $this->getAdminSession()->isAllowed('sales/tax/classes_customer'); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php index b8281621f67..d5767933c5f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/RateController.php @@ -57,7 +57,7 @@ public function addAction() $this->_title($this->__('New Rate')); - $rateModel->setData(Mage::getSingleton('adminhtml/session')->getFormData(true)); + $rateModel->setData($this->getAdminhtmlSession()->getFormData(true)); if ($rateModel->getZipIsRange() && !$rateModel->hasTaxPostcode()) { $rateModel->setTaxPostcode($rateModel->getZipFrom() . '-' . $rateModel->getZipTo()); @@ -99,14 +99,14 @@ public function saveAction() try { $rateModel->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tax')->__('The tax rate has been saved.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('tax')->__('The tax rate has been saved.')); $this->getResponse()->setRedirect($this->getUrl('*/*/')); return true; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->setFormData($ratePost); - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->setFormData($ratePost); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } $this->_redirectReferer(); @@ -126,7 +126,7 @@ public function editAction() $rateId = (int) $this->getRequest()->getParam('rate'); $rateModel = Mage::getSingleton('tax/calculation_rate')->load(null); - $rateModel->setData(Mage::getSingleton('adminhtml/session')->getFormData(true)); + $rateModel->setData($this->getAdminhtmlSession()->getFormData(true)); if ($rateModel->getId() != $rateId) { $rateModel->load($rateId); } @@ -169,13 +169,13 @@ public function deleteAction() try { $rateModel->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tax')->__('The tax rate has been deleted.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('tax')->__('The tax rate has been deleted.')); $this->getResponse()->setRedirect($this->getUrl('*/*/')); return true; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('An error occurred while deleting this rate.')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('An error occurred while deleting this rate.')); } if ($referer = $this->getRequest()->getServer('HTTP_REFERER')) { $this->getResponse()->setRedirect($referer); @@ -183,7 +183,7 @@ public function deleteAction() $this->getResponse()->setRedirect($this->getUrl('*/*/')); } } else { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('An error occurred while deleting this rate. Incorrect rate ID.')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('An error occurred while deleting this rate. Incorrect rate ID.')); $this->getResponse()->setRedirect($this->getUrl('*/*/')); } } @@ -256,14 +256,14 @@ public function importPostAction() try { $this->_importRates(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tax')->__('The tax rate has been imported.')); + $this->getAdminhtmlSession()->addSuccess(Mage::helper('tax')->__('The tax rate has been imported.')); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('Invalid file upload attempt')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('Invalid file upload attempt')); } } else { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('Invalid file upload attempt')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('Invalid file upload attempt')); } $this->_redirect('*/*/importExport'); } @@ -338,12 +338,12 @@ protected function _importRates() // phpcs:ignore Ecg.Performance.Loop.ArraySize if (count($csvFields) != count($v)) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('Invalid file upload attempt')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('Invalid file upload attempt')); } $country = Mage::getModel('directory/country')->loadByCode($v[1], 'iso2_code'); if (!$country->getId()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('One of the country has invalid code.')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('One of the country has invalid code.')); continue; } @@ -464,10 +464,10 @@ protected function _isAllowed() $action = strtolower($this->getRequest()->getActionName()); switch ($action) { case 'importexport': - return Mage::getSingleton('admin/session')->isAllowed('sales/tax/import_export'); + return $this->getAdminSession()->isAllowed('sales/tax/import_export'); case 'index': default: - return Mage::getSingleton('admin/session')->isAllowed('sales/tax/rates'); + return $this->getAdminSession()->isAllowed('sales/tax/rates'); } } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php b/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php index 8a1f57250d2..b267407783b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Tax/RuleController.php @@ -67,15 +67,15 @@ public function editAction() if ($taxRuleId) { $ruleModel->load($taxRuleId); if (!$ruleModel->getId()) { - Mage::getSingleton('adminhtml/session')->unsRuleData(); - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession()->unsRuleData(); + $this->getAdminhtmlSession() ->addError(Mage::helper('tax')->__('This rule no longer exists.')); $this->_redirect('*/*/'); return; } } - $data = Mage::getSingleton('adminhtml/session')->getRuleData(true); + $data = $this->getAdminhtmlSession()->getRuleData(true); if (!empty($data)) { $ruleModel->setData($data); } @@ -109,8 +109,7 @@ public function saveAction() $ruleModel->setData($postData); $ruleModel->setCalculateSubtotal($this->getRequest()->getParam('calculate_subtotal', 0)); - /** @var Mage_Adminhtml_Model_Session $session */ - $session = $this->_getSingletonModel('adminhtml/session'); + $session = $this->getAdminhtmlSession(); try { //Check if the rule already exists @@ -132,7 +131,7 @@ public function saveAction() $session->addError($this->_getHelperModel('tax')->__('An error occurred while saving this tax rule.')); } - $this->_getSingletonModel('adminhtml/session')->setRuleData($postData); + $this->getAdminhtmlSession()->setRuleData($postData); $this->_redirectReferer(); } @@ -150,8 +149,7 @@ protected function _isValidRuleRequest($ruleModel) $ruleModel->getTaxProductClass(), ); - /** @var Mage_Adminhtml_Model_Session $session */ - $session = $this->_getSingletonModel('adminhtml/session'); + $session = $this->getAdminhtmlSession(); //Remove the current one from the list $existingRules = array_diff($existingRules, [$ruleModel->getOrigData('code')]); @@ -176,7 +174,7 @@ public function deleteAction() $ruleModel = Mage::getSingleton('tax/calculation_rule') ->load($ruleId); if (!$ruleModel->getId()) { - Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This rule no longer exists')); + $this->getAdminhtmlSession()->addError(Mage::helper('tax')->__('This rule no longer exists')); $this->_redirect('*/*/'); return; } @@ -184,15 +182,15 @@ public function deleteAction() try { $ruleModel->delete(); - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addSuccess(Mage::helper('tax')->__('The tax rule has been deleted.')); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addError(Mage::helper('tax')->__('An error occurred while deleting this tax rule.')); } diff --git a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php index f95e56a47fe..8ffcd7c7aae 100644 --- a/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php +++ b/app/code/core/Mage/Adminhtml/controllers/UrlrewriteController.php @@ -119,7 +119,7 @@ public function saveAction() $this->_initRegistry(); if ($data = $this->getRequest()->getPost()) { - $session = Mage::getSingleton('adminhtml/session'); + $session = $this->getAdminhtmlSession(); try { // set basic urlrewrite data $model = Mage::registry('current_urlrewrite'); @@ -205,11 +205,11 @@ public function deleteAction() if (Mage::registry('current_urlrewrite')->getId()) { try { Mage::registry('current_urlrewrite')->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('adminhtml')->__('The URL Rewrite has been deleted.'), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addException($e, Mage::helper('adminhtml')->__('An error occurred while deleting URL Rewrite.')); $this->_redirect('*/*/edit/', ['id' => Mage::registry('current_urlrewrite')->getId()]); return; diff --git a/app/code/core/Mage/Api/Model/Resource/Abstract.php b/app/code/core/Mage/Api/Model/Resource/Abstract.php index b49baf9ba57..6fc3c76f5bc 100644 --- a/app/code/core/Mage/Api/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Api/Model/Resource/Abstract.php @@ -22,6 +22,8 @@ */ class Mage_Api_Model_Resource_Abstract { + use Mage_Core_Trait_Session; + /** * Resource configuration * @@ -33,10 +35,12 @@ class Mage_Api_Model_Resource_Abstract * Retrieve webservice session * * @return Mage_Api_Model_Session + * @deprecated + * @see getApiSession() */ protected function _getSession() { - return Mage::getSingleton('api/session'); + return $this->getApiSession(); } /** diff --git a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php index faa42fb42f0..dde53c8e29c 100644 --- a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php +++ b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Api_Model_Server_Handler_Abstract { + use Mage_Core_Trait_Session; + protected $_resourceSuffix = null; public function __construct() @@ -49,10 +51,12 @@ public function handlePhpError($errorCode, $errorMessage, $errorFile, $errLine) * Retrieve webservice session * * @return Mage_Api_Model_Session + * @deprecated + * @see getApiSession() */ protected function _getSession() { - return Mage::getSingleton('api/session'); + return $this->getApiSession(); } /** diff --git a/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php b/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php index e2a7d3ebeaa..c6cc51ea466 100644 --- a/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php +++ b/app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php @@ -88,8 +88,7 @@ public function _prepareLayout() */ public function getRowUrl($row) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); if ($session->isAllowed('system/api/attributes/edit')) { return $this->getUrl('*/*/edit', ['type' => $row->getUserTypeCode()]); } diff --git a/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php b/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php index d540d55b85e..03169a1b5cf 100644 --- a/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php +++ b/app/code/core/Mage/Api2/Block/Adminhtml/Roles.php @@ -31,8 +31,7 @@ public function __construct() $this->_headerText = Mage::helper('adminhtml')->__('REST Roles'); //check allow edit - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); if ($session->isAllowed('system/api/roles/add')) { $this->_updateButton('add', 'label', $this->__('Add Admin Role')); } else { diff --git a/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php b/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php index 066dbe592e3..a0513df314f 100644 --- a/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php +++ b/app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php @@ -97,8 +97,7 @@ public function getGridUrl() */ public function getRowUrl($row) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); if ($session->isAllowed('system/api/roles/edit')) { return $this->getUrl('*/*/edit', ['id' => $row->getId()]); diff --git a/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php b/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php index be43c8afcb9..efc8c6b44a9 100644 --- a/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php +++ b/app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php @@ -290,8 +290,7 @@ public function deleteAction() */ protected function _isAllowed() { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); return $session->isAllowed('system/api/rest_roles'); } diff --git a/app/code/core/Mage/Authorizenet/Helper/Data.php b/app/code/core/Mage/Authorizenet/Helper/Data.php index 7f2ad4d45a1..1463b898eb0 100644 --- a/app/code/core/Mage/Authorizenet/Helper/Data.php +++ b/app/code/core/Mage/Authorizenet/Helper/Data.php @@ -89,7 +89,7 @@ public function getRedirectIframeUrl($params) */ public function getPlaceOrderFrontUrl() { - $params = [Mage_Core_Model_Url::FORM_KEY => Mage::getSingleton('core/session')->getFormKey()]; + $params = [Mage_Core_Model_Url::FORM_KEY => $this->getCoreSession()->getFormKey()]; return $this->_getUrl('authorizenet/directpost_payment/place', $params); } diff --git a/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php b/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php index 3d6176a48e7..907a1e4119d 100644 --- a/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php +++ b/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php @@ -171,8 +171,8 @@ public function redirectAction() //clear sessions $this->_getSession()->clear(); $this->_getDirectPostSession()->removeCheckoutOrderIncrementId($redirectParams['x_invoice_num']); - Mage::getSingleton('adminhtml/session')->clear(); - Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The order has been created.')); + $this->getAdminhtmlSession()->clear(); + $this->getAdminhtmlSession()->addSuccess($this->__('The order has been created.')); } if (!empty($redirectParams['error_msg'])) { diff --git a/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php b/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php index 9b90b63b69d..98d5e9ad5ed 100644 --- a/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php +++ b/app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php @@ -24,10 +24,12 @@ class Mage_Authorizenet_Directpost_PaymentController extends Mage_Core_Controlle { /** * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckout() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Bundle/Model/Price/Index.php b/app/code/core/Mage/Bundle/Model/Price/Index.php index 801826455e7..bd6d1c0f75c 100644 --- a/app/code/core/Mage/Bundle/Model/Price/Index.php +++ b/app/code/core/Mage/Bundle/Model/Price/Index.php @@ -82,7 +82,7 @@ public function addPriceIndexToCollection($collection) } $websiteId = Mage::app()->getStore($collection->getStoreId()) ->getWebsiteId(); - $groupId = Mage::getSingleton('customer/session') + $groupId = $this->getCustomerSession() ->getCustomerGroupId(); $addOptionsToResult = false; @@ -114,7 +114,7 @@ public function addPriceIndexToCollection($collection) public function addPriceIndexToProduct($product) { $websiteId = $product->getStore()->getWebsiteId(); - $groupId = Mage::getSingleton('customer/session') + $groupId = $this->getCustomerSession() ->getCustomerGroupId(); $prices = $this->_getResource() ->loadPriceIndex($product->getId(), $websiteId, $groupId); diff --git a/app/code/core/Mage/Captcha/Model/Observer.php b/app/code/core/Mage/Captcha/Model/Observer.php index 57b302cc680..0567c8d4922 100644 --- a/app/code/core/Mage/Captcha/Model/Observer.php +++ b/app/code/core/Mage/Captcha/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Captcha */ -class Mage_Captcha_Model_Observer +class Mage_Captcha_Model_Observer extends Mage_Core_Model_Observer { /** * Check Captcha On Forgot Password Page @@ -35,7 +35,7 @@ public function checkForgotpassword($observer) if ($captchaModel->isRequired()) { $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { - Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $this->getCustomerSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); $controller->getResponse()->setRedirect(Mage::getUrl('*/*/forgotpassword')); } @@ -59,10 +59,10 @@ public function checkUserLogin($observer) if ($captchaModel->isRequired($login)) { $word = $this->_getCaptchaString($controller->getRequest(), $formId); if (!$captchaModel->isCorrect($word)) { - Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $this->getCustomerSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - Mage::getSingleton('customer/session')->setUsername($login); - $beforeUrl = Mage::getSingleton('customer/session')->getBeforeAuthUrl(); + $this->getCustomerSession()->setUsername($login); + $beforeUrl = $this->getCustomerSession()->getBeforeAuthUrl(); $url = $beforeUrl ? $beforeUrl : Mage::helper('customer')->getLoginUrl(); $controller->getResponse()->setRedirect($url); } @@ -83,9 +83,9 @@ public function checkUserCreate(Varien_Event_Observer $observer) if ($captchaModel->isRequired()) { $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { - Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $this->getCustomerSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - Mage::getSingleton('customer/session')->setCustomerFormData($controller->getRequest()->getPost()); + $this->getCustomerSession()->setCustomerFormData($controller->getRequest()->getPost()); $controller->getResponse()->setRedirect(Mage::getUrl('*/*/create')); } } @@ -165,10 +165,12 @@ public function checkUserLoginBackend($observer) * Returns backend session * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ protected function _getBackendSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } /** @@ -188,9 +190,9 @@ public function checkUserForgotPasswordBackend($observer) if (!empty($email) && !empty($params)) { if ($captchaModel->isRequired()) { if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { - $this->_getBackendSession()->setEmail((string) $controller->getRequest()->getPost('email')); + $this->getAdminhtmlSession()->setEmail((string) $controller->getRequest()->getPost('email')); $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - $this->_getBackendSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $this->getAdminhtmlSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); $controller->getResponse()->setRedirect(Mage::getUrl('*/*/forgotpassword')); } } @@ -291,9 +293,9 @@ public function checkWishlistSharing($observer) $controller = $observer->getControllerAction(); $request = $controller->getRequest(); if (!$captchaModel->isCorrect($this->_getCaptchaString($request, $formId))) { - Mage::getSingleton('wishlist/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $this->getWishlistSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - Mage::getSingleton('wishlist/session')->setSharingForm($request->getPost()); + $this->getWishlistSession()->setSharingForm($request->getPost()); $wishlistId = (int) $request->getParam('wishlist_id'); $controller->getResponse() ->setRedirect(Mage::getUrl('wishlist/index/share/wishlist_id/' . $wishlistId)); @@ -316,9 +318,9 @@ public function checkSendfriendSend($observer) $controller = $observer->getControllerAction(); $request = $controller->getRequest(); if (!$captchaModel->isCorrect($this->_getCaptchaString($request, $formId))) { - Mage::getSingleton('catalog/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); + $this->getCatalogSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.')); $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true); - Mage::getSingleton('catalog/session')->setFormData($request->getPost()); + $this->getCatalogSession()->setFormData($request->getPost()); $id = (int) $request->getParam('id'); $catId = $request->getParam('cat_id'); if ($catId !== null) { diff --git a/app/code/core/Mage/Captcha/Model/Zend.php b/app/code/core/Mage/Captcha/Model/Zend.php index feaa2c2038f..35990996d0c 100644 --- a/app/code/core/Mage/Captcha/Model/Zend.php +++ b/app/code/core/Mage/Captcha/Model/Zend.php @@ -22,6 +22,8 @@ */ class Mage_Captcha_Model_Zend extends Zend_Captcha_Image implements Mage_Captcha_Model_Interface { + use Mage_Core_Trait_Session; + /** * Key in session for captcha code */ @@ -190,8 +192,8 @@ protected function _isOverLimitLoginAttempts($login) protected function _isUserAuth() { return Mage::app()->getStore()->isAdmin() - ? Mage::getSingleton('admin/session')->isLoggedIn() - : Mage::getSingleton('customer/session')->isLoggedIn(); + ? $this->getAdminSession()->isLoggedIn() + : $this->getCustomerSession()->isLoggedIn(); } /** @@ -277,10 +279,12 @@ public function isCorrect($word) * Returns session instance * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ public function getSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** diff --git a/app/code/core/Mage/Catalog/Block/Navigation.php b/app/code/core/Mage/Catalog/Block/Navigation.php index df0ecf6819d..179cf891ff2 100644 --- a/app/code/core/Mage/Catalog/Block/Navigation.php +++ b/app/code/core/Mage/Catalog/Block/Navigation.php @@ -74,7 +74,7 @@ public function getCacheKeyInfo() Mage::app()->getStore()->getId(), Mage::getDesign()->getPackageName(), Mage::getDesign()->getTheme('template'), - Mage::getSingleton('customer/session')->getCustomerGroupId(), + $this->getCustomerSession()->getCustomerGroupId(), 'template' => $this->getTemplate(), 'name' => $this->getNameInLayout(), $this->getCurrenCategoryKey(), diff --git a/app/code/core/Mage/Catalog/Block/Product/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/Abstract.php index 7cc0ace7dcc..170f61ceafb 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/Abstract.php @@ -696,7 +696,7 @@ public function getAddToCartUrlCustom($product, $additional = [], $addFormKey = if ($addFormKey) { $additional = array_merge( $additional, - [Mage_Core_Model_Url::FORM_KEY => $this->_getSingletonModel('core/session')->getFormKey()], + [Mage_Core_Model_Url::FORM_KEY => $this->getCoreSession()->getFormKey()], ); } if (!isset($additional['_escape'])) { diff --git a/app/code/core/Mage/Catalog/Block/Product/Compare/List.php b/app/code/core/Mage/Catalog/Block/Product/Compare/List.php index b7c68b15893..a1f97ceabaa 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Compare/List.php +++ b/app/code/core/Mage/Catalog/Block/Product/Compare/List.php @@ -96,8 +96,8 @@ public function getItems() ->useProductItem(true) ->setStoreId(Mage::app()->getStore()->getId()); - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $this->_items->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()); + if ($this->getCustomerSession()->isLoggedIn()) { + $this->_items->setCustomerId($this->getCustomerSession()->getCustomerId()); } elseif ($this->_customerId) { $this->_items->setCustomerId($this->_customerId); } else { diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Related.php b/app/code/core/Mage/Catalog/Block/Product/List/Related.php index 0d576d76399..dce0fe7f842 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Related.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Related.php @@ -48,7 +48,7 @@ protected function _prepareData() if ($this->isModuleEnabled('Mage_Checkout', 'catalog')) { Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter( $this->_itemCollection, - Mage::getSingleton('checkout/session')->getQuoteId(), + $this->getCheckoutSession()->getQuoteId(), ); $this->_addProductAttributesAndPrices($this->_itemCollection); } diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php b/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php index 61937830659..6da18524a70 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php @@ -196,7 +196,7 @@ public function disableParamsMemorizing() */ protected function _memorizeParam($param, $value) { - $session = Mage::getSingleton('catalog/session'); + $session = $this->getCatalogSession(); if ($this->_paramsMemorizeAllowed && !$session->getParamsMemorizeDisabled()) { $session->setData($param, $value); } @@ -322,12 +322,12 @@ public function getCurrentOrder() $order = $this->getRequest()->getParam($this->getOrderVarName()); if ($order && isset($orders[$order])) { if ($order == $defaultOrder) { - Mage::getSingleton('catalog/session')->unsSortOrder(); + $this->getCatalogSession()->unsSortOrder(); } else { $this->_memorizeParam('sort_order', $order); } } else { - $order = Mage::getSingleton('catalog/session')->getSortOrder(); + $order = $this->getCatalogSession()->getSortOrder(); } // validate session value if (!$order || !isset($orders[$order])) { @@ -353,12 +353,12 @@ public function getCurrentDirection() $dir = strtolower($this->getRequest()->getParam($this->getDirectionVarName(), '')); if ($dir && in_array($dir, $directions)) { if ($dir == $this->_direction) { - Mage::getSingleton('catalog/session')->unsSortDirection(); + $this->getCatalogSession()->unsSortDirection(); } else { $this->_memorizeParam('sort_direction', $dir); } } else { - $dir = Mage::getSingleton('catalog/session')->getSortDirection(); + $dir = $this->getCatalogSession()->getSortDirection(); } // validate direction if (!$dir || !in_array($dir, $directions)) { @@ -507,12 +507,12 @@ public function getCurrentMode() $mode = $this->getRequest()->getParam($this->getModeVarName()); if ($mode) { if ($mode == $defaultMode) { - Mage::getSingleton('catalog/session')->unsDisplayMode(); + $this->getCatalogSession()->unsDisplayMode(); } else { $this->_memorizeParam('display_mode', $mode); } } else { - $mode = Mage::getSingleton('catalog/session')->getDisplayMode(); + $mode = $this->getCatalogSession()->getDisplayMode(); } if (!$mode || !isset($this->_availableMode[$mode])) { @@ -729,12 +729,12 @@ public function getLimit() $limit = $this->getRequest()->getParam($this->getLimitVarName()); if ($limit && isset($limits[$limit])) { if ($limit == $defaultLimit) { - Mage::getSingleton('catalog/session')->unsLimitPage(); + $this->getCatalogSession()->unsLimitPage(); } else { $this->_memorizeParam('limit_page', $limit); } } else { - $limit = Mage::getSingleton('catalog/session')->getLimitPage(); + $limit = $this->getCatalogSession()->getLimitPage(); } if (!$limit || !isset($limits[$limit])) { $limit = $defaultLimit; diff --git a/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php b/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php index 492a553ae3f..442a8636d26 100644 --- a/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php +++ b/app/code/core/Mage/Catalog/Block/Product/List/Upsell.php @@ -51,7 +51,7 @@ protected function _prepareData() if ($this->isModuleEnabled('Mage_Checkout', 'catalog')) { Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter( $this->_itemCollection, - Mage::getSingleton('checkout/session')->getQuoteId(), + $this->getCheckoutSession()->getQuoteId(), ); $this->_addProductAttributesAndPrices($this->_itemCollection); diff --git a/app/code/core/Mage/Catalog/Block/Product/New.php b/app/code/core/Mage/Catalog/Block/Product/New.php index 7bfd58d6ca4..cd93076d9ff 100644 --- a/app/code/core/Mage/Catalog/Block/Product/New.php +++ b/app/code/core/Mage/Catalog/Block/Product/New.php @@ -63,7 +63,7 @@ public function getCacheKeyInfo() Mage::app()->getStore()->getId(), Mage::getDesign()->getPackageName(), Mage::getDesign()->getTheme('template'), - Mage::getSingleton('customer/session')->getCustomerGroupId(), + $this->getCustomerSession()->getCustomerGroupId(), 'template' => $this->getTemplate(), $this->getProductsCount(), ]; diff --git a/app/code/core/Mage/Catalog/Block/Product/Send.php b/app/code/core/Mage/Catalog/Block/Product/Send.php index ff8a06973fb..a5125b78038 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Send.php +++ b/app/code/core/Mage/Catalog/Block/Product/Send.php @@ -30,7 +30,7 @@ class Mage_Catalog_Block_Product_Send extends Mage_Catalog_Block_Product_Abstrac public function getUserName() { - return Mage::getSingleton('customer/session')->getCustomer()->getName(); + return $this->getCustomerSession()->getCustomer()->getName(); } /** @@ -38,7 +38,7 @@ public function getUserName() */ public function getEmail() { - return (string) Mage::getSingleton('customer/session')->getCustomer()->getEmail(); + return (string) $this->getCustomerSession()->getCustomer()->getEmail(); } /** diff --git a/app/code/core/Mage/Catalog/Helper/Data.php b/app/code/core/Mage/Catalog/Helper/Data.php index 38ab381dd96..ff5dbe255b8 100644 --- a/app/code/core/Mage/Catalog/Helper/Data.php +++ b/app/code/core/Mage/Catalog/Helper/Data.php @@ -155,14 +155,14 @@ public function getProduct() */ public function getLastViewedUrl() { - if ($productId = Mage::getSingleton('catalog/session')->getLastViewedProductId()) { + if ($productId = $this->getCatalogSession()->getLastViewedProductId()) { $product = Mage::getModel('catalog/product')->load($productId); /** @var Mage_Catalog_Model_Product $product */ if (Mage::helper('catalog/product')->canShow($product, 'catalog')) { return $product->getProductUrl(); } } - if ($categoryId = Mage::getSingleton('catalog/session')->getLastViewedCategoryId()) { + if ($categoryId = $this->getCatalogSession()->getLastViewedCategoryId()) { $category = Mage::getModel('catalog/category')->load($categoryId); /** @var Mage_Catalog_Model_Category $category */ if (!Mage::helper('catalog/category')->canShow($category)) { diff --git a/app/code/core/Mage/Catalog/Helper/Product.php b/app/code/core/Mage/Catalog/Helper/Product.php index 437749115e6..89becb50597 100644 --- a/app/code/core/Mage/Catalog/Helper/Product.php +++ b/app/code/core/Mage/Catalog/Helper/Product.php @@ -337,7 +337,7 @@ public function initProduct($productId, $controller, $params = null) // Load product current category $categoryId = $params->getCategoryId(); if (!$categoryId && ($categoryId !== false)) { - $lastId = Mage::getSingleton('catalog/session')->getLastVisitedCategoryId(); + $lastId = $this->getCatalogSession()->getLastVisitedCategoryId(); if ($product->canBeShowInCategory($lastId)) { $categoryId = $lastId; } diff --git a/app/code/core/Mage/Catalog/Helper/Product/Compare.php b/app/code/core/Mage/Catalog/Helper/Product/Compare.php index 013c265b230..c3c40a9c136 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/Compare.php +++ b/app/code/core/Mage/Catalog/Helper/Product/Compare.php @@ -88,9 +88,9 @@ class Mage_Catalog_Helper_Product_Compare extends Mage_Core_Helper_Url public function __construct(array $data = []) { $this->_logCondition = $data['log_condition'] ?? Mage::helper('log'); - $this->_catalogSession = $data['catalog_session'] ?? Mage::getSingleton('catalog/session'); - $this->_customerSession = $data['customer_session'] ?? Mage::getSingleton('customer/session'); - $this->_coreSession = $data['core_session'] ?? Mage::getSingleton('core/session'); + $this->_catalogSession = $data['catalog_session'] ?? $this->getCatalogSession(); + $this->_customerSession = $data['customer_session'] ?? $this->getCustomerSession(); + $this->_coreSession = $data['core_session'] ?? $this->getCoreSession(); $this->_productVisibility = $data['product_visibility'] ?? Mage::getSingleton('catalog/product_visibility'); $this->_logVisitor = $data['log_visitor'] ?? Mage::getSingleton('log/visitor'); } diff --git a/app/code/core/Mage/Catalog/Helper/Product/View.php b/app/code/core/Mage/Catalog/Helper/Product/View.php index 0e2cd7b5529..c33998b9b5f 100644 --- a/app/code/core/Mage/Catalog/Helper/Product/View.php +++ b/app/code/core/Mage/Catalog/Helper/Product/View.php @@ -121,7 +121,7 @@ public function prepareAndRender($productId, $controller, $params = null) } /** @see Mage_Checkout_CartController::_setProductBuyRequest() */ - $checkoutBuyRequest = Mage::getSingleton('checkout/session')->getProductBuyRequest(true); + $checkoutBuyRequest = $this->getCheckoutSession()->getProductBuyRequest(true); $buyRequest = $params->getBuyRequest() ?: $checkoutBuyRequest; if ($buyRequest) { $productHelper->prepareProductOptions($product, $buyRequest); @@ -135,10 +135,10 @@ public function prepareAndRender($productId, $controller, $params = null) if ($params->getSpecifyOptions()) { $notice = $product->getTypeInstance(true)->getSpecifyOptionMessage(); - Mage::getSingleton('catalog/session')->addNotice($notice); + $this->getCatalogSession()->addNotice($notice); } - Mage::getSingleton('catalog/session')->setLastViewedProductId($product->getId()); + $this->getCatalogSession()->setLastViewedProductId($product->getId()); $this->initProductLayout($product, $controller); diff --git a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Customer/V1.php b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Customer/V1.php index 55c6c8726dd..f348ef51fc9 100644 --- a/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Customer/V1.php +++ b/app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Customer/V1.php @@ -22,6 +22,8 @@ */ class Mage_Catalog_Model_Api2_Product_Rest_Customer_V1 extends Mage_Catalog_Model_Api2_Product_Rest { + use Mage_Core_Trait_Session; + /** * Current logged in customer * @@ -49,8 +51,7 @@ protected function _getCustomerGroupId() protected function _applyTaxToPrice($price, $withTax = true) { $customer = $this->_getCustomer(); - /** @var Mage_Customer_Model_Session $session */ - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); $session->setCustomerId($customer->getId()); $price = $this->_getPrice( $price, diff --git a/app/code/core/Mage/Catalog/Model/Layer.php b/app/code/core/Mage/Catalog/Model/Layer.php index d1b6a760b3e..e1778e50b1f 100644 --- a/app/code/core/Mage/Catalog/Model/Layer.php +++ b/app/code/core/Mage/Catalog/Model/Layer.php @@ -24,6 +24,8 @@ */ class Mage_Catalog_Model_Layer extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Product collections array * @@ -58,7 +60,7 @@ public function getStateKey() if ($this->_stateKey === null) { $this->_stateKey = 'STORE_' . Mage::app()->getStore()->getId() . '_CAT_' . $this->getCurrentCategory()->getId() - . '_CUSTGROUP_' . Mage::getSingleton('customer/session')->getCustomerGroupId(); + . '_CUSTGROUP_' . $this->getCustomerSession()->getCustomerGroupId(); } return $this->_stateKey; diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php index 4b8f678792e..0a37e59bac0 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Catalog_Model_Layer_Filter_Abstract extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Request variable name with filter value * diff --git a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php index a1f2a69d2a8..c83410bc9ca 100644 --- a/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php +++ b/app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php @@ -212,7 +212,7 @@ protected function _renderRangeLabel($fromPrice, $toPrice) protected function _getCacheKey() { $key = $this->getLayer()->getStateKey() - . '_PRICES_GRP_' . Mage::getSingleton('customer/session')->getCustomerGroupId() + . '_PRICES_GRP_' . $this->getCustomerSession()->getCustomerGroupId() . '_CURR_' . Mage::app()->getStore()->getCurrentCurrencyCode() . '_ATTR_' . $this->getAttributeModel()->getAttributeCode() . '_LOC_' @@ -427,7 +427,7 @@ public function getCustomerGroupId() { $customerGroupId = $this->_getData('customer_group_id'); if (is_null($customerGroupId)) { - $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $customerGroupId = $this->getCustomerSession()->getCustomerGroupId(); } return $customerGroupId; } diff --git a/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php b/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php index 5b3633e7b1d..e14fd459280 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php +++ b/app/code/core/Mage/Catalog/Model/Product/Compare/Item.php @@ -203,7 +203,7 @@ public function clean() public function getCustomerId() { if (!$this->hasData('customer_id')) { - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); $this->setData('customer_id', $customerId); } return $this->getData('customer_id'); diff --git a/app/code/core/Mage/Catalog/Model/Product/Compare/List.php b/app/code/core/Mage/Catalog/Model/Product/Compare/List.php index 97571b0bbd8..b92110c741c 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Compare/List.php +++ b/app/code/core/Mage/Catalog/Model/Product/Compare/List.php @@ -22,6 +22,8 @@ */ class Mage_Catalog_Model_Product_Compare_List extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Add product to Compare List * @@ -98,8 +100,8 @@ public function removeProduct($product) protected function _addVisitorToItem($item) { $item->addVisitorId(Mage::getSingleton('log/visitor')->getId()); - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer()); + if ($this->getCustomerSession()->isLoggedIn()) { + $item->addCustomerData($this->getCustomerSession()->getCustomer()); } return $this; diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php index 1ac1af5364b..bbf61b38ce7 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php @@ -32,6 +32,8 @@ */ class Mage_Catalog_Model_Product_Option_Type_Default extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Option Instance * @@ -203,7 +205,7 @@ public function getConfigData($key) */ public function validateUserValue($values) { - Mage::getSingleton('checkout/session')->setUseNotice(false); + $this->getCheckoutSession()->setUseNotice(false); $this->setIsValid(false); diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php index 8c6e5a97caa..0bf4bc541f4 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php @@ -113,7 +113,7 @@ protected function _getCurrentConfigFileInfo() */ public function validateUserValue($values) { - Mage::getSingleton('checkout/session')->setUseNotice(false); + $this->getCheckoutSession()->setUseNotice(false); $this->setIsValid(true); $option = $this->getOption(); diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php index 765f4f3b170..e8c10bd6a26 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php @@ -22,6 +22,8 @@ */ class Mage_Catalog_Model_Product_Type_Price { + use Mage_Core_Trait_Session; + public const CACHE_TAG = 'PRODUCT_PRICE'; public static $attributeCache = []; @@ -257,7 +259,7 @@ protected function _getCustomerGroupId($product) if ($product->getCustomerGroupId()) { return $product->getCustomerGroupId(); } - return Mage::getSingleton('customer/session')->getCustomerGroupId(); + return $this->getCustomerSession()->getCustomerGroupId(); } /** diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php index 719b8830bd8..009214670a5 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php @@ -1224,7 +1224,7 @@ public function addFinalPrice() protected function _joinPriceRules() { if ($this->isEnabledFlat()) { - $customerGroup = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $customerGroup = $this->getCustomerSession()->getCustomerGroupId(); $priceColumn = 'e.display_price_group_' . $customerGroup; $this->getSelect()->columns(['_rule_price' => $priceColumn]); @@ -1234,7 +1234,7 @@ protected function _joinPriceRules() return $this; } $wId = Mage::app()->getWebsite()->getId(); - $gId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $gId = $this->getCustomerSession()->getCustomerGroupId(); $storeDate = Mage::app()->getLocale()->storeTimeStamp($this->getStoreId()); $conditions = 'price_rule.product_id = e.entity_id AND '; @@ -1333,7 +1333,7 @@ public function addPriceData($customerGroupId = null, $websiteId = null) $this->_productLimitationFilters['use_price_index'] = true; if (!isset($this->_productLimitationFilters['customer_group_id']) && is_null($customerGroupId)) { - $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $customerGroupId = $this->getCustomerSession()->getCustomerGroupId(); } if (!isset($this->_productLimitationFilters['website_id']) && is_null($websiteId)) { $websiteId = Mage::app()->getStore($this->getStoreId())->getWebsiteId(); @@ -1786,7 +1786,7 @@ public function applyFrontendPriceLimitations() { $this->_productLimitationFilters['use_price_index'] = true; if (!isset($this->_productLimitationFilters['customer_group_id'])) { - $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $customerGroupId = $this->getCustomerSession()->getCustomerGroupId(); $this->_productLimitationFilters['customer_group_id'] = $customerGroupId; } if (!isset($this->_productLimitationFilters['website_id'])) { diff --git a/app/code/core/Mage/Catalog/controllers/CategoryController.php b/app/code/core/Mage/Catalog/controllers/CategoryController.php index f0352af3316..426c51c52fc 100644 --- a/app/code/core/Mage/Catalog/controllers/CategoryController.php +++ b/app/code/core/Mage/Catalog/controllers/CategoryController.php @@ -43,7 +43,7 @@ protected function _initCategory() if (!Mage::helper('catalog/category')->canShow($category)) { return false; } - Mage::getSingleton('catalog/session')->setLastVisitedCategoryId($category->getId()); + $this->getCatalogSession()->setLastVisitedCategoryId($category->getId()); Mage::register('current_category', $category); Mage::register('current_entity_key', $category->getPath()); @@ -126,7 +126,7 @@ public function viewAction() $design->applyCustomDesign($settings->getCustomDesign()); } - Mage::getSingleton('catalog/session')->setLastViewedCategoryId($category->getId()); + $this->getCatalogSession()->setLastViewedCategoryId($category->getId()); $update = $this->getLayout()->getUpdate(); $update->addHandle('default'); @@ -162,8 +162,8 @@ public function viewAction() ->addBodyClass('category-' . $category->getUrlKey()); } - $this->_initLayoutMessages('catalog/session'); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->renderLayout(); } elseif (!$this->getResponse()->isRedirect()) { $this->_forward('noRoute'); diff --git a/app/code/core/Mage/Catalog/controllers/Product/CompareController.php b/app/code/core/Mage/Catalog/controllers/Product/CompareController.php index fdeb10dcb8f..c157acaa881 100644 --- a/app/code/core/Mage/Catalog/controllers/Product/CompareController.php +++ b/app/code/core/Mage/Catalog/controllers/Product/CompareController.php @@ -41,7 +41,7 @@ public function indexAction() $items = $this->getRequest()->getParam('items'); if ($beforeUrl = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) { - Mage::getSingleton('catalog/session') + $this->getCatalogSession() ->setBeforeCompareUrl(Mage::helper('core')->urlDecodeAndEscape($beforeUrl)); } @@ -69,7 +69,7 @@ public function addAction() $productId = (int) $this->getRequest()->getParam('product'); if ($this->isProductAvailable($productId) - && (Mage::getSingleton('log/visitor')->getId() || Mage::getSingleton('customer/session')->isLoggedIn()) + && (Mage::getSingleton('log/visitor')->getId() || $this->getCustomerSession()->isLoggedIn()) ) { $product = Mage::getModel('catalog/product') ->setStoreId(Mage::app()->getStore()->getId()) @@ -77,7 +77,7 @@ public function addAction() if ($product->getId()/* && !$product->isSuper()*/) { Mage::getSingleton('catalog/product_compare_list')->addProduct($product); - Mage::getSingleton('catalog/session')->addSuccess( + $this->getCatalogSession()->addSuccess( $this->__('The product %s has been added to comparison list.', Mage::helper('core')->escapeHtml($product->getName())), ); Mage::dispatchEvent('catalog_product_compare_add_product', ['product' => $product]); @@ -103,8 +103,8 @@ public function removeAction() if ($product->getId()) { /** @var Mage_Catalog_Model_Product_Compare_Item $item */ $item = Mage::getModel('catalog/product_compare_item'); - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer()); + if ($this->getCustomerSession()->isLoggedIn()) { + $item->addCustomerData($this->getCustomerSession()->getCustomer()); } elseif ($this->_customerId) { $item->addCustomerData( Mage::getModel('customer/customer')->load($this->_customerId), @@ -117,7 +117,7 @@ public function removeAction() if ($item->getId()) { $item->delete(); - Mage::getSingleton('catalog/session')->addSuccess( + $this->getCatalogSession()->addSuccess( $this->__('The product %s has been removed from comparison list.', $product->getName()), ); Mage::dispatchEvent('catalog_product_compare_remove_product', ['product' => $item]); @@ -138,16 +138,15 @@ public function clearAction() { $items = Mage::getResourceModel('catalog/product_compare_item_collection'); - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $items->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()); + if ($this->getCustomerSession()->isLoggedIn()) { + $items->setCustomerId($this->getCustomerSession()->getCustomerId()); } elseif ($this->_customerId) { $items->setCustomerId($this->_customerId); } else { $items->setVisitorId(Mage::getSingleton('log/visitor')->getId()); } - /** @var Mage_Catalog_Model_Session $session */ - $session = Mage::getSingleton('catalog/session'); + $session = $this->getCatalogSession(); try { $items->clear(); diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Indexer.php index 4b766abedfc..e467eee15d1 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Indexer.php +++ b/app/code/core/Mage/CatalogIndex/Model/Indexer.php @@ -658,7 +658,7 @@ public function buildEntityPriceFilter($attributes, $values, &$filteredAttribute if ($code == 'price') { $filter[$code]->where( $table . '.customer_group_id = ?', - Mage::getSingleton('customer/session')->getCustomerGroupId(), + $this->getCustomerSession()->getCustomerGroupId(), ); } diff --git a/app/code/core/Mage/CatalogIndex/Model/Price.php b/app/code/core/Mage/CatalogIndex/Model/Price.php index 60e47268a66..6b376b6aa07 100644 --- a/app/code/core/Mage/CatalogIndex/Model/Price.php +++ b/app/code/core/Mage/CatalogIndex/Model/Price.php @@ -47,7 +47,7 @@ protected function _construct() $this->_init('catalogindex/price'); $this->_getResource()->setStoreId(Mage::app()->getStore()->getId()); $this->_getResource()->setRate(Mage::app()->getStore()->getCurrentCurrencyRate()); - $this->_getResource()->setCustomerGroupId(Mage::getSingleton('customer/session')->getCustomerGroupId()); + $this->_getResource()->setCustomerGroupId($this->getCustomerSession()->getCustomerGroupId()); } /** diff --git a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php index faa35607cfd..c0138128f1a 100644 --- a/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php +++ b/app/code/core/Mage/CatalogInventory/Model/Stock/Item.php @@ -330,7 +330,7 @@ public function getMinSaleQty() if (!$customerGroupId) { $customerGroupId = Mage::app()->getStore()->isAdmin() ? Mage_Customer_Model_Group::CUST_GROUP_ALL - : Mage::getSingleton('customer/session')->getCustomerGroupId(); + : $this->getCustomerSession()->getCustomerGroupId(); } if (!isset($this->_minSaleQtyCache[$customerGroupId])) { diff --git a/app/code/core/Mage/CatalogRule/Model/Observer.php b/app/code/core/Mage/CatalogRule/Model/Observer.php index 30a1889ed23..65b26892b9a 100644 --- a/app/code/core/Mage/CatalogRule/Model/Observer.php +++ b/app/code/core/Mage/CatalogRule/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_CatalogRule */ -class Mage_CatalogRule_Model_Observer +class Mage_CatalogRule_Model_Observer extends Mage_Core_Model_Observer { /** * Preload price rules for all items in quote @@ -159,7 +159,7 @@ public function processFrontFinalPrice($observer) } elseif ($product->hasCustomerGroupId()) { $gId = $product->getCustomerGroupId(); } else { - $gId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $gId = $this->getCustomerSession()->getCustomerGroupId(); } $key = $this->_getRulePricesKey([$date, $wId, $gId, $pId]); @@ -325,7 +325,7 @@ protected function _checkCatalogRulesAvailability($attributeCode) if ($disabledRulesCount) { Mage::getModel('catalogrule/rule')->applyAll(); - Mage::getSingleton('adminhtml/session')->addWarning( + $this->getAdminhtmlSession()->addWarning( Mage::helper('catalogrule')->__('%d Catalog Price Rules based on "%s" attribute have been disabled.', $disabledRulesCount, $attributeCode), ); } @@ -402,10 +402,9 @@ public function prepareCatalogProductCollectionPrices(Varien_Event_Observer $obs if ($observer->getEvent()->hasCustomerGroupId()) { $groupId = $observer->getEvent()->getCustomerGroupId(); } else { - /** @var Mage_Customer_Model_Session $session */ - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); if ($session->isLoggedIn()) { - $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $groupId = $this->getCustomerSession()->getCustomerGroupId(); } else { $groupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID; } diff --git a/app/code/core/Mage/CatalogRule/Model/Rule.php b/app/code/core/Mage/CatalogRule/Model/Rule.php index 7cae8e9606e..5594589aab6 100644 --- a/app/code/core/Mage/CatalogRule/Model/Rule.php +++ b/app/code/core/Mage/CatalogRule/Model/Rule.php @@ -359,7 +359,7 @@ public function calcProductPriceRule(Mage_Catalog_Model_Product $product, $price if ($product->hasCustomerGroupId()) { $customerGroupId = $product->getCustomerGroupId(); } else { - $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $customerGroupId = $this->getCustomerSession()->getCustomerGroupId(); } $dateTs = Mage::app()->getLocale()->date()->getTimestamp(); $cacheKey = date('Y-m-d', $dateTs) . "|$websiteId|$customerGroupId|$productId|$price"; diff --git a/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php b/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php index d156cbb66ce..a877d3731cf 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php +++ b/app/code/core/Mage/CatalogSearch/Model/Fulltext/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_CatalogSearch */ -class Mage_CatalogSearch_Model_Fulltext_Observer +class Mage_CatalogSearch_Model_Fulltext_Observer extends Mage_Core_Model_Observer { /** * Retrieve fulltext (indexer) model @@ -98,7 +98,7 @@ public function eavAttributeChange(Varien_Event_Observer $observer) if ($showNotice) { $url = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/system_cache'); - Mage::getSingleton('adminhtml/session')->addNotice( + $this->getAdminhtmlSession()->addNotice( Mage::helper('catalogsearch')->__('Attribute setting change related with Search Index. Please run Rebuild Search Index process.', $url), ); } diff --git a/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php b/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php index 15f667bff48..d828adf416f 100644 --- a/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php +++ b/app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php @@ -26,7 +26,7 @@ class Mage_CatalogSearch_AdvancedController extends Mage_Core_Controller_Front_A public function indexAction() { $this->loadLayout(); - $this->_initLayoutMessages('catalogsearch/session'); + $this->_initLayoutMessages($this->getCatalogSearchSessionStorage()); $this->renderLayout(); } @@ -36,7 +36,7 @@ public function resultAction() try { Mage::getSingleton('catalogsearch/advanced')->addFilters($this->getRequest()->getQuery()); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('catalogsearch/session')->addError($e->getMessage()); + $this->getCatalogSearchSession()->addError($e->getMessage()); $this->_redirectError( Mage::getModel('core/url') ->setQueryParams($this->getRequest()->getQuery()) @@ -44,7 +44,7 @@ public function resultAction() ); return; } - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $this->renderLayout(); } } diff --git a/app/code/core/Mage/CatalogSearch/controllers/ResultController.php b/app/code/core/Mage/CatalogSearch/controllers/ResultController.php index 4bc98018f51..c113131f746 100644 --- a/app/code/core/Mage/CatalogSearch/controllers/ResultController.php +++ b/app/code/core/Mage/CatalogSearch/controllers/ResultController.php @@ -26,10 +26,12 @@ class Mage_CatalogSearch_ResultController extends Mage_Core_Controller_Front_Act * Retrieve catalog session * * @return Mage_Catalog_Model_Session + * @deprecated + * @see getCatalogSession() */ protected function _getSession() { - return Mage::getSingleton('catalog/session'); + return $this->getCatalogSession(); } /** * Display search result @@ -65,8 +67,8 @@ public function indexAction() Mage::helper('catalogsearch')->checkNotes(); $this->loadLayout(); - $this->_initLayoutMessages('catalog/session'); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->renderLayout(); if (!Mage::helper('catalogsearch')->isMinQueryLength()) { diff --git a/app/code/core/Mage/Centinel/Block/Authentication.php b/app/code/core/Mage/Centinel/Block/Authentication.php index 639ca49bdc2..06cf41839bc 100644 --- a/app/code/core/Mage/Centinel/Block/Authentication.php +++ b/app/code/core/Mage/Centinel/Block/Authentication.php @@ -66,7 +66,7 @@ public function getRelatedBlocks() */ protected function _toHtml() { - $method = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance(); + $method = $this->getCheckoutSession()->getQuote()->getPayment()->getMethodInstance(); if ($method->getIsCentinelValidationEnabled()) { $centinel = $method->getCentinelValidator(); if ($centinel && $centinel->shouldAuthenticate()) { diff --git a/app/code/core/Mage/Centinel/Model/Service.php b/app/code/core/Mage/Centinel/Model/Service.php index f430081e68a..610f184da3b 100644 --- a/app/code/core/Mage/Centinel/Model/Service.php +++ b/app/code/core/Mage/Centinel/Model/Service.php @@ -22,6 +22,8 @@ */ class Mage_Centinel_Model_Service extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Cmpi public keys */ @@ -63,10 +65,12 @@ class Mage_Centinel_Model_Service extends Varien_Object * Return validation session object * * @return Mage_Centinel_Model_Session + * @deprecated + * @see getCentinalSession() */ protected function _getSession() { - return Mage::getSingleton('centinel/session'); + return $this->getCentinalSession(); } /** @@ -108,7 +112,7 @@ private function _getUrl($suffix, $current = false) $params = [ '_secure' => true, '_current' => $current, - 'form_key' => Mage::getSingleton('core/session')->getFormKey(), + 'form_key' => $this->getCoreSession()->getFormKey(), 'isIframe' => true, ]; if (Mage::app()->getStore()->isAdmin()) { diff --git a/app/code/core/Mage/Centinel/controllers/IndexController.php b/app/code/core/Mage/Centinel/controllers/IndexController.php index c3f75110e70..a5b45ec750c 100644 --- a/app/code/core/Mage/Centinel/controllers/IndexController.php +++ b/app/code/core/Mage/Centinel/controllers/IndexController.php @@ -64,7 +64,7 @@ public function authenticationCompleteAction() */ private function _getPayment() { - return Mage::getSingleton('checkout/session')->getQuote()->getPayment(); + return $this->getCheckoutSession()->getQuote()->getPayment(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Cart.php b/app/code/core/Mage/Checkout/Block/Cart.php index 43885d71b13..8c1a9f3a1ab 100644 --- a/app/code/core/Mage/Checkout/Block/Cart.php +++ b/app/code/core/Mage/Checkout/Block/Cart.php @@ -103,7 +103,7 @@ public function isWishlistActive() $isActive = $this->_getData('is_wishlist_active'); if ($isActive === null) { $isActive = Mage::getStoreConfig('wishlist/general/active') - && Mage::getSingleton('customer/session')->isLoggedIn(); + && $this->getCustomerSession()->isLoggedIn(); $this->setIsWishlistActive($isActive); } return $isActive; @@ -134,7 +134,7 @@ public function getContinueShoppingUrl() { $url = $this->getData('continue_shopping_url'); if (is_null($url)) { - $url = Mage::getSingleton('checkout/session')->getContinueShoppingUrl(true); + $url = $this->getCheckoutSession()->getContinueShoppingUrl(true); if (!$url) { $url = Mage::getUrl(); } diff --git a/app/code/core/Mage/Checkout/Block/Cart/Abstract.php b/app/code/core/Mage/Checkout/Block/Cart/Abstract.php index cf8db7b7259..74601fdbd5b 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Abstract.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Abstract.php @@ -106,7 +106,7 @@ public function getItemRenderer($type) public function getCustomer() { if ($this->_customer === null) { - $this->_customer = Mage::getSingleton('customer/session')->getCustomer(); + $this->_customer = $this->getCustomerSession()->getCustomer(); } return $this->_customer; } @@ -119,7 +119,7 @@ public function getCustomer() public function getCheckout() { if ($this->_checkout === null) { - $this->_checkout = Mage::getSingleton('checkout/session'); + $this->_checkout = $this->getCheckoutSession(); } return $this->_checkout; } diff --git a/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php b/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php index 0d776407638..86f06834a81 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Crosssell.php @@ -135,7 +135,7 @@ protected function _getCartProductIdsRel() */ protected function _getLastAddedProductId() { - return Mage::getSingleton('checkout/session')->getLastAddedProductId(true); + return $this->getCheckoutSession()->getLastAddedProductId(true); } /** @@ -145,7 +145,7 @@ protected function _getLastAddedProductId() */ public function getQuote() { - return Mage::getSingleton('checkout/session')->getQuote(); + return $this->getCheckoutSession()->getQuote(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php index 9d3dbf5a0ce..d37e7d852c1 100644 --- a/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php +++ b/app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php @@ -241,7 +241,7 @@ public function getDeleteUrlCustom($addFormKey = true) Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $helper->getEncodedUrl(), ]; if ($addFormKey) { - $params[Mage_Core_Model_Url::FORM_KEY] = Mage::getSingleton('core/session')->getFormKey(); + $params[Mage_Core_Model_Url::FORM_KEY] = $this->getCoreSession()->getFormKey(); } return $this->getUrl('checkout/cart/delete', $params); @@ -320,10 +320,10 @@ public function getIsInStock() * * @return Mage_Checkout_Model_Session */ - public function getCheckoutSession() + public function getCheckout() { if ($this->_checkoutSession === null) { - $this->_checkoutSession = Mage::getSingleton('checkout/session'); + $this->_checkoutSession = $this->getCheckoutSession(); } return $this->_checkoutSession; } @@ -354,7 +354,7 @@ public function getMessages() } // Add messages saved previously in checkout session - $checkoutSession = $this->getCheckoutSession(); + $checkoutSession = $this->getCheckout(); if ($checkoutSession) { /** @var Mage_Core_Model_Message_Collection $collection */ $collection = $checkoutSession->getQuoteItemMessages($quoteItem->getId(), true); diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php b/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php index 154a31b8be7..c0fe888b1ed 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Billing.php @@ -82,7 +82,7 @@ public function getAddress() */ public function getQuote() { - return Mage::getSingleton('checkout/session')->getQuote(); + return $this->getCheckoutSession()->getQuote(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php b/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php index eb2635ce3ac..b93a8f92c17 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Billing/Items.php @@ -39,7 +39,7 @@ public function getCheckout() */ public function getQuote() { - return Mage::getSingleton('checkout/session')->getQuote(); + return $this->getCheckoutSession()->getQuote(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Link.php b/app/code/core/Mage/Checkout/Block/Multishipping/Link.php index f3683df513e..69c4c557f63 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Link.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Link.php @@ -35,7 +35,7 @@ public function getCheckoutUrl() */ public function getQuote() { - return Mage::getSingleton('checkout/session')->getQuote(); + return $this->getCheckoutSession()->getQuote(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Multishipping/Success.php b/app/code/core/Mage/Checkout/Block/Multishipping/Success.php index 2505391dbc4..4aabf02723f 100644 --- a/app/code/core/Mage/Checkout/Block/Multishipping/Success.php +++ b/app/code/core/Mage/Checkout/Block/Multishipping/Success.php @@ -27,7 +27,7 @@ class Mage_Checkout_Block_Multishipping_Success extends Mage_Checkout_Block_Mult */ public function getOrderIds() { - $ids = Mage::getSingleton('core/session')->getOrderIds(true); + $ids = $this->getCoreSession()->getOrderIds(true); if ($ids && is_array($ids)) { return $ids; } diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php b/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php index af5ce7a7be2..cb1a0a89ba2 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Abstract.php @@ -39,7 +39,7 @@ abstract class Mage_Checkout_Block_Onepage_Abstract extends Mage_Core_Block_Temp public function getCustomer() { if (empty($this->_customer)) { - $this->_customer = Mage::getSingleton('customer/session')->getCustomer(); + $this->_customer = $this->getCustomerSession()->getCustomer(); } return $this->_customer; } @@ -52,7 +52,7 @@ public function getCustomer() public function getCheckout() { if (empty($this->_checkout)) { - $this->_checkout = Mage::getSingleton('checkout/session'); + $this->_checkout = $this->getCheckoutSession(); } return $this->_checkout; } @@ -75,7 +75,7 @@ public function getQuote() */ public function isCustomerLoggedIn() { - return Mage::getSingleton('customer/session')->isLoggedIn(); + return $this->getCustomerSession()->isLoggedIn(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Failure.php b/app/code/core/Mage/Checkout/Block/Onepage/Failure.php index 080f9d02ea8..6b54a3c7750 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Failure.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Failure.php @@ -21,28 +21,28 @@ class Mage_Checkout_Block_Onepage_Failure extends Mage_Core_Block_Template { /** - * @return mixed + * @return string */ public function getRealOrderId() { - return Mage::getSingleton('checkout/session')->getLastRealOrderId(); + return $this->getCheckoutSession()->getLastRealOrderId(); } /** * Payment custom error message * - * @return string + * @return string */ public function getErrorMessage() { - // Mage::getSingleton('checkout/session')->unsErrorMessage(); - return Mage::getSingleton('checkout/session')->getErrorMessage(); + // $this->getCheckoutSession()->unsErrorMessage(); + return $this->getCheckoutSession()->getErrorMessage(); } /** * Continue shopping URL * - * @return string + * @return string */ public function getContinueShoppingUrl() { diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Link.php b/app/code/core/Mage/Checkout/Block/Onepage/Link.php index acc143ae014..fceaeb4fa83 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Link.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Link.php @@ -35,7 +35,7 @@ public function getCheckoutUrl() */ public function isDisabled() { - return !Mage::getSingleton('checkout/session')->getQuote()->validateMinimumAmount(); + return !$this->getCheckoutSession()->getQuote()->validateMinimumAmount(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Login.php b/app/code/core/Mage/Checkout/Block/Onepage/Login.php index c59638632b8..cfbf513419a 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Login.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Login.php @@ -35,7 +35,7 @@ protected function _construct() */ public function getMessages() { - return Mage::getSingleton('customer/session')->getMessages(true); + return $this->getCustomerSession()->getMessages(true); } /** @@ -85,6 +85,6 @@ public function getErrorUrl() */ public function getUsername() { - return Mage::getSingleton('customer/session')->getUsername(true); + return $this->getCustomerSession()->getUsername(true); } } diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php index 22a391baf70..c1d89a4cdd3 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Info.php @@ -29,7 +29,7 @@ class Mage_Checkout_Block_Onepage_Payment_Info extends Mage_Payment_Block_Info_C */ public function getPaymentInfo() { - $info = Mage::getSingleton('checkout/session')->getQuote()->getPayment(); + $info = $this->getCheckoutSession()->getQuote()->getPayment(); if ($info->getMethod()) { return $info; } diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php index 2c13cfa2850..a17deb89a28 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Payment/Methods.php @@ -27,7 +27,7 @@ class Mage_Checkout_Block_Onepage_Payment_Methods extends Mage_Payment_Block_For */ public function getQuote() { - return Mage::getSingleton('checkout/session')->getQuote(); + return $this->getCheckoutSession()->getQuote(); } /** diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php b/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php index 9198db36afd..e799c37bb11 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Review/Info.php @@ -27,7 +27,7 @@ class Mage_Checkout_Block_Onepage_Review_Info extends Mage_Sales_Block_Items_Abs */ public function getItems() { - return Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems(); + return $this->getCheckoutSession()->getQuote()->getAllVisibleItems(); } /** @@ -35,6 +35,6 @@ public function getItems() */ public function getTotals() { - return Mage::getSingleton('checkout/session')->getQuote()->getTotals(); + return $this->getCheckoutSession()->getQuote()->getTotals(); } } diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Success.php b/app/code/core/Mage/Checkout/Block/Onepage/Success.php index 7bb111edfd6..64005c1cd8e 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Success.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Success.php @@ -87,7 +87,7 @@ protected function _beforeToHtml() */ protected function _prepareLastOrder() { - $orderId = Mage::getSingleton('checkout/session')->getLastOrderId(); + $orderId = $this->getCheckoutSession()->getLastOrderId(); if ($orderId) { $order = Mage::getModel('sales/order')->load($orderId); if ($order->getId()) { @@ -100,7 +100,7 @@ protected function _prepareLastOrder() 'view_order_id' => $this->getUrl('sales/order/view/', ['order_id' => $orderId]), 'print_url' => $this->getUrl('sales/order/print', ['order_id' => $orderId]), 'can_print_order' => $isVisible, - 'can_view_order' => Mage::getSingleton('customer/session')->isLoggedIn() && $isVisible, + 'can_view_order' => $this->getCustomerSession()->isLoggedIn() && $isVisible, 'order_id' => $order->getIncrementId(), 'order' => $order, ]); @@ -113,8 +113,8 @@ protected function _prepareLastOrder() */ protected function _prepareLastBillingAgreement() { - $agreementId = Mage::getSingleton('checkout/session')->getLastBillingAgreementId(); - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $agreementId = $this->getCheckoutSession()->getLastBillingAgreementId(); + $customerId = $this->getCustomerSession()->getCustomerId(); if ($agreementId && $customerId) { $agreement = Mage::getModel('sales/billing_agreement')->load($agreementId); if ($agreement->getId() && $customerId == $agreement->getCustomerId()) { @@ -135,7 +135,7 @@ protected function _prepareLastBillingAgreement() */ protected function _prepareLastRecurringProfiles() { - $profileIds = Mage::getSingleton('checkout/session')->getLastRecurringProfileIds(); + $profileIds = $this->getCheckoutSession()->getLastRecurringProfileIds(); if ($profileIds && is_array($profileIds)) { $collection = Mage::getModel('sales/recurring_profile')->getCollection() ->addFieldToFilter('profile_id', ['in' => $profileIds]) @@ -146,7 +146,7 @@ protected function _prepareLastRecurringProfiles() } if ($profiles) { $this->setRecurringProfiles($profiles); - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $this->setCanViewProfiles(true); } } diff --git a/app/code/core/Mage/Checkout/Controller/Action.php b/app/code/core/Mage/Checkout/Controller/Action.php index cf6d8d4e6fa..13ba2f93cb0 100644 --- a/app/code/core/Mage/Checkout/Controller/Action.php +++ b/app/code/core/Mage/Checkout/Controller/Action.php @@ -32,13 +32,13 @@ abstract class Mage_Checkout_Controller_Action extends Mage_Core_Controller_Fron */ protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true) { - $customer = Mage::getSingleton('customer/session')->getCustomer(); + $customer = $this->getCustomerSession()->getCustomer(); if ($customer && $customer->getId()) { $validationResult = $customer->validate(); if (($validationResult !== true) && is_array($validationResult)) { if ($addErrors) { foreach ($validationResult as $error) { - Mage::getSingleton('customer/session')->addError($error); + $this->getCustomerSession()->addError($error); } } if ($redirect) { diff --git a/app/code/core/Mage/Checkout/Helper/Cart.php b/app/code/core/Mage/Checkout/Helper/Cart.php index 1598aacc540..340d3974f15 100644 --- a/app/code/core/Mage/Checkout/Helper/Cart.php +++ b/app/code/core/Mage/Checkout/Helper/Cart.php @@ -99,7 +99,7 @@ public function getCartUrl() */ public function getQuote() { - return Mage::getSingleton('checkout/session')->getQuote(); + return $this->getCheckoutSession()->getQuote(); } /** @@ -169,7 +169,7 @@ public function getAddUrlCustom($product, $additional = [], $addFormKey = true) 'product' => $product->getEntityId(), ]; if ($addFormKey) { - $routeParams[Mage_Core_Model_Url::FORM_KEY] = $this->_getSingletonModel('core/session')->getFormKey(); + $routeParams[Mage_Core_Model_Url::FORM_KEY] = $this->getCoreSession()->getFormKey(); } if (!empty($additional)) { $routeParams = array_merge($routeParams, $additional); diff --git a/app/code/core/Mage/Checkout/Helper/Data.php b/app/code/core/Mage/Checkout/Helper/Data.php index 90d90e94924..a54dee35c3a 100644 --- a/app/code/core/Mage/Checkout/Helper/Data.php +++ b/app/code/core/Mage/Checkout/Helper/Data.php @@ -36,7 +36,7 @@ class Mage_Checkout_Helper_Data extends Mage_Core_Helper_Abstract */ public function getCheckout() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Checkout/Model/Cart.php b/app/code/core/Mage/Checkout/Model/Cart.php index 2cab9d82441..9c6704a26ba 100644 --- a/app/code/core/Mage/Checkout/Model/Cart.php +++ b/app/code/core/Mage/Checkout/Model/Cart.php @@ -22,6 +22,8 @@ */ class Mage_Checkout_Model_Cart extends Varien_Object implements Mage_Checkout_Model_Cart_Interface { + use Mage_Core_Trait_Session; + /** * Shopping cart items summary quantity(s) * @@ -46,26 +48,6 @@ protected function _getResource() return Mage::getResourceSingleton('checkout/cart'); } - /** - * Retrieve checkout session model - * - * @return Mage_Checkout_Model_Session - */ - public function getCheckoutSession() - { - return Mage::getSingleton('checkout/session'); - } - - /** - * Retrieve customer session model - * - * @return Mage_Customer_Model_Session - */ - public function getCustomerSession() - { - return Mage::getSingleton('customer/session'); - } - /** * List of shopping cart items * @@ -481,7 +463,6 @@ public function truncate() */ public function getProductIds() { - $quoteId = Mage::getSingleton('checkout/session')->getQuoteId(); if ($this->_productIds === null) { $this->_productIds = []; if ($this->getSummaryQty() > 0) { @@ -501,14 +482,13 @@ public function getProductIds() */ public function getSummaryQty() { - $quoteId = Mage::getSingleton('checkout/session')->getQuoteId(); + $quoteId = $this->getCheckoutSession()->getQuoteId(); //If there is no quote id in session trying to load quote //and get new quote id. This is done for cases when quote was created //not by customer (from backend for example). - if (!$quoteId && Mage::getSingleton('customer/session')->isLoggedIn()) { - $quote = Mage::getSingleton('checkout/session')->getQuote(); - $quoteId = Mage::getSingleton('checkout/session')->getQuoteId(); + if (!$quoteId && $this->getCustomerSession()->isLoggedIn()) { + $quoteId = $this->getCheckoutSession()->getQuoteId(); } if ($quoteId && $this->_summaryQty === null) { diff --git a/app/code/core/Mage/Checkout/Model/Observer.php b/app/code/core/Mage/Checkout/Model/Observer.php index 9347a0cd6f3..c1935eb7b08 100644 --- a/app/code/core/Mage/Checkout/Model/Observer.php +++ b/app/code/core/Mage/Checkout/Model/Observer.php @@ -20,21 +20,21 @@ * @category Mage * @package Mage_Checkout */ -class Mage_Checkout_Model_Observer +class Mage_Checkout_Model_Observer extends Mage_Core_Model_Observer { public function unsetAll() { - Mage::getSingleton('checkout/session')->unsetAll(); + $this->getCheckoutSession()->unsetAll(); } public function loadCustomerQuote() { try { - Mage::getSingleton('checkout/session')->loadCustomerQuote(); + $this->getCheckoutSession()->loadCustomerQuote(); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('checkout/session')->addError($e->getMessage()); + $this->getCheckoutSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('checkout/session')->addException( + $this->getCheckoutSession()->addException( $e, Mage::helper('checkout')->__('Load customer quote error'), ); @@ -46,7 +46,7 @@ public function salesQuoteSaveAfter(Varien_Event_Observer $observer) $quote = $observer->getEvent()->getQuote(); /** @var Mage_Sales_Model_Quote $quote */ if ($quote->getIsCheckoutCart()) { - Mage::getSingleton('checkout/session')->getQuoteId($quote->getId()); + $this->getCheckoutSession()->getQuoteId($quote->getId()); } } } diff --git a/app/code/core/Mage/Checkout/Model/Session.php b/app/code/core/Mage/Checkout/Model/Session.php index aee6c546a9e..1275ef4956b 100644 --- a/app/code/core/Mage/Checkout/Model/Session.php +++ b/app/code/core/Mage/Checkout/Model/Session.php @@ -216,7 +216,7 @@ public function getQuote() } } - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); if (!$this->getQuoteId()) { if ($customerSession->isLoggedIn() || $this->_customer) { @@ -280,7 +280,7 @@ public function getQuoteId() */ public function loadCustomerQuote() { - if (!Mage::getSingleton('customer/session')->getCustomerId()) { + if (!$this->getCustomerSession()->getCustomerId()) { return $this; } @@ -288,7 +288,7 @@ public function loadCustomerQuote() $customerQuote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore()->getId()) - ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId()); + ->loadByCustomer($this->getCustomerSession()->getCustomerId()); if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) { if ($this->getQuoteId()) { @@ -306,7 +306,7 @@ public function loadCustomerQuote() } else { $this->getQuote()->getBillingAddress(); $this->getQuote()->getShippingAddress(); - $this->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer()) + $this->getQuote()->setCustomer($this->getCustomerSession()->getCustomer()) ->setTotalsCollectedFlag(false) ->collectTotals() ->save(); diff --git a/app/code/core/Mage/Checkout/Model/Type/Abstract.php b/app/code/core/Mage/Checkout/Model/Type/Abstract.php index 7d03fad0f8e..56e3b4a01fd 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Abstract.php +++ b/app/code/core/Mage/Checkout/Model/Type/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Checkout_Model_Type_Abstract extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Retrieve checkout session model * @@ -66,7 +68,7 @@ public function getCustomerSession() { $customer = $this->getData('customer_session'); if (is_null($customer)) { - $customer = Mage::getSingleton('customer/session'); + $customer = $this->getCustomerSession(); $this->setData('customer_session', $customer); } return $customer; diff --git a/app/code/core/Mage/Checkout/Model/Type/Multishipping.php b/app/code/core/Mage/Checkout/Model/Type/Multishipping.php index 87d196cddbf..c9469f2e9c3 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Multishipping.php +++ b/app/code/core/Mage/Checkout/Model/Type/Multishipping.php @@ -519,8 +519,8 @@ public function createOrders() $orderIds[$order->getId()] = $order->getIncrementId(); } - Mage::getSingleton('core/session')->setOrderIds($orderIds); - Mage::getSingleton('checkout/session')->setLastQuoteId($this->getQuote()->getId()); + $this->getCoreSession()->setOrderIds($orderIds); + $this->getCheckoutSession()->setLastQuoteId($this->getQuote()->getId()); $this->getQuote() ->setIsActive(false) @@ -617,7 +617,7 @@ public function isCheckoutAvailable() */ public function getOrderIds($asAssoc = false) { - $idsAssoc = Mage::getSingleton('core/session')->getOrderIds(); + $idsAssoc = $this->getCoreSession()->getOrderIds(); return $asAssoc ? $idsAssoc : array_keys($idsAssoc); } } diff --git a/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php b/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php index eca1e327c10..a1dd79df81a 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php +++ b/app/code/core/Mage/Checkout/Model/Type/Multishipping/State.php @@ -22,6 +22,8 @@ */ class Mage_Checkout_Model_Type_Multishipping_State extends Varien_Object { + use Mage_Core_Trait_Session; + public const STEP_SELECT_ADDRESSES = 'multishipping_addresses'; public const STEP_SHIPPING = 'multishipping_shipping'; public const STEP_BILLING = 'multishipping_billing'; @@ -180,14 +182,4 @@ public function canInputShipping() {} public function canSeeOverview() {} public function canSuccess() {} - - /** - * Retrieve checkout session - * - * @return Mage_Checkout_Model_Session - */ - public function getCheckoutSession() - { - return Mage::getSingleton('checkout/session'); - } } diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 3ff917162cb..53d5a2cc12e 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -22,6 +22,8 @@ */ class Mage_Checkout_Model_Type_Onepage { + use Mage_Core_Trait_Session; + /** * Checkout types: Checkout as Guest, Register, Logged In Customer */ @@ -64,8 +66,8 @@ public function __construct() { $this->_helper = Mage::helper('checkout'); $this->_customerEmailExistsMessage = Mage::helper('checkout')->__('There is already a customer registered using this email address. Please login using this email address or enter a different email address to register your account.'); - $this->_checkoutSession = Mage::getSingleton('checkout/session'); - $this->_customerSession = Mage::getSingleton('customer/session'); + $this->_checkoutSession = $this->getCheckoutSession(); + $this->_customerSession = $this->getCustomerSession(); } /** diff --git a/app/code/core/Mage/Checkout/controllers/CartController.php b/app/code/core/Mage/Checkout/controllers/CartController.php index a987bf157ab..f57b6c3b802 100644 --- a/app/code/core/Mage/Checkout/controllers/CartController.php +++ b/app/code/core/Mage/Checkout/controllers/CartController.php @@ -43,10 +43,12 @@ protected function _getCart() * Get checkout session model instance * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getSession() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** @@ -137,10 +139,10 @@ public function indexAction() if ($cart->getQuote()->getItemsCount()) { $cart->init(); if ($cart->getQuote()->getShippingAddress() - && $this->_getSession()->getEstimatedShippingAddressData() - && $couponCode = $this->_getSession()->getCartCouponCode() + && $this->getCheckoutSession()->getEstimatedShippingAddressData() + && $couponCode = $this->getCheckoutSession()->getCartCouponCode() ) { - $estimatedSessionAddressData = $this->_getSession()->getEstimatedShippingAddressData(); + $estimatedSessionAddressData = $this->getCheckoutSession()->getEstimatedShippingAddressData(); $cart->getQuote()->getShippingAddress() ->setCountryId($estimatedSessionAddressData['country_id']) ->setCity($estimatedSessionAddressData['city']) @@ -178,13 +180,13 @@ public function indexAction() * if customer enteres shopping cart we should mark quote * as modified bc he can has checkout page in another window. */ - $this->_getSession()->setCartWasUpdated(true); + $this->getCheckoutSession()->setCartWasUpdated(true); Varien_Profiler::start(__METHOD__ . 'cart_display'); $this ->loadLayout() - ->_initLayoutMessages('checkout/session') - ->_initLayoutMessages('catalog/session') + ->_initLayoutMessages($this->getCheckoutSessionStorage()) + ->_initLayoutMessages($this->getCatalogSessionStorage()) ->getLayout()->getBlock('head')->setTitle($this->__('Shopping Cart')); $this->renderLayout(); Varien_Profiler::stop(__METHOD__ . 'cart_display'); @@ -239,24 +241,24 @@ public function addAction() ['product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()], ); - if (!$this->_getSession()->getNoCartRedirect(true)) { + if (!$this->getCheckoutSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName())); - $this->_getSession()->addSuccess($message); + $this->getCheckoutSession()->addSuccess($message); } $this->_goBack(); } } catch (Mage_Core_Exception $e) { - if ($this->_getSession()->getUseNotice(true)) { - $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage())); + if ($this->getCheckoutSession()->getUseNotice(true)) { + $this->getCheckoutSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage())); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { - $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message, ['em'])); + $this->getCheckoutSession()->addError(Mage::helper('core')->escapeHtml($message, ['em'])); } } - $url = $this->_getSession()->getRedirectUrl(true); + $url = $this->getCheckoutSession()->getRedirectUrl(true); if ($url) { $this->_setProductBuyRequest(); $this->getResponse()->setRedirect($url); @@ -265,7 +267,7 @@ public function addAction() } } catch (Exception $e) { $this->_setProductBuyRequest(); - $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.')); + $this->getCheckoutSession()->addException($e, $this->__('Cannot add the item to shopping cart.')); $this->_goBack(); } } @@ -276,7 +278,7 @@ public function addAction() public function addgroupAction() { $orderItemIds = $this->getRequest()->getParam('order_items', []); - $customerId = $this->_getCustomerSession()->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); if (!is_array($orderItemIds) || !$this->_validateFormKey() || !$customerId) { $this->_goBack(); @@ -294,18 +296,18 @@ public function addgroupAction() try { $cart->addOrderItem($item, 1); } catch (Mage_Core_Exception $e) { - if ($this->_getSession()->getUseNotice(true)) { - $this->_getSession()->addNotice($e->getMessage()); + if ($this->getCheckoutSession()->getUseNotice(true)) { + $this->getCheckoutSession()->addNotice($e->getMessage()); } else { - $this->_getSession()->addError($e->getMessage()); + $this->getCheckoutSession()->addError($e->getMessage()); } } catch (Exception $e) { - $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.')); + $this->getCheckoutSession()->addException($e, $this->__('Cannot add the item to shopping cart.')); $this->_goBack(); } } $cart->save(); - $this->_getSession()->setCartWasUpdated(true); + $this->getCheckoutSession()->setCartWasUpdated(true); $this->_goBack(); } @@ -323,7 +325,7 @@ public function configureAction() } if (!$quoteItem) { - $this->_getSession()->addError($this->__('Quote item is not found.')); + $this->getCheckoutSession()->addError($this->__('Quote item is not found.')); $this->_redirect('checkout/cart'); return; } @@ -388,30 +390,30 @@ public function updateItemOptionsAction() $cart->save(); - $this->_getSession()->setCartWasUpdated(true); + $this->getCheckoutSession()->setCartWasUpdated(true); Mage::dispatchEvent( 'checkout_cart_update_item_complete', ['item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse()], ); - if (!$this->_getSession()->getNoCartRedirect(true)) { + if (!$this->getCheckoutSession()->getNoCartRedirect(true)) { if (!$cart->getQuote()->getHasError()) { $message = $this->__('%s was updated in your shopping cart.', Mage::helper('core')->escapeHtml($item->getProduct()->getName())); - $this->_getSession()->addSuccess($message); + $this->getCheckoutSession()->addSuccess($message); } $this->_goBack(); } } catch (Mage_Core_Exception $e) { - if ($this->_getSession()->getUseNotice(true)) { - $this->_getSession()->addNotice($e->getMessage()); + if ($this->getCheckoutSession()->getUseNotice(true)) { + $this->getCheckoutSession()->addNotice($e->getMessage()); } else { $messages = array_unique(explode("\n", $e->getMessage())); foreach ($messages as $message) { - $this->_getSession()->addError($message); + $this->getCheckoutSession()->addError($message); } } - $url = $this->_getSession()->getRedirectUrl(true); + $url = $this->getCheckoutSession()->getRedirectUrl(true); if ($url) { $this->getResponse()->setRedirect($url); } else { @@ -419,7 +421,7 @@ public function updateItemOptionsAction() } } catch (Exception $e) { $this->_setProductBuyRequest(); - $this->_getSession()->addException($e, $this->__('Cannot update the item.')); + $this->getCheckoutSession()->addException($e, $this->__('Cannot update the item.')); $this->_goBack(); } $this->_redirect('*/*'); @@ -476,11 +478,11 @@ protected function _updateShoppingCart() $cart->updateItems($cartData) ->save(); } - $this->_getSession()->setCartWasUpdated(true); + $this->getCheckoutSession()->setCartWasUpdated(true); } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError(Mage::helper('core')->escapeHtml($e->getMessage())); + $this->getCheckoutSession()->addError(Mage::helper('core')->escapeHtml($e->getMessage())); } catch (Exception $e) { - $this->_getSession()->addException($e, $this->__('Cannot update shopping cart.')); + $this->getCheckoutSession()->addException($e, $this->__('Cannot update shopping cart.')); } } @@ -491,11 +493,11 @@ protected function _emptyShoppingCart() { try { $this->_getCart()->truncate()->save(); - $this->_getSession()->setCartWasUpdated(true); + $this->getCheckoutSession()->setCartWasUpdated(true); } catch (Mage_Core_Exception $exception) { - $this->_getSession()->addError($exception->getMessage()); + $this->getCheckoutSession()->addError($exception->getMessage()); } catch (Exception $exception) { - $this->_getSession()->addException($exception, $this->__('Cannot update shopping cart.')); + $this->getCheckoutSession()->addException($exception, $this->__('Cannot update shopping cart.')); } } @@ -511,12 +513,12 @@ public function deleteAction() $this->_getCart()->removeItem($id) ->save(); } catch (Exception $e) { - $this->_getSession()->addError($this->__('Cannot remove the item.')); + $this->getCheckoutSession()->addError($this->__('Cannot remove the item.')); Mage::logException($e); } } } else { - $this->_getSession()->addError($this->__('Cannot remove the item.')); + $this->getCheckoutSession()->addError($this->__('Cannot remove the item.')); } $this->_redirectReferer(Mage::getUrl('*/*')); @@ -549,7 +551,7 @@ public function estimatePostAction() ->setRegion($region) ->setCollectShippingRates(true); $this->_getQuote()->save(); - $this->_getSession()->setEstimatedShippingAddressData([ + $this->getCheckoutSession()->setEstimatedShippingAddressData([ 'country_id' => $country, 'postcode' => $postcode, 'city' => $city, @@ -606,23 +608,23 @@ public function couponPostAction() if ($codeLength) { if ($isCodeLengthValid && $couponCode == $this->_getQuote()->getCouponCode()) { - $this->_getSession()->addSuccess( + $this->getCheckoutSession()->addSuccess( $this->__('Coupon code "%s" was applied.', Mage::helper('core')->escapeHtml($couponCode)), ); - $this->_getSession()->setCartCouponCode($couponCode); + $this->getCheckoutSession()->setCartCouponCode($couponCode); } else { - $this->_getSession()->addError( + $this->getCheckoutSession()->addError( $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->escapeHtml($couponCode)), ); } } else { - $this->_getSession()->setCartCouponCode(''); - $this->_getSession()->addSuccess($this->__('Coupon code was canceled.')); + $this->getCheckoutSession()->setCartCouponCode(''); + $this->getCheckoutSession()->addSuccess($this->__('Coupon code was canceled.')); } } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError($e->getMessage()); + $this->getCheckoutSession()->addError($e->getMessage()); } catch (Exception $e) { - $this->_getSession()->addError($this->__('Cannot apply the coupon code.')); + $this->getCheckoutSession()->addError($this->__('Cannot apply the coupon code.')); Mage::logException($e); } @@ -718,10 +720,12 @@ public function ajaxUpdateAction() * Get customer session model * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getCustomerSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** @@ -732,6 +736,6 @@ protected function _setProductBuyRequest(): void { $buyRequest = $this->getRequest()->getPost(); $buyRequestObject = new Varien_Object($buyRequest); - $this->_getSession()->setProductBuyRequest($buyRequestObject); + $this->getCheckoutSession()->setProductBuyRequest($buyRequestObject); } } diff --git a/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php b/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php index 7681b1c0db4..59978bd5175 100644 --- a/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php +++ b/app/code/core/Mage/Checkout/controllers/Multishipping/AddressController.php @@ -49,7 +49,7 @@ public function newShippingAction() { $this->_getState()->setActiveStep(Mage_Checkout_Model_Type_Multishipping_State::STEP_SELECT_ADDRESSES); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); if ($addressForm = $this->getLayout()->getBlock('customer_address_edit')) { $addressForm->setTitle(Mage::helper('checkout')->__('Create Shipping Address')) ->setSuccessUrl(Mage::getUrl('*/*/shippingSaved')) @@ -83,7 +83,7 @@ public function editShippingAction() { $this->_getState()->setActiveStep(Mage_Checkout_Model_Type_Multishipping_State::STEP_SHIPPING); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); if ($addressForm = $this->getLayout()->getBlock('customer_address_edit')) { $addressForm->setTitle(Mage::helper('checkout')->__('Edit Shipping Address')) ->setSuccessUrl(Mage::getUrl('*/*/editShippingPost', ['id' => $this->getRequest()->getParam('id')])) @@ -113,15 +113,15 @@ public function selectBillingAction() { $this->_getState()->setActiveStep(Mage_Checkout_Model_Type_Multishipping_State::STEP_BILLING); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->renderLayout(); } public function newBillingAction() { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); if ($addressForm = $this->getLayout()->getBlock('customer_address_edit')) { $addressForm->setTitle(Mage::helper('checkout')->__('Create Billing Address')) ->setSuccessUrl(Mage::getUrl('*/*/selectBilling')) @@ -138,7 +138,7 @@ public function newBillingAction() public function editAddressAction() { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); if ($addressForm = $this->getLayout()->getBlock('customer_address_edit')) { $addressForm->setTitle(Mage::helper('checkout')->__('Edit Address')) ->setSuccessUrl(Mage::getUrl('*/*/selectBilling')) @@ -158,7 +158,7 @@ public function editBillingAction() Mage_Checkout_Model_Type_Multishipping_State::STEP_BILLING, ); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); if ($addressForm = $this->getLayout()->getBlock('customer_address_edit')) { $addressForm->setTitle(Mage::helper('checkout')->__('Edit Billing Address')) ->setSuccessUrl(Mage::getUrl('*/*/saveBilling', ['id' => $this->getRequest()->getParam('id')])) diff --git a/app/code/core/Mage/Checkout/controllers/MultishippingController.php b/app/code/core/Mage/Checkout/controllers/MultishippingController.php index 0351a2d811c..e28bc8e992a 100644 --- a/app/code/core/Mage/Checkout/controllers/MultishippingController.php +++ b/app/code/core/Mage/Checkout/controllers/MultishippingController.php @@ -56,10 +56,12 @@ protected function _getHelper() * Retrieve checkout session * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckoutSession() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** @@ -100,7 +102,7 @@ public function preDispatch() } if (!in_array($action, ['login', 'register'])) { - if (!Mage::getSingleton('customer/session')->authenticate($this, $this->_getHelper()->getMSLoginUrl())) { + if (!$this->getCustomerSession()->authenticate($this, $this->_getHelper()->getMSLoginUrl())) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); } @@ -152,13 +154,13 @@ public function indexAction() */ public function loginAction() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $this->_redirect('*/*/'); return; } $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); // set account create url if ($loginForm = $this->getLayout()->getBlock('customer_form_login')) { @@ -172,13 +174,13 @@ public function loginAction() */ public function registerAction() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $this->_redirectUrl($this->_getHelper()->getMSCheckoutUrl()); return; } $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); if ($registerForm = $this->getLayout()->getBlock('customer_form_register')) { $registerForm->setShowAddressFields(true) @@ -213,8 +215,8 @@ public function addressesAction() $this->_getCheckout()->getCheckoutSession()->addNotice($message); } $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->renderLayout(); } @@ -325,8 +327,8 @@ public function shippingAction() Mage_Checkout_Model_Type_Multishipping_State::STEP_SHIPPING, ); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->renderLayout(); } @@ -420,8 +422,8 @@ public function billingAction() ); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->renderLayout(); } @@ -483,8 +485,8 @@ public function overviewAction() ); $this->loadLayout(); - $this->_initLayoutMessages('checkout/session'); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->renderLayout(); } catch (Mage_Core_Exception $e) { $this->_getCheckoutSession()->addError($e->getMessage()); @@ -575,7 +577,7 @@ public function successAction() } $this->loadLayout(); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $ids = $this->_getCheckout()->getOrderIds(); Mage::dispatchEvent('checkout_multishipping_controller_success_action', ['order_ids' => $ids]); $this->renderLayout(); @@ -587,7 +589,7 @@ public function successAction() public function redirectLogin() { $this->setFlag('', 'no-dispatch', true); - Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*', ['_secure' => true])); + $this->getCustomerSession()->setBeforeAuthUrl(Mage::getUrl('*/*', ['_secure' => true])); $this->getResponse()->setRedirect( Mage::helper('core/url')->addRequestParam( diff --git a/app/code/core/Mage/Checkout/controllers/OnepageController.php b/app/code/core/Mage/Checkout/controllers/OnepageController.php index f50e158520b..959eda1d2ee 100644 --- a/app/code/core/Mage/Checkout/controllers/OnepageController.php +++ b/app/code/core/Mage/Checkout/controllers/OnepageController.php @@ -51,7 +51,7 @@ public function preDispatch() // Disable flat for product collection Mage::helper('catalog/product_flat')->disableFlatCollection(true); - $checkoutSessionQuote = Mage::getSingleton('checkout/session')->getQuote(); + $checkoutSessionQuote = $this->getCheckoutSession()->getQuote(); if ($checkoutSessionQuote->getIsMultiShipping()) { $checkoutSessionQuote->setIsMultiShipping(false); $checkoutSessionQuote->removeAllAddresses(); @@ -95,7 +95,7 @@ protected function _expireAjax() return true; } $action = strtolower($this->getRequest()->getActionName()); - if (Mage::getSingleton('checkout/session')->getCartWasUpdated(true) + if ($this->getCheckoutSession()->getCartWasUpdated(true) && !in_array($action, ['index', 'progress']) ) { $this->_ajaxRedirectResponse(); @@ -178,7 +178,7 @@ public function getOnepage() public function indexAction() { if (!Mage::helper('checkout')->canOnepageCheckout()) { - Mage::getSingleton('checkout/session')->addError($this->__('The onepage checkout is disabled.')); + $this->getCheckoutSession()->addError($this->__('The onepage checkout is disabled.')); $this->_redirect('checkout/cart'); return; } @@ -192,15 +192,15 @@ public function indexAction() Mage::getStoreConfig('sales/minimum_order/error_message') : Mage::helper('checkout')->__('Subtotal must exceed minimum order amount'); - Mage::getSingleton('checkout/session')->addError($error); + $this->getCheckoutSession()->addError($error); $this->_redirect('checkout/cart'); return; } - Mage::getSingleton('checkout/session')->setCartWasUpdated(false); - Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', ['_secure' => true])); + $this->getCheckoutSession()->setCartWasUpdated(false); + $this->getCustomerSession()->setBeforeAuthUrl(Mage::getUrl('*/*/*', ['_secure' => true])); $this->getOnepage()->initCheckout(); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $this->getLayout()->getBlock('head')->setTitle($this->__('Checkout')); $this->renderLayout(); } @@ -280,7 +280,7 @@ public function successAction() $session->clear(); $this->loadLayout(); - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); Mage::dispatchEvent('checkout_onepage_controller_success_action', ['order_ids' => [$lastOrderId]]); $this->renderLayout(); } @@ -322,7 +322,7 @@ public function getAddressAction() if ($addressId) { $address = $this->getOnepage()->getAddress($addressId); - if (Mage::getSingleton('customer/session')->getCustomer()->getId() == $address->getCustomerId()) { + if ($this->getCustomerSession()->getCustomer()->getId() == $address->getCustomerId()) { $this->_prepareDataJSON($address->toArray()); } else { $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden'); @@ -663,7 +663,7 @@ protected function _filterPostData($data) */ protected function _canShowForUnregisteredUsers() { - return Mage::getSingleton('customer/session')->isLoggedIn() + return $this->getCustomerSession()->isLoggedIn() || $this->getRequest()->getActionName() == 'index' || Mage::helper('checkout')->isAllowedGuestCheckout($this->getOnepage()->getQuote()) || !Mage::helper('checkout')->isCustomerMustBeLogged(); diff --git a/app/code/core/Mage/Cms/Model/Resource/Page.php b/app/code/core/Mage/Cms/Model/Resource/Page.php index 5502c03afcf..8b11deec59f 100644 --- a/app/code/core/Mage/Cms/Model/Resource/Page.php +++ b/app/code/core/Mage/Cms/Model/Resource/Page.php @@ -85,7 +85,7 @@ protected function _beforeSave(Mage_Core_Model_Abstract $object) $isUsedInConfig = $this->getUsedInStoreConfigCollection($object); if ($isUsedInConfig->count()) { $object->setIsActive(true); - Mage::getSingleton('adminhtml/session')->addWarning( + $this->getAdminhtmlSession()->addWarning( Mage::helper('cms')->__( 'Cannot disable page, it is used in configuration "%s".', implode(', ', $isUsedInConfig->getColumnValues('path')), diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php index 194ab470de5..3b7568e9e29 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Config.php @@ -25,6 +25,8 @@ */ class Mage_Cms_Model_Wysiwyg_Config extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Wysiwyg behaviour: enabled */ @@ -79,8 +81,8 @@ public function getConfig($data = []) 'hidden' => $this->isHidden(), 'skin' => Mage::getStoreConfig('cms/wysiwyg/skin'), 'use_container' => false, - 'add_variables' => Mage::getSingleton('admin/session')->isAllowed('system/variable'), - 'add_widgets' => Mage::getSingleton('admin/session')->isAllowed('cms/widget_instance'), + 'add_variables' => $this->getAdminSession()->isAllowed('system/variable'), + 'add_widgets' => $this->getAdminSession()->isAllowed('cms/widget_instance'), 'no_display' => false, 'translator' => Mage::helper('cms'), 'encode_directives' => true, @@ -91,7 +93,7 @@ public function getConfig($data = []) ]); $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url'))); - if (Mage::getSingleton('admin/session')->isAllowed('cms/media_gallery')) { + if ($this->getAdminSession()->isAllowed('cms/media_gallery')) { $config->addData([ 'add_images' => true, 'files_browser_window_url' => Mage::getSingleton('adminhtml/url')->getUrl('*/cms_wysiwyg_images/index'), diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php index 10039d135d4..4373327f7e3 100644 --- a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php +++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php @@ -22,6 +22,8 @@ */ class Mage_Cms_Model_Wysiwyg_Images_Storage extends Varien_Object { + use Mage_Core_Trait_Session; + public const DIRECTORY_NAME_REGEXP = '/^[a-z0-9\-\_]+$/si'; public const THUMBS_DIRECTORY_NAME = '.thumbs'; public const THUMB_PLACEHOLDER_PATH_SUFFIX = 'images/placeholder/thumbnail.jpg'; @@ -441,10 +443,12 @@ public function getHelper() * Storage session * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ public function getSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } /** diff --git a/app/code/core/Mage/Contacts/Helper/Data.php b/app/code/core/Mage/Contacts/Helper/Data.php index eee137c3cb9..7696b1685ae 100644 --- a/app/code/core/Mage/Contacts/Helper/Data.php +++ b/app/code/core/Mage/Contacts/Helper/Data.php @@ -39,10 +39,10 @@ public function isEnabled() */ public function getUserName() { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { return ''; } - $customer = Mage::getSingleton('customer/session')->getCustomer(); + $customer = $this->getCustomerSession()->getCustomer(); return trim($customer->getName()); } @@ -51,10 +51,10 @@ public function getUserName() */ public function getUserEmail() { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { return ''; } - $customer = Mage::getSingleton('customer/session')->getCustomer(); + $customer = $this->getCustomerSession()->getCustomer(); return $customer->getEmail(); } } diff --git a/app/code/core/Mage/Contacts/controllers/IndexController.php b/app/code/core/Mage/Contacts/controllers/IndexController.php index 97421d62f5a..d53822d099c 100644 --- a/app/code/core/Mage/Contacts/controllers/IndexController.php +++ b/app/code/core/Mage/Contacts/controllers/IndexController.php @@ -48,8 +48,8 @@ public function indexAction() $this->getLayout()->getBlock('contactForm') ->setFormAction(Mage::getUrl('*/*/post', ['_secure' => $this->getRequest()->isSecure()])); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $this->renderLayout(); } @@ -111,14 +111,14 @@ public function postAction() } $translate->setTranslateInline(true); - Mage::getSingleton('customer/session')->addSuccess($this->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.')); + $this->getCustomerSession()->addSuccess($this->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.')); } catch (Mage_Core_Exception $e) { $translate->setTranslateInline(true); Mage::logException($e); - Mage::getSingleton('customer/session')->addError($e->getMessage()); + $this->getCustomerSession()->addError($e->getMessage()); } catch (Exception $e) { Mage::logException($e); - Mage::getSingleton('customer/session')->addError($this->__('Unable to submit your request. Please, try again later')); + $this->getCustomerSession()->addError($this->__('Unable to submit your request. Please, try again later')); } } diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 2477a32543e..7179a269cdd 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -39,6 +39,8 @@ */ abstract class Mage_Core_Block_Abstract extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Prefix for cache key */ @@ -53,6 +55,11 @@ abstract class Mage_Core_Block_Abstract extends Varien_Object */ public const CACHE_TAGS_DATA_KEY = 'cache_tags'; + public const SESSION_CATALOG = 'catalog/session'; + public const SESSION_CHECKOUT = 'checkout/session'; + public const SESSION_CORE = 'core/session'; + public const SESSION_CUSTOMER = 'customer/session'; + /** * Block name in layout * @@ -217,6 +224,46 @@ protected function _construct() */ } + /** + * Retrieve core session model object + */ + final protected function getCatalogSession(): Mage_Catalog_Model_Session + { + /** @var Mage_Catalog_Model_Session $session */ + $session = Mage::getSingleton(self::SESSION_CATALOG); + return $session; + } + + /** + * Retrieve core session model object + */ + final protected function getCheckoutSession(): Mage_Checkout_Model_Session + { + /** @var Mage_Checkout_Model_Session $session */ + $session = Mage::getSingleton(self::SESSION_CHECKOUT); + return $session; + } + + /** + * Retrieve core session model object + */ + final protected function getCoreSession(): Mage_Core_Model_Session + { + /** @var Mage_Core_Model_Session $session */ + $session = Mage::getSingleton(self::SESSION_CORE); + return $session; + } + + /** + * Retrieve core session model object + */ + final protected function getCustomerSession(): Mage_Customer_Model_Session + { + /** @var Mage_Customer_Model_Session $session */ + $session = Mage::getSingleton(self::SESSION_CUSTOMER); + return $session; + } + /** * Retrieve factory instance * @@ -1461,7 +1508,7 @@ public function getCacheLifetime() */ public function getFormKey() { - return Mage::getSingleton('core/session')->getFormKey(); + return $this->getCoreSession()->getFormKey(); } /** @@ -1475,8 +1522,7 @@ protected function _loadCache() return false; } $cacheKey = $this->getCacheKey(); - /** @var Mage_Core_Model_Session $session */ - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); $cacheData = $this->_getApp()->loadCache($cacheKey); if ($cacheData) { $cacheData = str_replace( @@ -1500,8 +1546,7 @@ protected function _saveCache($data) return false; } $cacheKey = $this->getCacheKey(); - /** @var Mage_Core_Model_Session $session */ - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); $data = str_replace( $session->getSessionIdQueryParam() . '=' . $session->getEncryptedSessionId(), $this->_getSidPlaceholder($cacheKey), diff --git a/app/code/core/Mage/Core/Block/Messages.php b/app/code/core/Mage/Core/Block/Messages.php index 4691e512270..f0a33b7a349 100644 --- a/app/code/core/Mage/Core/Block/Messages.php +++ b/app/code/core/Mage/Core/Block/Messages.php @@ -69,7 +69,7 @@ class Mage_Core_Block_Messages extends Mage_Core_Block_Template */ public function _prepareLayout() { - $this->addMessages(Mage::getSingleton('core/session')->getMessages(true)); + $this->addMessages($this->getCoreSession()->getMessages(true)); return parent::_prepareLayout(); } diff --git a/app/code/core/Mage/Core/Controller/Front/Action.php b/app/code/core/Mage/Core/Controller/Front/Action.php index 8ba40b38a25..e9e74936b90 100644 --- a/app/code/core/Mage/Core/Controller/Front/Action.php +++ b/app/code/core/Mage/Core/Controller/Front/Action.php @@ -68,7 +68,7 @@ public function postDispatch() { parent::postDispatch(); if (!$this->getFlag('', self::FLAG_NO_START_SESSION)) { - Mage::getSingleton('core/session')->setLastUrl(Mage::getUrl('*/*/*', ['_current' => true])); + $this->getCoreSession()->setLastUrl(Mage::getUrl('*/*/*', ['_current' => true])); } return $this; } @@ -105,7 +105,7 @@ protected function _prepareDownloadResponse( $contentType = 'application/octet-stream', $contentLength = null ) { - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); if ($session->isFirstPageAfterLogin()) { $this->_redirect($session->getUser()->getStartupPageUrl()); return $this; diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index 5c36b16ba40..6d40d9b833c 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -24,6 +24,8 @@ */ abstract class Mage_Core_Controller_Varien_Action { + use Mage_Core_Trait_Session; + public const FLAG_NO_CHECK_INSTALLATION = 'no-install-check'; public const FLAG_NO_DISPATCH = 'no-dispatch'; public const FLAG_NO_PRE_DISPATCH = 'no-preDispatch'; @@ -898,7 +900,7 @@ protected function _rewrite() protected function _validateFormKey() { if (!($formKey = $this->getRequest()->getParam('form_key', null)) - || $formKey != Mage::getSingleton('core/session')->getFormKey() + || $formKey != $this->getCoreSession()->getFormKey() ) { return false; } @@ -1042,7 +1044,7 @@ protected function _prepareDownloadResponse( $contentType = 'application/octet-stream', $contentLength = null ) { - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); if ($session->isFirstPageAfterLogin()) { $this->_redirect($session->getUser()->getStartupPageUrl()); return $this; diff --git a/app/code/core/Mage/Core/Helper/Abstract.php b/app/code/core/Mage/Core/Helper/Abstract.php index bf5bbc2f38a..0ddb66aaba9 100644 --- a/app/code/core/Mage/Core/Helper/Abstract.php +++ b/app/code/core/Mage/Core/Helper/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Core_Helper_Abstract { + use Mage_Core_Trait_Session; + /** * Helper module name * diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 695521a2dfb..42871d3326e 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -1026,7 +1026,7 @@ public function isRateLimitExceeded(bool $setErrorMessage = true, bool $recordRa if (Mage::app()->testCache($cacheTag)) { if ($setErrorMessage) { $errorMessage = $this->__('Too Soon: You are trying to perform this operation too frequently. Please wait a few seconds and try again.'); - Mage::getSingleton('core/session')->addError($errorMessage); + $this->getCoreSession()->addError($errorMessage); } return true; } diff --git a/app/code/core/Mage/Core/Model/Abstract.php b/app/code/core/Mage/Core/Model/Abstract.php index 208eb1aa091..249e07a071a 100644 --- a/app/code/core/Mage/Core/Model/Abstract.php +++ b/app/code/core/Mage/Core/Model/Abstract.php @@ -30,6 +30,8 @@ */ abstract class Mage_Core_Model_Abstract extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Prefix of model events names * diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php index 576c5a32476..48476875dfd 100644 --- a/app/code/core/Mage/Core/Model/Layout.php +++ b/app/code/core/Mage/Core/Model/Layout.php @@ -22,6 +22,8 @@ */ class Mage_Core_Model_Layout extends Varien_Simplexml_Config { + use Mage_Core_Trait_Session; + /** * Layout Update module * @@ -167,7 +169,7 @@ public function generateXml() continue; } $acl = (string) $attributes->acl; - if ($acl && Mage::getSingleton('admin/session')->isAllowed($acl)) { + if ($acl && $this->getAdminSession()->isAllowed($acl)) { continue; } if (!isset($block->attributes()->ignore)) { diff --git a/app/code/core/Mage/Core/Model/Observer.php b/app/code/core/Mage/Core/Model/Observer.php index 1ae6b8ae942..7d499435085 100644 --- a/app/code/core/Mage/Core/Model/Observer.php +++ b/app/code/core/Mage/Core/Model/Observer.php @@ -22,6 +22,8 @@ */ class Mage_Core_Model_Observer { + use Mage_Core_Trait_Session; + /** * Check if synchronize process is finished and generate notification message * @@ -29,7 +31,7 @@ class Mage_Core_Model_Observer */ public function addSynchronizeNotification(Varien_Event_Observer $observer) { - $adminSession = Mage::getSingleton('admin/session'); + $adminSession = $this->getAdminSession(); if (!$adminSession->hasSyncProcessStopWatch()) { $flag = Mage::getSingleton('core/file_storage')->getSyncFlag(); $state = $flag->getState(); diff --git a/app/code/core/Mage/Core/Model/Resource/Abstract.php b/app/code/core/Mage/Core/Model/Resource/Abstract.php index 55497b83026..6868227546c 100644 --- a/app/code/core/Mage/Core/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Core/Model/Resource/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Core_Model_Resource_Abstract { + use Mage_Core_Trait_Session; + /** * Main constructor */ diff --git a/app/code/core/Mage/Core/Model/Session/Abstract.php b/app/code/core/Mage/Core/Model/Session/Abstract.php index 0b8cd0ceb86..890b37a6de4 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract.php @@ -30,6 +30,8 @@ */ class Mage_Core_Model_Session_Abstract extends Mage_Core_Model_Session_Abstract_Varien { + use Mage_Core_Trait_Session; + public const XML_PATH_COOKIE_DOMAIN = 'web/cookie/cookie_domain'; public const XML_PATH_COOKIE_PATH = 'web/cookie/cookie_path'; public const XML_PATH_COOKIE_LIFETIME = 'web/cookie/cookie_lifetime'; diff --git a/app/code/core/Mage/Core/Model/Url.php b/app/code/core/Mage/Core/Model/Url.php index b1d357cfd34..4f21ca224d4 100644 --- a/app/code/core/Mage/Core/Model/Url.php +++ b/app/code/core/Mage/Core/Model/Url.php @@ -75,6 +75,8 @@ */ class Mage_Core_Model_Url extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Default controller name */ @@ -769,7 +771,7 @@ public function checkCookieDomains() { $hostArr = explode(':', $this->getRequest()->getServer('HTTP_HOST')); if ($hostArr[0] !== $this->getHost()) { - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); if (!$session->isValidForHost($this->getHost())) { if (!self::$_encryptedSessionId) { $helper = Mage::helper('core'); @@ -791,7 +793,7 @@ public function checkCookieDomains() */ public function addSessionParam() { - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); if (!self::$_encryptedSessionId) { $helper = Mage::helper('core'); @@ -1180,7 +1182,7 @@ public function useSessionIdForUrl($secure = false) public function sessionVarCallback($match) { if ($this->useSessionIdForUrl($match[2] == 'S')) { - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); /** @var Mage_Core_Model_Session $session */ return $match[1] . $session->getSessionIdQueryParam() diff --git a/app/code/core/Mage/Core/Trait/Session.php b/app/code/core/Mage/Core/Trait/Session.php new file mode 100644 index 00000000000..d3d146f86a9 --- /dev/null +++ b/app/code/core/Mage/Core/Trait/Session.php @@ -0,0 +1,298 @@ +setCurrencySymbolsData($symbolsDataArray); - Mage::getSingleton('adminhtml/session')->addSuccess( + $this->getAdminhtmlSession()->addSuccess( Mage::helper('currencysymbol')->__('Custom currency symbols were applied successfully.'), ); } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->getAdminhtmlSession()->addError($e->getMessage()); } $this->_redirectReferer(); diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard.php b/app/code/core/Mage/Customer/Block/Account/Dashboard.php index 378f33f8283..1217b564750 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard.php @@ -32,7 +32,7 @@ class Mage_Customer_Block_Account_Dashboard extends Mage_Core_Block_Template */ public function getCustomer() { - return Mage::getSingleton('customer/session')->getCustomer(); + return $this->getCustomerSession()->getCustomer(); } /** diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php index 97908fca8aa..7d77d080eed 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Address.php @@ -27,7 +27,7 @@ class Mage_Customer_Block_Account_Dashboard_Address extends Mage_Core_Block_Temp */ public function getCustomer() { - return Mage::getSingleton('customer/session')->getCustomer(); + return $this->getCustomerSession()->getCustomer(); } /** diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php index d51aaf749e4..5677f99bcda 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Hello.php @@ -25,6 +25,6 @@ class Mage_Customer_Block_Account_Dashboard_Hello extends Mage_Core_Block_Templa */ public function getCustomerName() { - return Mage::getSingleton('customer/session')->getCustomer()->getName(); + return $this->getCustomerSession()->getCustomer()->getName(); } } diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php index 44f3d23eb60..1bf2445ce89 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Info.php @@ -32,7 +32,7 @@ class Mage_Customer_Block_Account_Dashboard_Info extends Mage_Core_Block_Templat */ public function getCustomer() { - return Mage::getSingleton('customer/session')->getCustomer(); + return $this->getCustomerSession()->getCustomer(); } /** @@ -52,7 +52,7 @@ public function getSubscriptionObject() { if (is_null($this->_subscription)) { $this->_subscription = Mage::getModel('newsletter/subscriber')->loadByCustomer( - Mage::getSingleton('customer/session')->getCustomer(), + $this->getCustomerSession()->getCustomer(), ); } diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php index 1aa05e6124e..9cc5625b318 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Newsletter.php @@ -34,7 +34,7 @@ public function getSubscriptionObject() { if (is_null($this->_subscription)) { $this->_subscription = Mage::getModel('newsletter/subscriber') - ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer()); + ->loadByCustomer($this->getCustomerSession()->getCustomer()); } return $this->_subscription; } diff --git a/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php b/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php index ea320c9fbe1..5bc540c456d 100644 --- a/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php +++ b/app/code/core/Mage/Customer/Block/Account/Dashboard/Sidebar.php @@ -61,7 +61,7 @@ public function getWishlist() { if (!$this->_wishlist) { $this->_wishlist = Mage::getModel('wishlist/wishlist') - ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer()); + ->loadByCustomer($this->getCustomerSession()->getCustomer()); $this->_wishlist->getItemCollection() ->addAttributeToSelect('name') ->addAttributeToSelect('price') @@ -102,7 +102,7 @@ public function getCompareItems() if (!$this->_compareItems) { $this->_compareItems = Mage::getResourceModel('catalog/product_compare_item_collection') ->setStoreId(Mage::app()->getStore()->getId()); - $this->_compareItems->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()); + $this->_compareItems->setCustomerId($this->getCustomerSession()->getCustomerId()); $this->_compareItems ->addAttributeToSelect('name') ->useProductItem() diff --git a/app/code/core/Mage/Customer/Block/Address/Book.php b/app/code/core/Mage/Customer/Block/Address/Book.php index d783ac808a0..105aa69e66d 100644 --- a/app/code/core/Mage/Customer/Block/Address/Book.php +++ b/app/code/core/Mage/Customer/Block/Address/Book.php @@ -62,7 +62,7 @@ public function getDeleteUrl() { return $this->getUrl( 'customer/address/delete', - [Mage_Core_Model_Url::FORM_KEY => Mage::getSingleton('core/session')->getFormKey()], + [Mage_Core_Model_Url::FORM_KEY => $this->getCoreSession()->getFormKey()], ); } @@ -125,7 +125,7 @@ public function getCustomer() { $customer = $this->getData('customer'); if (is_null($customer)) { - $customer = Mage::getSingleton('customer/session')->getCustomer(); + $customer = $this->getCustomerSession()->getCustomer(); $this->setData('customer', $customer); } return $customer; diff --git a/app/code/core/Mage/Customer/Block/Address/Edit.php b/app/code/core/Mage/Customer/Block/Address/Edit.php index bdc350ebfb3..ce7d60fc9b8 100644 --- a/app/code/core/Mage/Customer/Block/Address/Edit.php +++ b/app/code/core/Mage/Customer/Block/Address/Edit.php @@ -42,7 +42,7 @@ protected function _prepareLayout() // Init address object if ($id = $this->getRequest()->getParam('id')) { $this->_address->load($id); - if ($this->_address->getCustomerId() != Mage::getSingleton('customer/session')->getCustomerId()) { + if ($this->_address->getCustomerId() != $this->getCustomerSession()->getCustomerId()) { $this->_address->setData([]); } } @@ -59,7 +59,7 @@ protected function _prepareLayout() $headBlock->setTitle($this->getTitle()); } - if ($postedData = Mage::getSingleton('customer/session')->getAddressFormData(true)) { + if ($postedData = $this->getCustomerSession()->getAddressFormData(true)) { $this->_address->addData($postedData); } return $this; @@ -151,7 +151,7 @@ public function getRegionId() */ public function getCustomerAddressCount() { - return count(Mage::getSingleton('customer/session')->getCustomer()->getAddresses()); + return count($this->getCustomerSession()->getCustomer()->getAddresses()); } /** @@ -181,7 +181,7 @@ public function canSetAsDefaultShipping() */ public function isDefaultBilling() { - $defaultBilling = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling(); + $defaultBilling = $this->getCustomerSession()->getCustomer()->getDefaultBilling(); return $this->getAddress()->getId() && $this->getAddress()->getId() == $defaultBilling; } @@ -190,7 +190,7 @@ public function isDefaultBilling() */ public function isDefaultShipping() { - $defaultShipping = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping(); + $defaultShipping = $this->getCustomerSession()->getCustomer()->getDefaultShipping(); return $this->getAddress()->getId() && $this->getAddress()->getId() == $defaultShipping; } @@ -199,7 +199,7 @@ public function isDefaultShipping() */ public function getCustomer() { - return Mage::getSingleton('customer/session')->getCustomer(); + return $this->getCustomerSession()->getCustomer(); } /** diff --git a/app/code/core/Mage/Customer/Block/Form/Login.php b/app/code/core/Mage/Customer/Block/Form/Login.php index 24ad3a8852b..7c1b9d3c236 100644 --- a/app/code/core/Mage/Customer/Block/Form/Login.php +++ b/app/code/core/Mage/Customer/Block/Form/Login.php @@ -74,7 +74,7 @@ public function getForgotPasswordUrl() public function getUsername() { if ($this->_username === -1) { - $this->_username = Mage::getSingleton('customer/session')->getUsername(true); + $this->_username = $this->getCustomerSession()->getUsername(true); } return $this->_username; } @@ -110,7 +110,7 @@ public function canShowLogin() $url = $this->getUrl('*/*/*', ['_current' => true]); } } - Mage::getSingleton('customer/session')->setBeforeAuthUrl($url); + $this->getCustomerSession()->setBeforeAuthUrl($url); return true; } diff --git a/app/code/core/Mage/Customer/Block/Form/Register.php b/app/code/core/Mage/Customer/Block/Form/Register.php index 79adfb2243f..e56eb32c065 100644 --- a/app/code/core/Mage/Customer/Block/Form/Register.php +++ b/app/code/core/Mage/Customer/Block/Form/Register.php @@ -80,7 +80,7 @@ public function getFormData() { $data = $this->getData('form_data'); if (is_null($data)) { - $formData = Mage::getSingleton('customer/session')->getCustomerFormData(true); + $formData = $this->getCustomerSession()->getCustomerFormData(true); $data = new Varien_Object(); if ($formData) { $data->addData($formData); diff --git a/app/code/core/Mage/Customer/Block/Widget/Gender.php b/app/code/core/Mage/Customer/Block/Widget/Gender.php index 13b2c8b28d3..f4acfe6a04c 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Gender.php +++ b/app/code/core/Mage/Customer/Block/Widget/Gender.php @@ -58,6 +58,6 @@ public function isRequired() */ public function getCustomer() { - return Mage::getSingleton('customer/session')->getCustomer(); + return $this->getCustomerSession()->getCustomer(); } } diff --git a/app/code/core/Mage/Customer/Block/Widget/Taxvat.php b/app/code/core/Mage/Customer/Block/Widget/Taxvat.php index 248ecec81e5..d14621ebe01 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Taxvat.php +++ b/app/code/core/Mage/Customer/Block/Widget/Taxvat.php @@ -53,6 +53,6 @@ public function isRequired() */ public function getCustomer() { - return Mage::getSingleton('customer/session')->getCustomer(); + return $this->getCustomerSession()->getCustomer(); } } diff --git a/app/code/core/Mage/Customer/Helper/Data.php b/app/code/core/Mage/Customer/Helper/Data.php index 1a4a741f5f2..6ce711a31ca 100644 --- a/app/code/core/Mage/Customer/Helper/Data.php +++ b/app/code/core/Mage/Customer/Helper/Data.php @@ -109,7 +109,7 @@ class Mage_Customer_Helper_Data extends Mage_Core_Helper_Abstract */ public function isLoggedIn() { - return Mage::getSingleton('customer/session')->isLoggedIn(); + return $this->getCustomerSession()->isLoggedIn(); } /** @@ -120,7 +120,7 @@ public function isLoggedIn() public function getCustomer() { if (empty($this->_customer)) { - $this->_customer = Mage::getSingleton('customer/session')->getCustomer(); + $this->_customer = $this->getCustomerSession()->getCustomer(); } return $this->_customer; } @@ -235,7 +235,7 @@ public function getLoginUrlParams() $referer = $this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME); if (!$referer && !Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD) - && !Mage::getSingleton('customer/session')->getNoReferer() + && !$this->getCustomerSession()->getNoReferer() ) { $referer = Mage::getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]); $referer = Mage::helper('core')->urlEncode($referer); diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 4dcf9b2c926..70c0e9264ea 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -338,7 +338,7 @@ public function setPasswordCreatedAt($time) { $this->setData('password_created_at', $time); if (session_status() === PHP_SESSION_ACTIVE) { - Mage::getSingleton('checkout/session')->setValidatorSessionRenewTimestamp($time); + $this->getCheckoutSession()->setValidatorSessionRenewTimestamp($time); } return $this; } diff --git a/app/code/core/Mage/Customer/Model/Flowpassword.php b/app/code/core/Mage/Customer/Model/Flowpassword.php index 394489bf16f..ff686a42354 100644 --- a/app/code/core/Mage/Customer/Model/Flowpassword.php +++ b/app/code/core/Mage/Customer/Model/Flowpassword.php @@ -48,7 +48,7 @@ protected function _beforeSave() */ protected function _prepareData() { - $validatorData = Mage::getSingleton('customer/session')->getValidatorData(); + $validatorData = $this->getCustomerSession()->getValidatorData(); $this->setIp($validatorData[Mage_Customer_Model_Session::VALIDATOR_REMOTE_ADDR_KEY]) ->setRequestedDate(Mage::getModel('core/date')->date()); return $this; @@ -91,7 +91,7 @@ public function checkCustomerForgotPasswordFlowEmail($email) public function checkCustomerForgotPasswordFlowIp() { $helper = Mage::helper('customer'); - $validatorData = Mage::getSingleton('customer/session')->getValidatorData(); + $validatorData = $this->getCustomerSession()->getValidatorData(); $remoteAddr = $validatorData[Mage_Customer_Model_Session::VALIDATOR_REMOTE_ADDR_KEY]; $checkForgotPasswordFlowTypes = [ Mage_Adminhtml_Model_System_Config_Source_Customer_Forgotpassword::FORGOTPASS_FLOW_IP_EMAIL, diff --git a/app/code/core/Mage/Customer/Model/Observer.php b/app/code/core/Mage/Customer/Model/Observer.php index ac863e1950b..3d32f7eaedc 100644 --- a/app/code/core/Mage/Customer/Model/Observer.php +++ b/app/code/core/Mage/Customer/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Customer */ -class Mage_Customer_Model_Observer +class Mage_Customer_Model_Observer extends Mage_Core_Model_Observer { /** * VAT ID validation processed flag code @@ -86,7 +86,7 @@ protected function _canProcessAddress($address) */ public function beforeLoadLayout($observer) { - $loggedIn = Mage::getSingleton('customer/session')->isLoggedIn(); + $loggedIn = $this->getCustomerSession()->isLoggedIn(); $observer->getEvent()->getLayout()->getUpdate() ->addHandle('customer_logged_' . ($loggedIn ? 'in' : 'out')); @@ -180,9 +180,9 @@ public function afterAddressSave($observer) ); if (!$validationMessage->getIsError()) { - Mage::getSingleton('customer/session')->addSuccess($validationMessage->getMessage()); + $this->getCustomerSession()->addSuccess($validationMessage->getMessage()); } else { - Mage::getSingleton('customer/session')->addError($validationMessage->getMessage()); + $this->getCustomerSession()->addError($validationMessage->getMessage()); } } } diff --git a/app/code/core/Mage/Customer/Model/Session.php b/app/code/core/Mage/Customer/Model/Session.php index 7bb9b6add30..be40d519d74 100644 --- a/app/code/core/Mage/Customer/Model/Session.php +++ b/app/code/core/Mage/Customer/Model/Session.php @@ -249,7 +249,7 @@ public function setCustomerAsLoggedIn($customer) { $this->setCustomer($customer); $this->renewSession(); - Mage::getSingleton('core/session')->renewFormKey(); + $this->getCoreSession()->renewFormKey(); Mage::dispatchEvent('customer_login', ['customer' => $customer]); return $this; } @@ -319,7 +319,7 @@ public function authenticate(Mage_Core_Controller_Varien_Action $action, $loginU protected function _setAuthUrl($key, $url) { $url = Mage::helper('core/url') - ->removeRequestParam($url, Mage::getSingleton('core/session')->getSessionIdQueryParam()); + ->removeRequestParam($url, $this->getCoreSession()->getSessionIdQueryParam()); // Add correct session ID to URL if needed $url = Mage::getModel('core/url')->getRebuiltUrl($url); return $this->setData($key, $url); @@ -335,7 +335,7 @@ protected function _logout() $this->setId(null); $this->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); $this->getCookie()->delete($this->getSessionName()); - Mage::getSingleton('core/session')->renewFormKey(); + $this->getCoreSession()->renewFormKey(); return $this; } @@ -369,7 +369,7 @@ public function setAfterAuthUrl($url) public function renewSession() { parent::renewSession(); - Mage::getSingleton('core/session')->unsSessionHosts(); + $this->getCoreSession()->unsSessionHosts(); return $this; } diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php index 09737e0a1cf..395b365b594 100644 --- a/app/code/core/Mage/Customer/controllers/AccountController.php +++ b/app/code/core/Mage/Customer/controllers/AccountController.php @@ -38,10 +38,12 @@ class Mage_Customer_AccountController extends Mage_Core_Controller_Front_Action * Retrieve customer session model object * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** @@ -102,8 +104,8 @@ public function postDispatch() public function indexAction() { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('customer/account_dashboard'), @@ -123,8 +125,8 @@ public function loginAction() } $this->getResponse()->setHeader('Login-Required', 'true'); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $this->getLayout()->getBlock('head')->setTitle($this->__('Customer Login')); $this->renderLayout(); } @@ -261,7 +263,7 @@ public function createAction() } $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $this->renderLayout(); } @@ -687,7 +689,7 @@ public function confirmationAction() $this->getLayout()->getBlock('accountConfirmation') ->setEmail($this->getRequest()->getParam('email', $email)); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $this->renderLayout(); } @@ -715,7 +717,7 @@ public function forgotPasswordAction() ); $this->_getSession()->unsForgottenEmail(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $this->renderLayout(); } @@ -944,8 +946,8 @@ protected function _validateResetPasswordLinkToken($customerId, $resetPasswordLi public function editAction() { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $block = $this->getLayout()->getBlock('customer_edit'); if ($block) { diff --git a/app/code/core/Mage/Customer/controllers/AddressController.php b/app/code/core/Mage/Customer/controllers/AddressController.php index 272b707ac02..ea5c6e44ba4 100644 --- a/app/code/core/Mage/Customer/controllers/AddressController.php +++ b/app/code/core/Mage/Customer/controllers/AddressController.php @@ -26,10 +26,12 @@ class Mage_Customer_AddressController extends Mage_Core_Controller_Front_Action * Retrieve customer session object * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** @@ -38,7 +40,7 @@ protected function _getSession() public function preDispatch() { parent::preDispatch(); - if (!Mage::getSingleton('customer/session')->authenticate($this)) { + if (!$this->getCustomerSession()->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); } return $this; @@ -49,10 +51,10 @@ public function preDispatch() */ public function indexAction() { - if (count($this->_getSession()->getCustomer()->getAddresses())) { + if (count($this->getCustomerSession()->getCustomer()->getAddresses())) { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $block = $this->getLayout()->getBlock('address_book'); if ($block) { @@ -80,7 +82,7 @@ public function newAction() public function formAction() { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { $navigationBlock->setActive('customer/address'); diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Abstract.php b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Abstract.php index 1c8048b4341..7d37817c2b8 100644 --- a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Abstract.php +++ b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Dataflow_Model_Convert_Adapter_Abstract extends Mage_Dataflow_Model_Convert_Container_Abstract implements Mage_Dataflow_Model_Convert_Adapter_Interface { + use Mage_Core_Trait_Session; + /** * Adapter resource instance * diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php index 67b59315400..d15b575f8dc 100644 --- a/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php +++ b/app/code/core/Mage/Dataflow/Model/Convert/Adapter/Http.php @@ -74,7 +74,7 @@ public function loadFile() $session = Mage::getModel('dataflow/session'); $session->setCreatedDate(date(Varien_Date::DATETIME_PHP_FORMAT)); $session->setDirection('import'); - $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId()); + $session->setUserId($this->getAdminSession()->getUser()->getId()); $session->save(); $sessionId = $session->getId(); $newFilename = 'import_' . $sessionId . '_' . $uploadFile; diff --git a/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php b/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php index d612e8c597f..1665ed629d7 100644 --- a/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php +++ b/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php @@ -44,7 +44,7 @@ public function load() $session = Mage::getModel('dataflow/session'); $session->setCreatedDate(date(Varien_Date::DATETIME_PHP_FORMAT)); $session->setDirection('import'); - $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId()); + $session->setUserId($this->getAdminSession()->getUser()->getId()); $session->save(); $sessionId = $session->getId(); $newFilename = 'import_' . $sessionId . '_' . $uploadFile; diff --git a/app/code/core/Mage/Downloadable/Block/Checkout/Success.php b/app/code/core/Mage/Downloadable/Block/Checkout/Success.php index a1553cf3b60..69d84f10a45 100644 --- a/app/code/core/Mage/Downloadable/Block/Checkout/Success.php +++ b/app/code/core/Mage/Downloadable/Block/Checkout/Success.php @@ -29,7 +29,7 @@ class Mage_Downloadable_Block_Checkout_Success extends Mage_Checkout_Block_Onepa */ public function getOrderHasDownloadable() { - $hasDownloadableFlag = Mage::getSingleton('checkout/session') + $hasDownloadableFlag = $this->getCheckoutSession() ->getHasDownloadableProducts(true); if (!$this->isOrderVisible()) { return false; @@ -37,7 +37,7 @@ public function getOrderHasDownloadable() /** * if use guest checkout */ - if (!Mage::getSingleton('customer/session')->getCustomerId()) { + if (!$this->getCustomerSession()->getCustomerId()) { return false; } return $hasDownloadableFlag; diff --git a/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php b/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php index d4028d7a436..6413c799a89 100644 --- a/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php +++ b/app/code/core/Mage/Downloadable/Block/Customer/Products/List.php @@ -35,7 +35,7 @@ class Mage_Downloadable_Block_Customer_Products_List extends Mage_Core_Block_Tem public function __construct() { parent::__construct(); - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); $purchased = Mage::getResourceModel('downloadable/link_purchased_collection') ->addFieldToFilter('customer_id', $session->getCustomerId()) ->addOrder('created_at', 'desc'); diff --git a/app/code/core/Mage/Downloadable/Model/Observer.php b/app/code/core/Mage/Downloadable/Model/Observer.php index d5c2df05442..334fcea3e8e 100644 --- a/app/code/core/Mage/Downloadable/Model/Observer.php +++ b/app/code/core/Mage/Downloadable/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Downloadable */ -class Mage_Downloadable_Model_Observer +class Mage_Downloadable_Model_Observer extends Mage_Core_Model_Observer { public const XML_PATH_DISABLE_GUEST_CHECKOUT = 'catalog/downloadable/disable_guest_checkout'; @@ -129,7 +129,7 @@ public function saveDownloadableOrderItem(Varien_Event_Observer $observer) */ public function setHasDownloadableProducts($observer) { - $session = Mage::getSingleton('checkout/session'); + $session = $this->getCheckoutSession(); if (!$session->getHasDownloadableProducts()) { /** @var Mage_Sales_Model_Order $order */ $order = $observer->getEvent()->getOrder(); diff --git a/app/code/core/Mage/Downloadable/controllers/CustomerController.php b/app/code/core/Mage/Downloadable/controllers/CustomerController.php index 9746f4d4bfc..46822d61569 100644 --- a/app/code/core/Mage/Downloadable/controllers/CustomerController.php +++ b/app/code/core/Mage/Downloadable/controllers/CustomerController.php @@ -31,7 +31,7 @@ public function preDispatch() $loginUrl = Mage::helper('customer')->getLoginUrl(); - if (!Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) { + if (!$this->getCustomerSession()->authenticate($this, $loginUrl)) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); } return $this; @@ -43,7 +43,7 @@ public function preDispatch() public function productsAction() { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); if ($block = $this->getLayout()->getBlock('downloadable_customer_products_list')) { $block->setRefererUrl($this->_getRefererUrl()); } diff --git a/app/code/core/Mage/Downloadable/controllers/DownloadController.php b/app/code/core/Mage/Downloadable/controllers/DownloadController.php index 2e969e3a32c..a2587698fbb 100644 --- a/app/code/core/Mage/Downloadable/controllers/DownloadController.php +++ b/app/code/core/Mage/Downloadable/controllers/DownloadController.php @@ -26,20 +26,24 @@ class Mage_Downloadable_DownloadController extends Mage_Core_Controller_Front_Ac * Return core session object * * @return Mage_Core_Model_Session + * @deprecated + * @see getCoreSession() */ protected function _getSession() { - return Mage::getSingleton('core/session'); + return $this->getCoreSession(); } /** * Return customer session object * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getCustomerSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** diff --git a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php index 5e2b41da7e2..4b85a86ca65 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Eav_Model_Entity_Collection_Abstract extends Varien_Data_Collection_Db { + use Mage_Core_Trait_Session; + /** * Array of items with item id key * diff --git a/app/code/core/Mage/GiftMessage/Block/Message/Inline.php b/app/code/core/Mage/GiftMessage/Block/Message/Inline.php index 57d9bb4e552..50b3c9765bd 100644 --- a/app/code/core/Mage/GiftMessage/Block/Message/Inline.php +++ b/app/code/core/Mage/GiftMessage/Block/Message/Inline.php @@ -108,8 +108,8 @@ protected function _initMessage() */ public function getDefaultFrom() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - return Mage::getSingleton('customer/session')->getCustomer()->getName(); + if ($this->getCustomerSession()->isLoggedIn()) { + return $this->getCustomerSession()->getCustomer()->getName(); } else { return $this->getEntity()->getBillingAddress()->getName(); } diff --git a/app/code/core/Mage/GoogleAnalytics/Block/Ga.php b/app/code/core/Mage/GoogleAnalytics/Block/Ga.php index 336fee12a96..a867971ea3d 100644 --- a/app/code/core/Mage/GoogleAnalytics/Block/Ga.php +++ b/app/code/core/Mage/GoogleAnalytics/Block/Ga.php @@ -66,8 +66,8 @@ protected function _getPageTrackingCodeAnalytics4($accountId) } //add user_id - if ($this->helper('googleanalytics')->isUserIdEnabled() && Mage::getSingleton('customer/session')->isLoggedIn()) { - $customer = Mage::getSingleton('customer/session')->getCustomer(); + if ($this->helper('googleanalytics')->isUserIdEnabled() && $this->getCustomerSession()->isLoggedIn()) { + $customer = $this->getCustomerSession()->getCustomer(); $trackingCode .= " gtag('set', 'user_id', '{$customer->getId()}'); "; @@ -139,7 +139,7 @@ protected function _getEnhancedEcommerceDataForAnalytics4() * * @link https://developers.google.com/tag-platform/gtagjs/reference/events#remove_from_cart */ - $removedProducts = Mage::getSingleton('core/session')->getRemovedProductsForAnalytics(); + $removedProducts = $this->getCoreSession()->getRemovedProductsForAnalytics(); if ($removedProducts) { foreach ($removedProducts as $removedProduct) { $eventData = []; @@ -157,7 +157,7 @@ protected function _getEnhancedEcommerceDataForAnalytics4() $eventData['items'][] = $_item; $result[] = ['remove_from_cart', $eventData]; } - Mage::getSingleton('core/session')->unsRemovedProductsForAnalytics(); + $this->getCoreSession()->unsRemovedProductsForAnalytics(); } /** @@ -165,7 +165,7 @@ protected function _getEnhancedEcommerceDataForAnalytics4() * * @link https://developers.google.com/tag-platform/gtagjs/reference/events#add_to_cart */ - $addedProducts = Mage::getSingleton('core/session')->getAddedProductsForAnalytics(); + $addedProducts = $this->getCoreSession()->getAddedProductsForAnalytics(); if ($addedProducts) { foreach ($addedProducts as $_addedProduct) { $eventData = []; @@ -182,7 +182,7 @@ protected function _getEnhancedEcommerceDataForAnalytics4() ]; $eventData['items'][] = $_item; $result[] = ['add_to_cart', $eventData]; - Mage::getSingleton('core/session')->unsAddedProductsForAnalytics(); + $this->getCoreSession()->unsAddedProductsForAnalytics(); } } @@ -251,7 +251,7 @@ protected function _getEnhancedEcommerceDataForAnalytics4() } elseif ($moduleName == 'checkout' && $controllerName == 'cart') { // This event signifies that a user viewed his cart. // @see https://developers.google.com/tag-platform/gtagjs/reference/events#view_cart - $productCollection = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); + $productCollection = $this->getCheckoutSession()->getQuote()->getAllItems(); $eventData = []; $eventData['currency'] = Mage::app()->getStore()->getCurrentCurrencyCode(); $eventData['value'] = 0.00; @@ -283,7 +283,7 @@ protected function _getEnhancedEcommerceDataForAnalytics4() } elseif ($moduleName == static::CHECKOUT_MODULE_NAME && $controllerName == static::CHECKOUT_CONTROLLER_NAME) { // This event signifies that a user has begun a checkout. // @see https://developers.google.com/tag-platform/gtagjs/reference/events#begin_checkout - $productCollection = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); + $productCollection = $this->getCheckoutSession()->getQuote()->getAllItems(); if ($productCollection) { $eventData = []; $eventData['currency'] = Mage::app()->getStore()->getCurrentCurrencyCode(); diff --git a/app/code/core/Mage/GoogleAnalytics/Model/Observer.php b/app/code/core/Mage/GoogleAnalytics/Model/Observer.php index 858fbafc09f..f90851b770e 100644 --- a/app/code/core/Mage/GoogleAnalytics/Model/Observer.php +++ b/app/code/core/Mage/GoogleAnalytics/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_GoogleAnalytics */ -class Mage_GoogleAnalytics_Model_Observer +class Mage_GoogleAnalytics_Model_Observer extends Mage_Core_Model_Observer { /** * Add order information into GA block to render on checkout success pages @@ -87,7 +87,7 @@ public function processItemsAddedOrRemovedFromCart(Varien_Event_Observer $observ 'category' => Mage::helper('googleanalytics')->getLastCategoryName($product), ]; - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); if ($addedQty) { $addedProducts = $session->getAddedProductsForAnalytics() ?: []; $addedProducts[] = $dataForAnalytics; diff --git a/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php b/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php index a52e70c06d6..e17c76402da 100644 --- a/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php +++ b/app/code/core/Mage/Index/Block/Adminhtml/Notifications.php @@ -57,7 +57,7 @@ public function getManageUrl() */ protected function _toHtml() { - if (Mage::getSingleton('admin/session')->isAllowed('system/index')) { + if ($this->getAdminSession()->isAllowed('system/index')) { return parent::_toHtml(); } return ''; diff --git a/app/code/core/Mage/Install/Block/Admin.php b/app/code/core/Mage/Install/Block/Admin.php index 3fb3958e163..09067c979f8 100644 --- a/app/code/core/Mage/Install/Block/Admin.php +++ b/app/code/core/Mage/Install/Block/Admin.php @@ -37,7 +37,7 @@ public function getFormData() { $data = $this->getData('form_data'); if (is_null($data)) { - $data = new Varien_Object(Mage::getSingleton('install/session')->getAdminData(true)); + $data = new Varien_Object($this->getInstallSession()->getAdminData(true)); $this->setData('form_data', $data); } return $data; diff --git a/app/code/core/Mage/Install/Block/Config.php b/app/code/core/Mage/Install/Block/Config.php index dd692db5557..3e4c9f568ea 100644 --- a/app/code/core/Mage/Install/Block/Config.php +++ b/app/code/core/Mage/Install/Block/Config.php @@ -47,7 +47,7 @@ public function getFormData() { $data = $this->getData('form_data'); if (is_null($data)) { - $data = Mage::getSingleton('install/session')->getConfigData(true); + $data = $this->getInstallSession()->getConfigData(true); if (empty($data)) { $data = Mage::getModel('install/installer_config')->getFormData(); } else { @@ -60,12 +60,12 @@ public function getFormData() public function getSkipUrlValidation() { - return Mage::getSingleton('install/session')->getSkipUrlValidation(); + return $this->getInstallSession()->getSkipUrlValidation(); } public function getSkipBaseUrlValidation() { - return Mage::getSingleton('install/session')->getSkipBaseUrlValidation(); + return $this->getInstallSession()->getSkipBaseUrlValidation(); } public function getSessionSaveOptions() diff --git a/app/code/core/Mage/Install/Block/Db/Main.php b/app/code/core/Mage/Install/Block/Db/Main.php index ad8f3ced8d6..31dc30202d5 100644 --- a/app/code/core/Mage/Install/Block/Db/Main.php +++ b/app/code/core/Mage/Install/Block/Db/Main.php @@ -93,7 +93,7 @@ public function getFormData() { $data = $this->getData('form_data'); if (is_null($data)) { - $data = Mage::getSingleton('install/session')->getConfigData(true); + $data = $this->getInstallSession()->getConfigData(true); if (empty($data)) { $data = Mage::getModel('install/installer_config')->getFormData(); } else { diff --git a/app/code/core/Mage/Install/Block/Db/Type.php b/app/code/core/Mage/Install/Block/Db/Type.php index f310eeb4bc2..44e6c0a4f06 100644 --- a/app/code/core/Mage/Install/Block/Db/Type.php +++ b/app/code/core/Mage/Install/Block/Db/Type.php @@ -48,7 +48,7 @@ public function getFormData() { $data = $this->getData('form_data'); if (is_null($data)) { - $data = Mage::getSingleton('install/session')->getConfigData(true); + $data = $this->getInstallSession()->getConfigData(true); if (empty($data)) { $data = Mage::getModel('install/installer_config')->getFormData(); } else { diff --git a/app/code/core/Mage/Install/Block/Locale.php b/app/code/core/Mage/Install/Block/Locale.php index edf64c1a8c3..0695f40150d 100644 --- a/app/code/core/Mage/Install/Block/Locale.php +++ b/app/code/core/Mage/Install/Block/Locale.php @@ -105,8 +105,8 @@ public function getTimezoneSelect() */ public function getTimezone() { - $timezone = Mage::getSingleton('install/session')->getTimezone() - ? Mage::getSingleton('install/session')->getTimezone() + $timezone = $this->getInstallSession()->getTimezone() + ? $this->getInstallSession()->getTimezone() : Mage::app()->getLocale()->getTimezone(); if ($timezone == Mage_Core_Model_Locale::DEFAULT_TIMEZONE) { $timezone = 'America/Los_Angeles'; @@ -138,8 +138,8 @@ public function getCurrencySelect() */ public function getCurrency() { - return Mage::getSingleton('install/session')->getCurrency() - ? Mage::getSingleton('install/session')->getCurrency() + return $this->getInstallSession()->getCurrency() + ? $this->getInstallSession()->getCurrency() : Mage::app()->getLocale()->getCurrency(); } diff --git a/app/code/core/Mage/Install/Model/Installer.php b/app/code/core/Mage/Install/Model/Installer.php index c743ab52857..a591c7669ec 100644 --- a/app/code/core/Mage/Install/Model/Installer.php +++ b/app/code/core/Mage/Install/Model/Installer.php @@ -22,6 +22,8 @@ */ class Mage_Install_Model_Installer extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Installer host response used to check urls * @@ -31,7 +33,7 @@ class Mage_Install_Model_Installer extends Varien_Object /** * Installer data model used to store data between installation steps * - * @var Mage_Install_Model_Installer_Data|null + * @var Mage_Install_Model_Session|null */ protected $_dataModel; @@ -53,7 +55,7 @@ public function isApplicationInstalled() public function getDataModel() { if (is_null($this->_dataModel)) { - $this->setDataModel(Mage::getSingleton('install/session')); + $this->setDataModel($this->getInstallSession()); } return $this->_dataModel; } @@ -61,7 +63,7 @@ public function getDataModel() /** * Set data model to store data between installation steps * - * @param Mage_Install_Model_Installer_Data $model + * @param Mage_Install_Model_Installer_Data|Mage_Install_Model_Session $model * @return $this */ public function setDataModel(Varien_Object $model) diff --git a/app/code/core/Mage/Install/Model/Installer/Env.php b/app/code/core/Mage/Install/Model/Installer/Env.php index 2449454d4b0..90b9eaf0225 100644 --- a/app/code/core/Mage/Install/Model/Installer/Env.php +++ b/app/code/core/Mage/Install/Model/Installer/Env.php @@ -22,6 +22,8 @@ */ class Mage_Install_Model_Installer_Env extends Mage_Install_Model_Installer_Abstract { + use Mage_Core_Trait_Session; + public function __construct() {} public function install() @@ -57,13 +59,13 @@ protected function _checkExtension($extension) } if (!$oneLoaded) { - Mage::getSingleton('install/session')->addError( + $this->getInstallSession()->addError( Mage::helper('install')->__('One of PHP Extensions "%s" must be loaded.', implode(',', $extension)), ); return false; } } elseif (!extension_loaded($extension)) { - Mage::getSingleton('install/session')->addError( + $this->getInstallSession()->addError( Mage::helper('install')->__('PHP extension "%s" must be loaded.', $extension), ); return false; diff --git a/app/code/core/Mage/Install/Model/Observer.php b/app/code/core/Mage/Install/Model/Observer.php index 38eaa04cd83..4135681c557 100644 --- a/app/code/core/Mage/Install/Model/Observer.php +++ b/app/code/core/Mage/Install/Model/Observer.php @@ -20,12 +20,12 @@ * @category Mage * @package Mage_Install */ -class Mage_Install_Model_Observer +class Mage_Install_Model_Observer extends Mage_Core_Model_Observer { public function bindLocale($observer) { if ($locale = $observer->getEvent()->getLocale()) { - if ($choosedLocale = Mage::getSingleton('install/session')->getLocale()) { + if ($choosedLocale = $this->getInstallSession()->getLocale()) { $locale->setLocaleCode($choosedLocale); } } diff --git a/app/code/core/Mage/Install/controllers/WizardController.php b/app/code/core/Mage/Install/controllers/WizardController.php index b80edff6327..b63495d4f5f 100644 --- a/app/code/core/Mage/Install/controllers/WizardController.php +++ b/app/code/core/Mage/Install/controllers/WizardController.php @@ -105,7 +105,7 @@ public function beginAction() $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true); $this->_prepareLayout(); - $this->_initLayoutMessages('install/session'); + $this->_initLayoutMessages($this->getInstallSessionStorage()); $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('install/begin', 'install.begin'), @@ -139,7 +139,7 @@ public function localeAction() $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true); $this->_prepareLayout(); - $this->_initLayoutMessages('install/session'); + $this->_initLayoutMessages($this->getInstallSessionStorage()); $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('install/locale', 'install.locale'), ); @@ -158,9 +158,9 @@ public function localeChangeAction() $timezone = $this->getRequest()->getParam('timezone'); $currency = $this->getRequest()->getParam('currency'); if ($locale) { - Mage::getSingleton('install/session')->setLocale($locale); - Mage::getSingleton('install/session')->setTimezone($timezone); - Mage::getSingleton('install/session')->setCurrency($currency); + $this->getInstallSession()->setLocale($locale); + $this->getInstallSession()->setTimezone($timezone); + $this->getInstallSession()->setCurrency($currency); } $this->_redirect('*/*/locale'); @@ -175,7 +175,7 @@ public function localePostAction() $step = $this->_getWizard()->getStepByName('locale'); if ($data = $this->getRequest()->getPost('config')) { - Mage::getSingleton('install/session')->setLocaleData($data); + $this->getInstallSession()->setLocaleData($data); } $this->getResponse()->setRedirect($step->getNextUrl()); @@ -193,11 +193,11 @@ public function configAction() $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true); if ($data = $this->getRequest()->getQuery('config')) { - Mage::getSingleton('install/session')->setLocaleData($data); + $this->getInstallSession()->setLocaleData($data); } $this->_prepareLayout(); - $this->_initLayoutMessages('install/session'); + $this->_initLayoutMessages($this->getInstallSessionStorage()); $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('install/config', 'install.config'), ); @@ -223,7 +223,7 @@ public function configPostAction() $config['secure_base_url'] = Mage::helper('core/url')->encodePunycode($config['unsecure_base_url']); $data = array_merge($config, $connectionConfig[$config['db_model']]); - Mage::getSingleton('install/session') + $this->getInstallSession() ->setConfigData($data) ->setSkipUrlValidation($this->getRequest()->getPost('skip_url_validation')) ->setSkipBaseUrlValidation($this->getRequest()->getPost('skip_base_url_validation')); @@ -232,7 +232,7 @@ public function configPostAction() $this->_redirect('*/*/installDb'); return $this; } catch (Exception $e) { - Mage::getSingleton('install/session')->addError($e->getMessage()); + $this->getInstallSession()->addError($e->getMessage()); $this->getResponse()->setRedirect($step->getUrl()); } } @@ -251,13 +251,13 @@ public function installDbAction() /** * Clear session config data */ - Mage::getSingleton('install/session')->getConfigData(true); + $this->getInstallSession()->getConfigData(true); Mage::app()->getStore()->resetConfig(); $this->getResponse()->setRedirect(Mage::getUrl($step->getNextUrlPath())); } catch (Exception $e) { - Mage::getSingleton('install/session')->addError($e->getMessage()); + $this->getInstallSession()->addError($e->getMessage()); $this->getResponse()->setRedirect($step->getUrl()); } } @@ -270,7 +270,7 @@ public function administratorAction() $this->_checkIfInstalled(); $this->_prepareLayout(); - $this->_initLayoutMessages('install/session'); + $this->_initLayoutMessages($this->getInstallSessionStorage()); $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('install/admin', 'install.administrator'), @@ -306,7 +306,7 @@ public function administratorPostAction() } if (!empty($errors)) { - Mage::getSingleton('install/session')->setAdminData($adminData); + $this->getInstallSession()->setAdminData($adminData); $this->getResponse()->setRedirect($step->getUrl()); return false; } @@ -315,7 +315,7 @@ public function administratorPostAction() $this->_getInstaller()->createAdministrator($user); $this->_getInstaller()->installEnryptionKey($encryptionKey); } catch (Exception $e) { - Mage::getSingleton('install/session') + $this->getInstallSession() ->setAdminData($adminData) ->addError($e->getMessage()); $this->getResponse()->setRedirect($step->getUrl()); @@ -340,13 +340,13 @@ public function endAction() $this->_getInstaller()->finish(); $this->_prepareLayout(); - $this->_initLayoutMessages('install/session'); + $this->_initLayoutMessages($this->getInstallSessionStorage()); $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('install/end', 'install.end'), ); $this->renderLayout(); - Mage::getSingleton('install/session')->clear(); + $this->getInstallSession()->clear(); } /** diff --git a/app/code/core/Mage/Log/Model/Visitor.php b/app/code/core/Mage/Log/Model/Visitor.php index 016bbacb99b..60e5c6fe338 100644 --- a/app/code/core/Mage/Log/Model/Visitor.php +++ b/app/code/core/Mage/Log/Model/Visitor.php @@ -91,7 +91,7 @@ public function __construct(array $data = []) $this->_config = !empty($data['config']) ? $data['config'] : Mage::getConfig(); $this->_logCondition = !empty($data['log_condition']) ? $data['log_condition'] : Mage::helper('log'); - $this->_session = !empty($data['session']) ? $data['session'] : Mage::getSingleton('core/session'); + $this->_session = !empty($data['session']) ? $data['session'] : $this->getCoreSession(); parent::__construct($data); } diff --git a/app/code/core/Mage/Newsletter/Block/Subscribe.php b/app/code/core/Mage/Newsletter/Block/Subscribe.php index 4c528af2735..5e6a592af2a 100644 --- a/app/code/core/Mage/Newsletter/Block/Subscribe.php +++ b/app/code/core/Mage/Newsletter/Block/Subscribe.php @@ -27,7 +27,7 @@ class Mage_Newsletter_Block_Subscribe extends Mage_Core_Block_Template */ public function getSuccessMessage() { - return Mage::getSingleton('newsletter/session')->getSuccess(); + return $this->getNewsletterSession()->getSuccess(); } /** @@ -35,7 +35,7 @@ public function getSuccessMessage() */ public function getErrorMessage() { - return Mage::getSingleton('newsletter/session')->getError(); + return $this->getNewsletterSession()->getError(); } /** diff --git a/app/code/core/Mage/Newsletter/Model/Subscriber.php b/app/code/core/Mage/Newsletter/Model/Subscriber.php index 91547ae500d..1be60b96fa4 100644 --- a/app/code/core/Mage/Newsletter/Model/Subscriber.php +++ b/app/code/core/Mage/Newsletter/Model/Subscriber.php @@ -309,7 +309,7 @@ public function randomSequence($length = 32) public function subscribe($email) { $this->loadByEmail($email); - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); if (!$this->getId()) { $this->setSubscriberConfirmCode($this->randomSequence()); diff --git a/app/code/core/Mage/Newsletter/controllers/ManageController.php b/app/code/core/Mage/Newsletter/controllers/ManageController.php index cdc9f64d675..9d69da83fa4 100644 --- a/app/code/core/Mage/Newsletter/controllers/ManageController.php +++ b/app/code/core/Mage/Newsletter/controllers/ManageController.php @@ -30,7 +30,7 @@ class Mage_Newsletter_ManageController extends Mage_Core_Controller_Front_Action public function preDispatch() { parent::preDispatch(); - if (!Mage::getSingleton('customer/session')->authenticate($this)) { + if (!$this->getCustomerSession()->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); } return $this; @@ -39,8 +39,8 @@ public function preDispatch() public function indexAction() { $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); if ($block = $this->getLayout()->getBlock('customer_newsletter')) { $block->setRefererUrl($this->_getRefererUrl()); @@ -49,23 +49,26 @@ public function indexAction() $this->renderLayout(); } + /** + * @return Mage_Newsletter_ManageController|void + */ public function saveAction() { if (!$this->_validateFormKey()) { return $this->_redirect('customer/account/'); } try { - Mage::getSingleton('customer/session')->getCustomer() + $this->getCustomerSession()->getCustomer() ->setStoreId(Mage::app()->getStore()->getId()) ->setIsSubscribed((bool) $this->getRequest()->getParam('is_subscribed', false)) ->save(); if ((bool) $this->getRequest()->getParam('is_subscribed', false)) { - Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been saved.')); + $this->getCustomerSession()->addSuccess($this->__('The subscription has been saved.')); } else { - Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been removed.')); + $this->getCustomerSession()->addSuccess($this->__('The subscription has been removed.')); } } catch (Exception $e) { - Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription.')); + $this->getCustomerSession()->addError($this->__('An error occurred while saving your subscription.')); } $this->_redirect('customer/account/'); } diff --git a/app/code/core/Mage/Newsletter/controllers/SubscriberController.php b/app/code/core/Mage/Newsletter/controllers/SubscriberController.php index a68534799d5..15d49823d95 100644 --- a/app/code/core/Mage/Newsletter/controllers/SubscriberController.php +++ b/app/code/core/Mage/Newsletter/controllers/SubscriberController.php @@ -38,8 +38,8 @@ public function newAction() } if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) { - $session = Mage::getSingleton('core/session'); - $customerSession = Mage::getSingleton('customer/session'); + $session = $this->getCoreSession(); + $customerSession = $this->getCustomerSession(); $email = (string) $this->getRequest()->getPost('email'); try { @@ -86,7 +86,7 @@ public function confirmAction() if ($id && $code) { $subscriber = Mage::getModel('newsletter/subscriber')->load($id); - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); if ($subscriber->getStatus() == $subscriber::STATUS_SUBSCRIBED) { $session->addNotice($this->__('This email address is already confirmed.')); @@ -114,7 +114,7 @@ public function unsubscribeAction() $code = (string) $this->getRequest()->getParam('code'); if ($id && $code) { - $session = Mage::getSingleton('core/session'); + $session = $this->getCoreSession(); try { Mage::getModel('newsletter/subscriber')->load($id) ->setCheckCode($code) diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Admin/Token/Grid.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Admin/Token/Grid.php index 5284b239eaf..e083b4ad5ea 100644 --- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Admin/Token/Grid.php +++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Admin/Token/Grid.php @@ -42,8 +42,7 @@ public function __construct() */ protected function _prepareCollection() { - /** @var Mage_Admin_Model_User $user */ - $user = Mage::getSingleton('admin/session')->getData('user'); + $user = $this->getAdminSession()->getUser(); /** @var Mage_Oauth_Model_Resource_Token_Collection $collection */ $collection = Mage::getModel('oauth/token')->getCollection(); diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Authorize.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Authorize.php index a121f9a58bf..0fc4a0a9f9f 100644 --- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Authorize.php +++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Authorize.php @@ -29,7 +29,7 @@ class Mage_Oauth_Block_Adminhtml_Oauth_Authorize extends Mage_Oauth_Block_Author */ public function getFormKey() { - return Mage::getSingleton('core/session')->getFormKey(); + return $this->getCoreSession()->getFormKey(); } /** diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php index 20531051527..5894b4fcd89 100644 --- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php +++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/AuthorizedTokens/Grid.php @@ -182,7 +182,7 @@ public function decorateUserType($value, $row, $column, $isExport) * @param Mage_Oauth_Model_Token $row * @param Mage_Adminhtml_Block_Widget_Grid_Column $column * @param bool $isExport - * @return mixed + * @return int */ public function decorateUserId($value, $row, $column, $isExport) { @@ -196,8 +196,6 @@ public function decorateUserId($value, $row, $column, $isExport) */ protected function _isAllowed() { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); - return $session->isAllowed('system/oauth/authorizedTokens'); + return $this->getAdminSession()->isAllowed('system/oauth/authorizedTokens'); } } diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php index 9d25dc9fb8e..55c41e50c8a 100644 --- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php +++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer.php @@ -34,8 +34,7 @@ public function __construct() $this->_headerText = Mage::helper('adminhtml')->__('OAuth Consumers'); //check allow edit - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); if (!$session->isAllowed('system/oauth/consumer/edit')) { $this->_removeButton('add'); } diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php index 436908c11d8..523d4288e70 100644 --- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php +++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Edit.php @@ -68,8 +68,7 @@ public function __construct() Mage::helper('adminhtml')->__('Are you sure you want to do this?'), ) . '\')) editForm.submit(\'' . $this->getUrl('*/*/delete') . '\'); return false;'); - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); if (!$this->getModel() || !$this->getModel()->getId() || !$session->isAllowed('system/oauth/consumer/delete')) { $this->_removeButton('delete'); } diff --git a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php index a6e61c2d56b..f511001d91a 100644 --- a/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php +++ b/app/code/core/Mage/Oauth/Block/Adminhtml/Oauth/Consumer/Grid.php @@ -41,8 +41,7 @@ public function __construct() $this->setDefaultSort('entity_id') ->setDefaultDir(Varien_Db_Select::SQL_DESC); - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); $this->_editAllow = $session->isAllowed('system/oauth/consumer/edit'); } diff --git a/app/code/core/Mage/Oauth/Block/Customer/Token/List.php b/app/code/core/Mage/Oauth/Block/Customer/Token/List.php index 11f84689282..e5ff199691c 100644 --- a/app/code/core/Mage/Oauth/Block/Customer/Token/List.php +++ b/app/code/core/Mage/Oauth/Block/Customer/Token/List.php @@ -34,8 +34,7 @@ class Mage_Oauth_Block_Customer_Token_List extends Mage_Customer_Block_Account_D */ protected function _construct() { - /** @var Mage_Customer_Model_Session $session */ - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); /** @var Mage_Oauth_Model_Resource_Token_Collection $collection */ $collection = Mage::getModel('oauth/token')->getCollection(); diff --git a/app/code/core/Mage/Oauth/Model/Observer.php b/app/code/core/Mage/Oauth/Model/Observer.php index 802c7576e14..42739b9fa3c 100644 --- a/app/code/core/Mage/Oauth/Model/Observer.php +++ b/app/code/core/Mage/Oauth/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Oauth */ -class Mage_Oauth_Model_Observer +class Mage_Oauth_Model_Observer extends Mage_Core_Model_Observer { /** * Retrieve oauth_token param from request @@ -76,8 +76,7 @@ public function afterAdminLogin(Varien_Event_Observer $observer) public function afterAdminLoginFailed(Varien_Event_Observer $observer) { if ($this->_getOauthToken() !== null) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); $session->addError($observer->getException()->getMessage()); $userType = Mage_Oauth_Model_Token::USER_TYPE_ADMIN; diff --git a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php index 9aa5016f541..bba5ac3470d 100644 --- a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php +++ b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/Admin/TokenController.php @@ -80,8 +80,7 @@ public function revokeAction() } try { - /** @var Mage_Admin_Model_User $user */ - $user = Mage::getSingleton('admin/session')->getData('user'); + $user = $this->getAdminSession()->getUser(); /** @var Mage_Oauth_Model_Resource_Token_Collection $collection */ $collection = Mage::getModel('oauth/token')->getCollection(); @@ -126,8 +125,7 @@ public function deleteAction() } try { - /** @var Mage_Admin_Model_User $user */ - $user = Mage::getSingleton('admin/session')->getData('user'); + $user = $this->getAdminSession()->getUser(); /** @var Mage_Oauth_Model_Resource_Token_Collection $collection */ $collection = Mage::getModel('oauth/token')->getCollection(); @@ -155,8 +153,6 @@ public function deleteAction() */ protected function _isAllowed() { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); - return $session->isAllowed('system/api/oauth_admin_token'); + return $this->getAdminSession()->isAllowed('system/api/oauth_admin_token'); } } diff --git a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizeController.php b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizeController.php index 2f3f5765696..ec3ae2b6a47 100644 --- a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizeController.php +++ b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizeController.php @@ -53,7 +53,7 @@ public function preDispatch() // call after parent::preDispatch(); to get session started if ($loginError) { - Mage::getSingleton('adminhtml/session') + $this->getAdminhtmlSession() ->addError(Mage::helper('adminhtml')->__('Invalid User Name or Password.')); $params = ['_query' => ['oauth_token' => $this->getRequest()->getParam('oauth_token', null)]]; $this->setFlag('', self::FLAG_NO_DISPATCH, true); diff --git a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php index 6cad5ac2c41..026a42c5c6a 100644 --- a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php +++ b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizedTokensController.php @@ -149,8 +149,7 @@ public function deleteAction() */ protected function _isAllowed() { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); return $session->isAllowed('system/api/oauth_authorized_tokens'); } @@ -163,8 +162,7 @@ protected function _isAllowed() protected function _sendTokenStatusChangeNotification($token, $newStatus) { if (($adminId = $token->getAdminId())) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); $admin = $session->getUser(); diff --git a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php index 2f3cdcc3035..413eee8e8cf 100644 --- a/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php +++ b/app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/ConsumerController.php @@ -241,8 +241,7 @@ protected function _isAllowed() } $action = '/' . $action; } - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('admin/session'); + $session = $this->getAdminSession(); return $session->isAllowed('system/api/oauth_consumer' . $action); } diff --git a/app/code/core/Mage/Page/Block/Html/Footer.php b/app/code/core/Mage/Page/Block/Html/Footer.php index 56f50d9df3e..8d3765fe178 100644 --- a/app/code/core/Mage/Page/Block/Html/Footer.php +++ b/app/code/core/Mage/Page/Block/Html/Footer.php @@ -49,7 +49,7 @@ public function getCacheKeyInfo() (int) Mage::app()->getStore()->isCurrentlySecure(), Mage::getDesign()->getPackageName(), Mage::getDesign()->getTheme('template'), - Mage::getSingleton('customer/session')->isLoggedIn(), + $this->getCustomerSession()->isLoggedIn(), ]; } diff --git a/app/code/core/Mage/Page/Block/Html/Header.php b/app/code/core/Mage/Page/Block/Html/Header.php index 9fcd27a5380..c81c1dab5c9 100644 --- a/app/code/core/Mage/Page/Block/Html/Header.php +++ b/app/code/core/Mage/Page/Block/Html/Header.php @@ -95,8 +95,8 @@ public function getLogoAlt() public function getWelcome() { if (empty($this->_data['welcome'])) { - if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) { - $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName())); + if (Mage::isInstalled() && $this->getCustomerSession()->isLoggedIn()) { + $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->getCustomerSession()->getCustomer()->getName())); } else { $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); } diff --git a/app/code/core/Mage/Page/Block/Html/Topmenu.php b/app/code/core/Mage/Page/Block/Html/Topmenu.php index 0ab1ddd6716..79122652722 100644 --- a/app/code/core/Mage/Page/Block/Html/Topmenu.php +++ b/app/code/core/Mage/Page/Block/Html/Topmenu.php @@ -217,7 +217,7 @@ public function getCacheKeyInfo() Mage::app()->getStore()->getId(), Mage::getDesign()->getPackageName(), Mage::getDesign()->getTheme('template'), - Mage::getSingleton('customer/session')->getCustomerGroupId(), + $this->getCustomerSession()->getCustomerGroupId(), 'template' => $this->getTemplate(), 'name' => $this->getNameInLayout(), $this->getCurrentEntityKey(), diff --git a/app/code/core/Mage/Page/Block/Html/Welcome.php b/app/code/core/Mage/Page/Block/Html/Welcome.php index 43e644a22fe..9e93fe29341 100644 --- a/app/code/core/Mage/Page/Block/Html/Welcome.php +++ b/app/code/core/Mage/Page/Block/Html/Welcome.php @@ -28,10 +28,12 @@ class Mage_Page_Block_Html_Welcome extends Mage_Core_Block_Template * Get customer session * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** @@ -42,8 +44,8 @@ protected function _getSession() protected function _toHtml() { if (empty($this->_data['welcome'])) { - if (Mage::isInstalled() && $this->_getSession()->isLoggedIn()) { - $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->_getSession()->getCustomer()->getName())); + if (Mage::isInstalled() && $this->getCustomerSession()->isLoggedIn()) { + $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->getCustomerSession()->getCustomer()->getName())); } else { $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); } @@ -59,8 +61,8 @@ protected function _toHtml() */ public function getCacheTags() { - if ($this->_getSession()->isLoggedIn()) { - $this->addModelTags($this->_getSession()->getCustomer()); + if ($this->getCustomerSession()->isLoggedIn()) { + $this->addModelTags($this->getCustomerSession()->getCustomer()); } return parent::getCacheTags(); diff --git a/app/code/core/Mage/Page/Block/Template/Links.php b/app/code/core/Mage/Page/Block/Template/Links.php index 01b4cc5ee51..31ba0c2cd25 100644 --- a/app/code/core/Mage/Page/Block/Template/Links.php +++ b/app/code/core/Mage/Page/Block/Template/Links.php @@ -259,8 +259,8 @@ protected function _getNewPosition($position = 0) */ public function getCacheTags() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $this->addModelTags(Mage::getSingleton('customer/session')->getCustomer()); + if ($this->getCustomerSession()->isLoggedIn()) { + $this->addModelTags($this->getCustomerSession()->getCustomer()); } return parent::getCacheTags(); diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet.php b/app/code/core/Mage/Paygate/Model/Authorizenet.php index 59459bd07c1..ab503bd5dc4 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet.php @@ -1389,7 +1389,7 @@ protected function _getSession() if (Mage::app()->getStore()->isAdmin()) { return Mage::getSingleton('adminhtml/session_quote'); } else { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } } diff --git a/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php b/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php index 822941d7c2e..1b0bf92097b 100644 --- a/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php +++ b/app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php @@ -31,7 +31,7 @@ public function cancelAction() try { $paymentMethod = Mage::helper('payment')->getMethodInstance(Mage_Paygate_Model_Authorizenet::METHOD_CODE); if ($paymentMethod) { - $paymentMethod->cancelPartialAuthorization(Mage::getSingleton('checkout/session')->getQuote()->getPayment()); + $paymentMethod->cancelPartialAuthorization($this->getCheckoutSession()->getQuote()->getPayment()); } $result['success'] = true; $result['update_html'] = $this->_getPaymentMethodsHtml(); @@ -43,7 +43,7 @@ public function cancelAction() $result['error_message'] = $this->__('There was an error canceling transactions. Please contact us or try again later.'); } - Mage::getSingleton('checkout/session')->getQuote()->getPayment()->save(); + $this->getCheckoutSession()->getQuote()->getPayment()->save(); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } diff --git a/app/code/core/Mage/Payment/Model/Method/Abstract.php b/app/code/core/Mage/Payment/Model/Method/Abstract.php index 8fecb02d2c3..93078d42801 100644 --- a/app/code/core/Mage/Payment/Model/Method/Abstract.php +++ b/app/code/core/Mage/Payment/Model/Method/Abstract.php @@ -34,6 +34,8 @@ */ abstract class Mage_Payment_Model_Method_Abstract extends Varien_Object { + use Mage_Core_Trait_Session; + public const ACTION_ORDER = 'order'; public const ACTION_AUTHORIZE = 'authorize'; public const ACTION_AUTHORIZE_CAPTURE = 'authorize_capture'; diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Expanded.php b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Expanded.php index 0c31e849701..0e69b4a3204 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Expanded.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Expanded.php @@ -30,7 +30,7 @@ class Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Expanded extends Mage_A */ protected function _getCollapseState($element) { - $extra = Mage::getSingleton('admin/session')->getUser()->getExtra(); + $extra = $this->getAdminSession()->getUser()->getExtra(); return $extra['configState'][$element->getId()] ?? true; } } diff --git a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php index 394c7a6dde4..86704f279b0 100644 --- a/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php +++ b/app/code/core/Mage/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php @@ -49,7 +49,7 @@ protected function _getHeaderCommentHtml($element) */ protected function _getCollapseState($element) { - $extra = Mage::getSingleton('admin/session')->getUser()->getExtra(); + $extra = $this->getAdminSession()->getUser()->getExtra(); if (isset($extra['configState'][$element->getId()])) { return $extra['configState'][$element->getId()]; } diff --git a/app/code/core/Mage/Paypal/Block/Express/Form.php b/app/code/core/Mage/Paypal/Block/Express/Form.php index 94980b7bac4..3ebd0600966 100644 --- a/app/code/core/Mage/Paypal/Block/Express/Form.php +++ b/app/code/core/Mage/Paypal/Block/Express/Form.php @@ -44,7 +44,7 @@ protected function _construct() */ protected function _beforeToHtml() { - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); if (Mage::helper('paypal')->shouldAskToCreateBillingAgreement($this->_config, $customerId) && $this->canCreateBillingAgreement() ) { diff --git a/app/code/core/Mage/Paypal/Block/Express/Shortcut.php b/app/code/core/Mage/Paypal/Block/Express/Shortcut.php index ac6d827afd3..4f95b8a9a45 100644 --- a/app/code/core/Mage/Paypal/Block/Express/Shortcut.php +++ b/app/code/core/Mage/Paypal/Block/Express/Shortcut.php @@ -76,7 +76,7 @@ protected function _beforeToHtml() $config = Mage::getModel('paypal/config', [$this->_paymentMethodCode]); $isInCatalog = $this->getIsInCatalogProduct(); $quote = ($isInCatalog || $this->getIsQuoteAllowed() == '') - ? null : Mage::getSingleton('checkout/session')->getQuote(); + ? null : $this->getCheckoutSession()->getQuote(); // check visibility on cart or product page $context = $isInCatalog ? 'visible_on_product' : 'visible_on_cart'; @@ -132,7 +132,7 @@ protected function _beforeToHtml() } // ask whether to create a billing agreement - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); // potential issue for caching + $customerId = $this->getCustomerSession()->getCustomerId(); // potential issue for caching if (Mage::helper('paypal')->shouldAskToCreateBillingAgreement($config, $customerId)) { $this->setConfirmationUrl( $this->getUrl( diff --git a/app/code/core/Mage/Paypal/Block/Iframe.php b/app/code/core/Mage/Paypal/Block/Iframe.php index d7637aaf333..4605324d6b6 100644 --- a/app/code/core/Mage/Paypal/Block/Iframe.php +++ b/app/code/core/Mage/Paypal/Block/Iframe.php @@ -114,10 +114,12 @@ protected function _getOrder() * Get frontend checkout session object * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckout() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Paypal/Controller/Express/Abstract.php b/app/code/core/Mage/Paypal/Controller/Express/Abstract.php index a04dbfff98c..0b1408220a0 100644 --- a/app/code/core/Mage/Paypal/Controller/Express/Abstract.php +++ b/app/code/core/Mage/Paypal/Controller/Express/Abstract.php @@ -76,7 +76,7 @@ public function startAction() $this->_getQuote()->removeAllAddresses(); } - $customer = Mage::getSingleton('customer/session')->getCustomer(); + $customer = $this->getCustomerSession()->getCustomer(); $quoteCheckoutMethod = $this->_getQuote()->getCheckoutMethod(); if ($customer && $customer->getId()) { $this->_checkout->setCustomerWithAddressChange( @@ -91,11 +91,11 @@ public function startAction() $this->_getQuote()->getStoreId(), ) ) { - Mage::getSingleton('core/session')->addNotice( + $this->getCoreSession()->addNotice( Mage::helper('paypal')->__('To proceed to Checkout, please log in using your email address.'), ); $this->redirectLogin(); - Mage::getSingleton('customer/session') + $this->getCustomerSession() ->setBeforeAuthUrl(Mage::getUrl('*/*/*', ['_current' => true])); return; } @@ -207,9 +207,9 @@ public function returnAction() return; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('checkout/session')->addError($e->getMessage()); + $this->getCheckoutSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Express Checkout approval.')); + $this->getCheckoutSession()->addError($this->__('Unable to process Express Checkout approval.')); Mage::logException($e); } $this->_redirect('checkout/cart'); @@ -224,7 +224,7 @@ public function reviewAction() $this->_initCheckout(); $this->_checkout->prepareOrderReview($this->_initToken()); $this->loadLayout(); - $this->_initLayoutMessages('paypal/session'); + $this->_initLayoutMessages($this->getPaypalSessionStorage()); $reviewBlock = $this->getLayout()->getBlock('paypal.express.review'); $reviewBlock->setQuote($this->_getQuote()); $reviewBlock->getChild('details')->setQuote($this->_getQuote()); @@ -234,9 +234,9 @@ public function reviewAction() $this->renderLayout(); return; } catch (Mage_Core_Exception $e) { - Mage::getSingleton('checkout/session')->addError($e->getMessage()); + $this->getCheckoutSession()->addError($e->getMessage()); } catch (Exception $e) { - Mage::getSingleton('checkout/session')->addError( + $this->getCheckoutSession()->addError( $this->__('Unable to initialize Express Checkout review.'), ); Mage::logException($e); @@ -498,20 +498,24 @@ protected function _initToken($setToken = null) * PayPal session instance getter * * @return Mage_Paypal_Model_Session + * @deprecated + * @see getPaypalSession() */ private function _getSession() { - return Mage::getSingleton('paypal/session'); + return $this->getPaypalSession(); } /** * Return checkout session object * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckoutSession() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Paypal/Helper/Checkout.php b/app/code/core/Mage/Paypal/Helper/Checkout.php index 5db658cf8d0..a63452d75cd 100644 --- a/app/code/core/Mage/Paypal/Helper/Checkout.php +++ b/app/code/core/Mage/Paypal/Helper/Checkout.php @@ -67,10 +67,12 @@ public function cancelCurrentOrder($comment) * Return checkout session instance * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckoutSession() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Paypal/Helper/Hss.php b/app/code/core/Mage/Paypal/Helper/Hss.php index 5f6ae4d9af0..860c128c367 100644 --- a/app/code/core/Mage/Paypal/Helper/Hss.php +++ b/app/code/core/Mage/Paypal/Helper/Hss.php @@ -44,7 +44,7 @@ class Mage_Paypal_Helper_Hss extends Mage_Core_Helper_Abstract */ public function getReviewButtonTemplate($name, $block) { - $quote = Mage::getSingleton('checkout/session')->getQuote(); + $quote = $this->getCheckoutSession()->getQuote(); if ($quote) { $payment = $quote->getPayment(); if ($payment && in_array($payment->getMethod(), $this->_hssMethods)) { diff --git a/app/code/core/Mage/Paypal/Model/Express.php b/app/code/core/Mage/Paypal/Model/Express.php index d2e27b1a905..a16fd732fcc 100644 --- a/app/code/core/Mage/Paypal/Model/Express.php +++ b/app/code/core/Mage/Paypal/Model/Express.php @@ -190,7 +190,7 @@ public function getConfigData($field, $storeId = null) */ public function order(Varien_Object $payment, $amount) { - $paypalTransactionData = Mage::getSingleton('checkout/session')->getPaypalTransactionData(); + $paypalTransactionData = $this->getCheckoutSession()->getPaypalTransactionData(); if (!is_array($paypalTransactionData)) { $this->_placeOrder($payment, $amount); } else { @@ -667,7 +667,7 @@ protected function _callDoAuthorize($amount, $payment, $parentTransactionId) unset($apiData[$k]); } } - Mage::getSingleton('checkout/session')->setPaypalTransactionData($apiData); + $this->getCheckoutSession()->setPaypalTransactionData($apiData); $this->_pro->resetApi(); $api = $this->_setApiProcessableErrors() ->setAmount($amount) diff --git a/app/code/core/Mage/Paypal/Model/Express/Checkout.php b/app/code/core/Mage/Paypal/Model/Express/Checkout.php index 0ec6258ad76..79e8e6ffad2 100644 --- a/app/code/core/Mage/Paypal/Model/Express/Checkout.php +++ b/app/code/core/Mage/Paypal/Model/Express/Checkout.php @@ -158,7 +158,7 @@ public function __construct($params = []) throw new Exception('Config instance is required.'); } $this->_customerSession = isset($params['session']) && $params['session'] instanceof Mage_Customer_Model_Session - ? $params['session'] : Mage::getSingleton('customer/session'); + ? $params['session'] : $this->getCustomerSession(); } /** diff --git a/app/code/core/Mage/Paypal/Model/Standard.php b/app/code/core/Mage/Paypal/Model/Standard.php index 0db8f8a1723..f8683fc2fad 100644 --- a/app/code/core/Mage/Paypal/Model/Standard.php +++ b/app/code/core/Mage/Paypal/Model/Standard.php @@ -48,23 +48,27 @@ public function canUseForCurrency($currencyCode) } /** - * Get paypal session namespace - * - * @return Mage_Paypal_Model_Session - */ + * Get paypal session namespace + * + * @return Mage_Paypal_Model_Session + * @deprecated + * @see getPaypalSession() + */ public function getSession() { - return Mage::getSingleton('paypal/session'); + return $this->getPaypalSession(); } /** * Get checkout session namespace * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ public function getCheckout() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php index e95bfd002a7..d0b3d003502 100644 --- a/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php +++ b/app/code/core/Mage/Paypal/controllers/Adminhtml/Paypal/ReportsController.php @@ -118,11 +118,11 @@ protected function _isAllowed() switch ($action) { case 'index': case 'details': - return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/view'); + return $this->getAdminSession()->isAllowed('report/salesroot/paypal_settlement_reports/view'); case 'fetch': - return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/fetch'); + return $this->getAdminSession()->isAllowed('report/salesroot/paypal_settlement_reports/fetch'); default: - return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports'); + return $this->getAdminSession()->isAllowed('report/salesroot/paypal_settlement_reports'); } } } diff --git a/app/code/core/Mage/Paypal/controllers/HostedproController.php b/app/code/core/Mage/Paypal/controllers/HostedproController.php index d98df970639..c3348ca546c 100644 --- a/app/code/core/Mage/Paypal/controllers/HostedproController.php +++ b/app/code/core/Mage/Paypal/controllers/HostedproController.php @@ -69,10 +69,12 @@ protected function _cancelPayment($errorMsg = '') * Get frontend checkout session object * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckout() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Paypal/controllers/PayflowController.php b/app/code/core/Mage/Paypal/controllers/PayflowController.php index f9b10a31960..c52e984aec9 100644 --- a/app/code/core/Mage/Paypal/controllers/PayflowController.php +++ b/app/code/core/Mage/Paypal/controllers/PayflowController.php @@ -119,10 +119,12 @@ protected function _cancelPayment($errorMsg = '') * Get frontend checkout session object * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckout() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Paypal/controllers/PayflowadvancedController.php b/app/code/core/Mage/Paypal/controllers/PayflowadvancedController.php index c2a4ae43ae6..201c05a35f2 100644 --- a/app/code/core/Mage/Paypal/controllers/PayflowadvancedController.php +++ b/app/code/core/Mage/Paypal/controllers/PayflowadvancedController.php @@ -139,10 +139,12 @@ protected function _cancelPayment($errorMsg = '') * Get frontend checkout session object * * @return Mage_Checkout_Model_Session + * @deprecated + * @see getCheckoutSession() */ protected function _getCheckout() { - return Mage::getSingleton('checkout/session'); + return $this->getCheckoutSession(); } /** diff --git a/app/code/core/Mage/Paypal/controllers/StandardController.php b/app/code/core/Mage/Paypal/controllers/StandardController.php index b5455687a72..105dc917004 100644 --- a/app/code/core/Mage/Paypal/controllers/StandardController.php +++ b/app/code/core/Mage/Paypal/controllers/StandardController.php @@ -44,7 +44,7 @@ public function getOrder() */ protected function _expireAjax() { - if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) { + if (!$this->getCheckoutSession()->getQuote()->hasItems()) { $this->getResponse()->setHeader('HTTP/1.1', '403 Session Expired'); exit; } @@ -66,7 +66,7 @@ public function getStandard() */ public function redirectAction() { - $session = Mage::getSingleton('checkout/session'); + $session = $this->getCheckoutSession(); $session->setPaypalStandardQuoteId($session->getQuoteId()); $this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml()); $session->unsQuoteId(); @@ -78,7 +78,7 @@ public function redirectAction() */ public function cancelAction() { - $session = Mage::getSingleton('checkout/session'); + $session = $this->getCheckoutSession(); $session->setQuoteId($session->getPaypalStandardQuoteId(true)); if ($session->getLastRealOrderId()) { $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId()); @@ -98,9 +98,9 @@ public function cancelAction() */ public function successAction() { - $session = Mage::getSingleton('checkout/session'); + $session = $this->getCheckoutSession(); $session->setQuoteId($session->getPaypalStandardQuoteId(true)); - Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save(); + $this->getCheckoutSession()->getQuote()->setIsActive(false)->save(); $this->_redirect('checkout/onepage/success', ['_secure' => true]); } } diff --git a/app/code/core/Mage/Persistent/Helper/Session.php b/app/code/core/Mage/Persistent/Helper/Session.php index dd3ecd81c08..e47f740fad5 100644 --- a/app/code/core/Mage/Persistent/Helper/Session.php +++ b/app/code/core/Mage/Persistent/Helper/Session.php @@ -90,10 +90,10 @@ public function isRememberMeChecked() { if (is_null($this->_isRememberMeChecked)) { //Try to get from checkout session - $isRememberMeChecked = Mage::getSingleton('checkout/session')->getRememberMeChecked(); + $isRememberMeChecked = $this->getCheckoutSession()->getRememberMeChecked(); if (!is_null($isRememberMeChecked)) { $this->_isRememberMeChecked = $isRememberMeChecked; - Mage::getSingleton('checkout/session')->unsRememberMeChecked(); + $this->getCheckoutSession()->unsRememberMeChecked(); return $isRememberMeChecked; } diff --git a/app/code/core/Mage/Persistent/Model/Observer.php b/app/code/core/Mage/Persistent/Model/Observer.php index f3ae96c94e5..0e78615f9a6 100644 --- a/app/code/core/Mage/Persistent/Model/Observer.php +++ b/app/code/core/Mage/Persistent/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Persistent */ -class Mage_Persistent_Model_Observer +class Mage_Persistent_Model_Observer extends Mage_Core_Model_Observer { /** * Whether set quote to be persistent in workflow @@ -38,7 +38,7 @@ class Mage_Persistent_Model_Observer public function applyPersistentData($observer) { if (!Mage::helper('persistent')->canProcess($observer) - || !$this->_getPersistentHelper()->isPersistent() || Mage::getSingleton('customer/session')->isLoggedIn() + || !$this->_getPersistentHelper()->isPersistent() || $this->getCustomerSession()->isLoggedIn() ) { return $this; } @@ -56,7 +56,7 @@ public function applyPersistentData($observer) */ public function applyBlockPersistentData($observer) { - if (!$this->_getPersistentHelper()->isPersistent() || Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->_getPersistentHelper()->isPersistent() || $this->getCustomerSession()->isLoggedIn()) { return $this; } @@ -164,7 +164,7 @@ public function emulateQuote($observer) ]; if (!Mage::helper('persistent')->canProcess($observer) - || !$this->_getPersistentHelper()->isPersistent() || Mage::getSingleton('customer/session')->isLoggedIn() + || !$this->_getPersistentHelper()->isPersistent() || $this->getCustomerSession()->isLoggedIn() ) { return; } @@ -177,7 +177,7 @@ public function emulateQuote($observer) return; } - $checkoutSession = Mage::getSingleton('checkout/session'); + $checkoutSession = $this->getCheckoutSession(); if ($this->_isShoppingCartPersist()) { $checkoutSession->setCustomer($this->_getPersistentCustomer()); if (!$checkoutSession->hasQuote()) { @@ -283,8 +283,7 @@ protected function _checkClearCheckoutSessionNecessity($observer) */ public function customerAuthenticatedEvent($observer) { - /** @var Mage_Customer_Model_Session $customerSession */ - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); $customerSession->setCustomerId(null)->setCustomerGroupId(null); if (Mage::app()->getRequest()->getParam('context') != 'checkout') { @@ -307,8 +306,7 @@ public function removePersistentCookie($observer) } $this->_getPersistentHelper()->getSession()->removePersistentCookie(); - /** @var Mage_Customer_Model_Session $customerSession */ - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); if (!$customerSession->isLoggedIn()) { $customerSession->setCustomerId(null)->setCustomerGroupId(null); } @@ -342,12 +340,12 @@ public function preventExpressCheckout($observer) /** @var Mage_Core_Controller_Front_Action $controllerAction */ $controllerAction = $observer->getEvent()->getControllerAction(); if (method_exists($controllerAction, 'redirectLogin')) { - Mage::getSingleton('core/session')->addNotice( + $this->getCoreSession()->addNotice( Mage::helper('persistent')->__('To proceed to Checkout, please log in using your email address.'), ); $controllerAction->redirectLogin(); if ($controllerAction instanceof Mage_Paypal_Controller_Express_Abstract) { - Mage::getSingleton('customer/session') + $this->getCustomerSession() ->setBeforeAuthUrl(Mage::getUrl('persistent/index/expressCheckout')); } } @@ -414,7 +412,7 @@ protected function _isPersistent() */ protected function _isLoggedOut() { - return $this->_isPersistent() && !Mage::getSingleton('customer/session')->isLoggedIn(); + return $this->_isPersistent() && !$this->getCustomerSession()->isLoggedIn(); } /** @@ -435,10 +433,10 @@ protected function _isGuestShoppingCart() public function setQuoteGuest($checkQuote = false) { /** @var Mage_Sales_Model_Quote $quote */ - $quote = Mage::getSingleton('checkout/session')->getQuote(); + $quote = $this->getCheckoutSession()->getQuote(); if ($quote && $quote->getId()) { if ($checkQuote && !Mage::helper('persistent')->isShoppingCartPersist() && !$quote->getIsPersistent()) { - Mage::getSingleton('checkout/session')->unsetAll(); + $this->getCheckoutSession()->unsetAll(); return; } @@ -473,12 +471,12 @@ public function checkExpirePersistentQuote(Varien_Event_Observer $observer) return; } - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); if (Mage::helper('persistent')->isEnabled() && !$this->_isPersistent() && !$customerSession->isLoggedIn() - && Mage::getSingleton('checkout/session')->getQuoteId() + && $this->getCheckoutSession()->getQuoteId() && !($observer->getControllerAction() instanceof Mage_Checkout_OnepageController) // persistent session does not expire on onepage checkout page to not spoil customer group id ) { @@ -492,8 +490,7 @@ public function checkExpirePersistentQuote(Varien_Event_Observer $observer) */ protected function _expirePersistentSession() { - /** @var Mage_Checkout_Model_Session $checkoutSession */ - $checkoutSession = Mage::getSingleton('checkout/session'); + $checkoutSession = $this->getCheckoutSession(); $quote = $checkoutSession->setLoadInactive()->getQuote(); if ($quote->getIsActive() && $quote->getCustomerId()) { @@ -536,7 +533,7 @@ public function createPersistentHandleLayout(Varien_Event_Observer $observer) if (Mage::helper('persistent')->canProcess($observer) && $layout && Mage::helper('persistent')->isEnabled() && Mage::helper('persistent/session')->isPersistent() ) { - $handle = (Mage::getSingleton('customer/session')->isLoggedIn()) + $handle = ($this->getCustomerSession()->isLoggedIn()) ? Mage_Persistent_Helper_Data::LOGGED_IN_LAYOUT_HANDLE : Mage_Persistent_Helper_Data::LOGGED_OUT_LAYOUT_HANDLE; $layout->getUpdate()->addHandle($handle); @@ -579,7 +576,7 @@ public function emulateCustomer($observer) $customer = Mage::getModel('customer/customer')->load( $this->_getPersistentHelper()->getSession()->getCustomerId(), ); - Mage::getSingleton('customer/session') + $this->getCustomerSession() ->setCustomerId($customer->getId()) ->setCustomerGroupId($customer->getGroupId()); } diff --git a/app/code/core/Mage/Persistent/Model/Observer/Session.php b/app/code/core/Mage/Persistent/Model/Observer/Session.php index 0bec6a72e1d..def6ce6bd3e 100644 --- a/app/code/core/Mage/Persistent/Model/Observer/Session.php +++ b/app/code/core/Mage/Persistent/Model/Observer/Session.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Persistent */ -class Mage_Persistent_Model_Observer_Session +class Mage_Persistent_Model_Observer_Session extends Mage_Core_Model_Observer { /** * Create/Update and Load session when customer log in @@ -106,7 +106,7 @@ public function synchronizePersistentInfo(Varien_Event_Observer $observer) $request = $observer->getEvent()->getFront()->getRequest(); // Quote Id could be changed only by logged in customer - if (Mage::getSingleton('customer/session')->isLoggedIn() + if ($this->getCustomerSession()->isLoggedIn() || ($request && $request->getActionName() == 'logout' && $request->getControllerName() == 'account') ) { $sessionModel->save(); @@ -131,7 +131,7 @@ public function setRememberMeCheckedStatus(Varien_Event_Observer $observer) if ($controllerAction->getFullActionName() == 'checkout_onepage_saveBilling' || $controllerAction->getFullActionName() == 'customer_account_createpost' ) { - Mage::getSingleton('checkout/session')->setRememberMeChecked((bool) $rememberMeCheckbox); + $this->getCheckoutSession()->setRememberMeChecked((bool) $rememberMeCheckbox); } } } @@ -149,7 +149,7 @@ public function renewCookie(Varien_Event_Observer $observer) $controllerAction = $observer->getEvent()->getControllerAction(); - if (Mage::getSingleton('customer/session')->isLoggedIn() + if ($this->getCustomerSession()->isLoggedIn() || $controllerAction->getFullActionName() == 'customer_account_logout' ) { Mage::getSingleton('core/cookie')->renew( diff --git a/app/code/core/Mage/Persistent/controllers/IndexController.php b/app/code/core/Mage/Persistent/controllers/IndexController.php index 24dc52ded3f..327eb547e0c 100644 --- a/app/code/core/Mage/Persistent/controllers/IndexController.php +++ b/app/code/core/Mage/Persistent/controllers/IndexController.php @@ -70,12 +70,12 @@ public function unsetCookieAction() protected function _cleanup() { Mage::dispatchEvent('persistent_session_expired'); - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); $customerSession ->setCustomerId(null) ->setCustomerGroupId(null); if ($this->_clearCheckoutSession) { - Mage::getSingleton('checkout/session')->unsetAll(); + $this->getCheckoutSession()->unsetAll(); } $this->_getHelper()->getSession()->removePersistentCookie(); return $this; @@ -88,8 +88,7 @@ public function saveMethodAction() { if ($this->_getHelper()->isPersistent()) { $this->_getHelper()->getSession()->removePersistentCookie(); - /** @var Mage_Customer_Model_Session $customerSession */ - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); if (!$customerSession->isLoggedIn()) { $customerSession->setCustomerId(null) ->setCustomerGroupId(null); @@ -108,7 +107,7 @@ public function saveMethodAction() */ public function expressCheckoutAction() { - Mage::getSingleton('core/session')->addNotice( + $this->getCoreSession()->addNotice( Mage::helper('persistent')->__('Shopping cart has been updated with appropriate prices'), ); $this->_redirect('checkout/cart'); diff --git a/app/code/core/Mage/ProductAlert/Helper/Data.php b/app/code/core/Mage/ProductAlert/Helper/Data.php index 2046040f370..8e03a6134d4 100644 --- a/app/code/core/Mage/ProductAlert/Helper/Data.php +++ b/app/code/core/Mage/ProductAlert/Helper/Data.php @@ -58,10 +58,12 @@ public function setProduct($product) /** * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ public function getCustomer() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** diff --git a/app/code/core/Mage/ProductAlert/controllers/AddController.php b/app/code/core/Mage/ProductAlert/controllers/AddController.php index 1ba9422fdb8..04f6b737584 100644 --- a/app/code/core/Mage/ProductAlert/controllers/AddController.php +++ b/app/code/core/Mage/ProductAlert/controllers/AddController.php @@ -29,10 +29,10 @@ public function preDispatch() { parent::preDispatch(); - if (!Mage::getSingleton('customer/session')->authenticate($this)) { + if (!$this->getCustomerSession()->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); - if (!Mage::getSingleton('customer/session')->getBeforeUrl()) { - Mage::getSingleton('customer/session')->setBeforeUrl($this->_getRefererUrl()); + if (!$this->getCustomerSession()->getBeforeUrl()) { + $this->getCustomerSession()->setBeforeUrl($this->_getRefererUrl()); } } return $this; @@ -47,7 +47,7 @@ public function testObserverAction() public function priceAction() { - $session = Mage::getSingleton('catalog/session'); + $session = $this->getCatalogSession(); $backUrl = $this->getRequest()->getParam(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED); $productId = (int) $this->getRequest()->getParam('product_id'); if (!$backUrl || !$productId) { @@ -69,7 +69,7 @@ public function priceAction() try { $model = Mage::getModel('productalert/price') - ->setCustomerId(Mage::getSingleton('customer/session')->getId()) + ->setCustomerId($this->getCustomerSession()->getId()) ->setProductId($product->getId()) ->setPrice($product->getFinalPrice()) ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); @@ -83,8 +83,7 @@ public function priceAction() public function stockAction() { - $session = Mage::getSingleton('catalog/session'); - /** @var Mage_Catalog_Model_Session $session */ + $session = $this->getCatalogSession(); $backUrl = $this->getRequest()->getParam(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED); $productId = (int) $this->getRequest()->getParam('product_id'); if (!$backUrl || !$productId) { @@ -92,8 +91,9 @@ public function stockAction() return ; } - if (!$product = Mage::getModel('catalog/product')->load($productId)) { - /** @var Mage_Catalog_Model_Product $product */ + /** @var Mage_Catalog_Model_Product $product */ + $product = Mage::getModel('catalog/product')->load($productId); + if (!$product) { $session->addError($this->__('Not enough parameters.')); $this->_redirectUrl($backUrl); return ; @@ -101,7 +101,7 @@ public function stockAction() try { $model = Mage::getModel('productalert/stock') - ->setCustomerId(Mage::getSingleton('customer/session')->getId()) + ->setCustomerId($this->getCustomerSession()->getId()) ->setProductId($product->getId()) ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); $model->save(); diff --git a/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php b/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php index 185810faef4..92f1fe964dd 100644 --- a/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php +++ b/app/code/core/Mage/ProductAlert/controllers/UnsubscribeController.php @@ -26,10 +26,10 @@ public function preDispatch() { parent::preDispatch(); - if (!Mage::getSingleton('customer/session')->authenticate($this)) { + if (!$this->getCustomerSession()->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); - if (!Mage::getSingleton('customer/session')->getBeforeUrl()) { - Mage::getSingleton('customer/session')->setBeforeUrl($this->_getRefererUrl()); + if (!$this->getCustomerSession()->getBeforeUrl()) { + $this->getCustomerSession()->setBeforeUrl($this->_getRefererUrl()); } } return $this; @@ -43,20 +43,20 @@ public function priceAction() $this->_redirect(''); return; } - $session = Mage::getSingleton('catalog/session'); - /** @var Mage_Catalog_Model_Session $session */ + $session = $this->getCatalogSession(); + + /** @var Mage_Catalog_Model_Product $product */ $product = Mage::getModel('catalog/product')->load($productId); if (!$product->getId() || !$product->isVisibleInCatalog()) { - /** @var Mage_Catalog_Model_Product $product */ - Mage::getSingleton('customer/session')->addError($this->__('The product is not found.')); + $this->getCustomerSession()->addError($this->__('The product is not found.')); $this->_redirect('customer/account/'); return ; } try { $model = Mage::getModel('productalert/price') - ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) + ->setCustomerId($this->getCustomerSession()->getCustomerId()) ->setProductId($product->getId()) ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) ->loadByParam(); @@ -73,8 +73,7 @@ public function priceAction() public function priceAllAction() { - $session = Mage::getSingleton('customer/session'); - /** @var Mage_Customer_Model_Session $session */ + $session = $this->getCustomerSession(); try { Mage::getModel('productalert/price')->deleteCustomer( @@ -97,18 +96,18 @@ public function stockAction() return; } - $session = Mage::getSingleton('catalog/session'); + $session = $this->getCatalogSession(); $product = Mage::getModel('catalog/product')->load($productId); if (!$product->getId() || !$product->isVisibleInCatalog()) { - Mage::getSingleton('customer/session')->addError($this->__('The product was not found.')); + $this->getCustomerSession()->addError($this->__('The product was not found.')); $this->_redirect('customer/account/'); return ; } try { $model = Mage::getModel('productalert/stock') - ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) + ->setCustomerId($this->getCustomerSession()->getCustomerId()) ->setProductId($product->getId()) ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) ->loadByParam(); @@ -124,7 +123,7 @@ public function stockAction() public function stockAllAction() { - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); try { Mage::getModel('productalert/stock')->deleteCustomer( diff --git a/app/code/core/Mage/Rating/Model/Resource/Rating/Option.php b/app/code/core/Mage/Rating/Model/Resource/Rating/Option.php index 14ba4dc0b61..a6cb74846c4 100644 --- a/app/code/core/Mage/Rating/Model/Resource/Rating/Option.php +++ b/app/code/core/Mage/Rating/Model/Resource/Rating/Option.php @@ -110,7 +110,7 @@ public function addVote($option) if (!$option->getDoUpdate()) { $data['remote_ip'] = Mage::helper('core/http')->getRemoteAddr(); $data['remote_ip_long'] = Mage::helper('core/http')->getRemoteAddr(true); - $data['customer_id'] = $option->getCustomerId() ?? Mage::getSingleton('customer/session')->getCustomerId(); + $data['customer_id'] = $option->getCustomerId() ?? $this->getCustomerSession()->getCustomerId(); $data['entity_pk_value'] = $option->getEntityPkValue(); $data['rating_id'] = $option->getRatingId(); } diff --git a/app/code/core/Mage/Reports/Model/Event/Observer.php b/app/code/core/Mage/Reports/Model/Event/Observer.php index 60542a40562..0148897ce1d 100644 --- a/app/code/core/Mage/Reports/Model/Event/Observer.php +++ b/app/code/core/Mage/Reports/Model/Event/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Reports */ -class Mage_Reports_Model_Event_Observer +class Mage_Reports_Model_Event_Observer extends Mage_Core_Model_Observer { protected $_enabledReports = true; @@ -46,8 +46,8 @@ public function __construct() protected function _event($eventTypeId, $objectId, $subjectId = null, $subtype = 0) { if (is_null($subjectId)) { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $customer = Mage::getSingleton('customer/session')->getCustomer(); + if ($this->getCustomerSession()->isLoggedIn()) { + $customer = $this->getCustomerSession()->getCustomer(); $subjectId = $customer->getId(); } else { $subjectId = Mage::getSingleton('log/visitor')->getId(); @@ -75,12 +75,12 @@ protected function _event($eventTypeId, $objectId, $subjectId = null, $subtype = */ public function customerLogin(Varien_Event_Observer $observer) { - if (!Mage::getSingleton('customer/session')->isLoggedIn() || !$this->_enabledReports) { + if (!$this->getCustomerSession()->isLoggedIn() || !$this->_enabledReports) { return $this; } $visitorId = Mage::getSingleton('log/visitor')->getId(); - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); $eventModel = Mage::getModel('reports/event'); $eventModel->updateCustomerType($visitorId, $customerId); diff --git a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php index 8ff5ff2606c..144a319262c 100644 --- a/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Product/Index/Abstract.php @@ -106,7 +106,7 @@ public function getCustomerId() if ($this->hasData('customer_id')) { return $this->getData('customer_id'); } - return Mage::getSingleton('customer/session')->getCustomerId(); + return $this->getCustomerSession()->getCustomerId(); } /** @@ -150,10 +150,12 @@ public function purgeVisitorByCustomer() * Retrieve Reports Session instance * * @return Mage_Reports_Model_Session + * @deprecated + * @see getReportsSession() */ protected function _getSession() { - return Mage::getSingleton('reports/session'); + return $this->getReportsSession(); } /** diff --git a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Collection/Abstract.php index 7d2589e6531..b494bfb039f 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Product/Index/Collection/Abstract.php +++ b/app/code/core/Mage/Reports/Model/Resource/Product/Index/Collection/Abstract.php @@ -105,8 +105,8 @@ protected function _getWhereCondition() { $condition = []; - if (Mage::getSingleton('customer/session')->isLoggedIn()) { - $condition['customer_id'] = Mage::getSingleton('customer/session')->getCustomerId(); + if ($this->getCustomerSession()->isLoggedIn()) { + $condition['customer_id'] = $this->getCustomerSession()->getCustomerId(); } elseif ($this->_customerId) { $condition['customer_id'] = $this->_customerId; } else { diff --git a/app/code/core/Mage/Review/Block/Customer/List.php b/app/code/core/Mage/Review/Block/Customer/List.php index 435624b02a0..920df1a067f 100644 --- a/app/code/core/Mage/Review/Block/Customer/List.php +++ b/app/code/core/Mage/Review/Block/Customer/List.php @@ -37,7 +37,7 @@ protected function _construct() $this->_collection = Mage::getModel('review/review')->getProductCollection(); $this->_collection ->addStoreFilter(Mage::app()->getStore()->getId()) - ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId()) + ->addCustomerFilter($this->getCustomerSession()->getCustomerId()) ->setDateOrder(); } diff --git a/app/code/core/Mage/Review/Block/Customer/Recent.php b/app/code/core/Mage/Review/Block/Customer/Recent.php index 8be5f909d59..77ea31c0c1c 100644 --- a/app/code/core/Mage/Review/Block/Customer/Recent.php +++ b/app/code/core/Mage/Review/Block/Customer/Recent.php @@ -36,7 +36,7 @@ public function __construct() $this->_collection ->addStoreFilter(Mage::app()->getStore()->getId()) - ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId()) + ->addCustomerFilter($this->getCustomerSession()->getCustomerId()) ->setDateOrder() ->setPageSize(5) ->load() diff --git a/app/code/core/Mage/Review/Block/Customer/View.php b/app/code/core/Mage/Review/Block/Customer/View.php index f87e9072b39..c7af21b7107 100644 --- a/app/code/core/Mage/Review/Block/Customer/View.php +++ b/app/code/core/Mage/Review/Block/Customer/View.php @@ -136,6 +136,6 @@ public function dateFormat($date) */ public function isReviewOwner() { - return ($this->getReviewData()->getCustomerId() == Mage::getSingleton('customer/session')->getCustomerId()); + return ($this->getReviewData()->getCustomerId() == $this->getCustomerSession()->getCustomerId()); } } diff --git a/app/code/core/Mage/Review/Block/Form.php b/app/code/core/Mage/Review/Block/Form.php index abe8cb289c3..bcd0a411c59 100644 --- a/app/code/core/Mage/Review/Block/Form.php +++ b/app/code/core/Mage/Review/Block/Form.php @@ -28,11 +28,11 @@ class Mage_Review_Block_Form extends Mage_Core_Block_Template { public function __construct() { - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); parent::__construct(); - $data = Mage::getSingleton('review/session')->getFormData(true); + $data = $this->getReviewSession()->getFormData(true); $data = new Varien_Object($data); // add logged in customer name as nickname @@ -61,7 +61,7 @@ public function __construct() $this->setTemplate('review/form.phtml') ->assign('data', $data) - ->assign('messages', Mage::getSingleton('review/session')->getMessages(true)); + ->assign('messages', $this->getReviewSession()->getMessages(true)); } /** diff --git a/app/code/core/Mage/Review/Model/Session.php b/app/code/core/Mage/Review/Model/Session.php index 072cafdc139..43a43f72d0f 100644 --- a/app/code/core/Mage/Review/Model/Session.php +++ b/app/code/core/Mage/Review/Model/Session.php @@ -22,7 +22,7 @@ * * @method array getFormData() * @method $this setFormData(array $value) - * @method array getRedirectUrl() + * @method string getRedirectUrl() * @method $this setRedirectUrl(string $value) */ class Mage_Review_Model_Session extends Mage_Core_Model_Session_Abstract diff --git a/app/code/core/Mage/Review/controllers/CustomerController.php b/app/code/core/Mage/Review/controllers/CustomerController.php index 4590121ea55..67fdc480a46 100644 --- a/app/code/core/Mage/Review/controllers/CustomerController.php +++ b/app/code/core/Mage/Review/controllers/CustomerController.php @@ -30,7 +30,7 @@ class Mage_Review_CustomerController extends Mage_Core_Controller_Front_Action public function preDispatch() { parent::preDispatch(); - if (!Mage::getSingleton('customer/session')->authenticate($this)) { + if (!$this->getCustomerSession()->authenticate($this)) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); } return $this; @@ -51,7 +51,7 @@ protected function _loadReview($reviewId) /** @var Mage_Review_Model_Review $review */ $review = Mage::getModel('review/review')->load($reviewId); - if (!$review->getId() || $review->getCustomerId() != Mage::getSingleton('customer/session')->getCustomerId()) { + if (!$review->getId() || $review->getCustomerId() != $this->getCustomerSession()->getCustomerId()) { return false; } @@ -61,7 +61,7 @@ protected function _loadReview($reviewId) public function indexAction() { $this->loadLayout(); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); if ($navigationBlock = $this->getLayout()->getBlock('customer_account_navigation')) { $navigationBlock->setActive('review/customer'); diff --git a/app/code/core/Mage/Review/controllers/ProductController.php b/app/code/core/Mage/Review/controllers/ProductController.php index c389c97602d..04e59b7dce7 100644 --- a/app/code/core/Mage/Review/controllers/ProductController.php +++ b/app/code/core/Mage/Review/controllers/ProductController.php @@ -43,10 +43,10 @@ public function preDispatch() $action = strtolower($this->getRequest()->getActionName()); if (!$allowGuest && $action == 'post' && $this->getRequest()->isPost()) { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); - Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', ['_current' => true])); - Mage::getSingleton('review/session')->setFormData($this->getRequest()->getPost()) + $this->getCustomerSession()->setBeforeAuthUrl(Mage::getUrl('*/*/*', ['_current' => true])); + $this->getReviewSession()->setFormData($this->getRequest()->getPost()) ->setRedirectUrl($this->_getRefererUrl()); $this->_redirectUrl(Mage::helper('customer')->getLoginUrl()); } @@ -152,7 +152,7 @@ public function postAction() return; } - if ($data = Mage::getSingleton('review/session')->getFormData(true)) { + if ($data = $this->getReviewSession()->getFormData(true)) { $rating = []; if (isset($data['ratings']) && is_array($data['ratings'])) { $rating = $data['ratings']; @@ -163,10 +163,9 @@ public function postAction() } if (($product = $this->_initProduct()) && !empty($data)) { - $session = Mage::getSingleton('core/session'); - /** @var Mage_Core_Model_Session $session */ - $review = Mage::getModel('review/review')->setData($this->_cropReviewData($data)); + $session = $this->getCoreSession(); /** @var Mage_Review_Model_Review $review */ + $review = Mage::getModel('review/review')->setData($this->_cropReviewData($data)); $validate = $review->validate(); if ($validate === true) { @@ -174,7 +173,7 @@ public function postAction() $review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE)) ->setEntityPkValue($product->getId()) ->setStatusId(Mage_Review_Model_Review::STATUS_PENDING) - ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) + ->setCustomerId($this->getCustomerSession()->getCustomerId()) ->setStoreId(Mage::app()->getStore()->getId()) ->setStores([Mage::app()->getStore()->getId()]) ->save(); @@ -183,7 +182,7 @@ public function postAction() Mage::getModel('rating/rating') ->setRatingId($ratingId) ->setReviewId($review->getId()) - ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId()) + ->setCustomerId($this->getCustomerSession()->getCustomerId()) ->addOptionVote($optionId, $product->getId()); } @@ -205,7 +204,7 @@ public function postAction() } } - if ($redirectUrl = Mage::getSingleton('review/session')->getRedirectUrl(true)) { + if ($redirectUrl = $this->getReviewSession()->getRedirectUrl(true)) { $this->_redirectUrl($redirectUrl); return; } @@ -265,8 +264,8 @@ public function viewAction() } $this->loadLayout(); - $this->_initLayoutMessages('review/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getReviewSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $this->renderLayout(); } diff --git a/app/code/core/Mage/Rss/Block/Abstract.php b/app/code/core/Mage/Rss/Block/Abstract.php index e2b4ef43d21..728a5d65175 100644 --- a/app/code/core/Mage/Rss/Block/Abstract.php +++ b/app/code/core/Mage/Rss/Block/Abstract.php @@ -47,7 +47,7 @@ protected function _getCustomerGroupId() //customer group id $custGroupID = (int) $this->getRequest()->getParam('cid'); if ($custGroupID == null) { - $custGroupID = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $custGroupID = $this->getCustomerSession()->getCustomerGroupId(); } return $custGroupID; } diff --git a/app/code/core/Mage/Rss/Block/List.php b/app/code/core/Mage/Rss/Block/List.php index 00fecd43992..698214d82fc 100644 --- a/app/code/core/Mage/Rss/Block/List.php +++ b/app/code/core/Mage/Rss/Block/List.php @@ -100,7 +100,7 @@ public function getCurrentStoreId() */ public function getCurrentCustomerGroupId() { - return Mage::getSingleton('customer/session')->getCustomerGroupId(); + return $this->getCustomerSession()->getCustomerGroupId(); } /** diff --git a/app/code/core/Mage/Rss/Block/Wishlist.php b/app/code/core/Mage/Rss/Block/Wishlist.php index aa650f287ee..01aa916d116 100644 --- a/app/code/core/Mage/Rss/Block/Wishlist.php +++ b/app/code/core/Mage/Rss/Block/Wishlist.php @@ -75,7 +75,7 @@ protected function _getCustomer() $params = Mage::helper('core')->urlDecode($this->getRequest()->getParam('data')); $data = explode(',', $params); $cId = abs((int) $data[0]); - if ($cId && ($cId == Mage::getSingleton('customer/session')->getCustomerId())) { + if ($cId && ($cId == $this->getCustomerSession()->getCustomerId())) { $this->_customer->load($cId); } } diff --git a/app/code/core/Mage/Rss/Helper/Data.php b/app/code/core/Mage/Rss/Helper/Data.php index 1203cd46730..61841869bf2 100644 --- a/app/code/core/Mage/Rss/Helper/Data.php +++ b/app/code/core/Mage/Rss/Helper/Data.php @@ -39,8 +39,8 @@ class Mage_Rss_Helper_Data extends Mage_Core_Helper_Abstract public function __construct(array $params = []) { - $this->_rssSession = $params['rss_session'] ?? Mage::getSingleton('rss/session'); - $this->_adminSession = $params['admin_session'] ?? Mage::getSingleton('admin/session'); + $this->_rssSession = $params['rss_session'] ?? $this->getRssSession(); + $this->_adminSession = $params['admin_session'] ?? $this->getAdminSession(); } /** diff --git a/app/code/core/Mage/Rss/controllers/IndexController.php b/app/code/core/Mage/Rss/controllers/IndexController.php index 957d54a2982..b75129e99c2 100644 --- a/app/code/core/Mage/Rss/controllers/IndexController.php +++ b/app/code/core/Mage/Rss/controllers/IndexController.php @@ -88,7 +88,7 @@ public function wishlistAction() return ; } - if (Mage::getSingleton('customer/session')->authenticate($this) + if ($this->getCustomerSession()->authenticate($this) && $wishlist->getCustomerId() == $this->_getCustomer()->getId() ) { $this->_showWishlistRss(); @@ -141,7 +141,7 @@ protected function _getCustomer() $params = $this->_getHelper('core')->urlDecode($this->getRequest()->getParam('data')); $data = explode(',', $params); $customerId = abs((int) $data[0]); - if ($customerId && ($customerId == Mage::getSingleton('customer/session')->getCustomerId())) { + if ($customerId && ($customerId == $this->getCustomerSession()->getCustomerId())) { $this->_customer->load($customerId); } } diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php index c58fe9b389c..86d41b60546 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Billing/Agreement/View.php @@ -95,6 +95,6 @@ protected function _getBillingAgreement() */ protected function _isAllowed($action) { - return Mage::getSingleton('admin/session')->isAllowed($action); + return $this->getAdminSession()->isAllowed($action); } } diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php index 556d89085a4..85fa809ad09 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Recurring/Profile/View/Tab/Orders.php @@ -110,7 +110,7 @@ protected function _prepareColumns() 'options' => Mage::getSingleton('sales/order_config')->getStatuses(), ]); - if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { + if ($this->getAdminSession()->isAllowed('sales/order/actions/view')) { $this->addColumn( 'action', [ diff --git a/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php b/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php index d57111c88ab..808f079cbf5 100644 --- a/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php +++ b/app/code/core/Mage/Sales/Block/Billing/Agreement/View.php @@ -62,7 +62,7 @@ public function getRelatedOrders() if (is_null($this->_relatedOrders)) { $this->_relatedOrders = Mage::getResourceModel('sales/order_collection') ->addFieldToSelect('*') - ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId()) + ->addFieldToFilter('customer_id', $this->getCustomerSession()->getCustomer()->getId()) ->addFieldToFilter( 'state', ['in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()], diff --git a/app/code/core/Mage/Sales/Block/Billing/Agreements.php b/app/code/core/Mage/Sales/Block/Billing/Agreements.php index 0acb7e2029f..c2e94f7e677 100644 --- a/app/code/core/Mage/Sales/Block/Billing/Agreements.php +++ b/app/code/core/Mage/Sales/Block/Billing/Agreements.php @@ -62,7 +62,7 @@ public function getBillingAgreements() { if (is_null($this->_billingAgreements)) { $this->_billingAgreements = Mage::getResourceModel('sales/billing_agreement_collection') - ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomerId()) + ->addFieldToFilter('customer_id', $this->getCustomerSession()->getCustomerId()) ->setOrder('agreement_id', 'desc'); } return $this->_billingAgreements; diff --git a/app/code/core/Mage/Sales/Block/Guest/Links.php b/app/code/core/Mage/Sales/Block/Guest/Links.php index 2baa8571ff0..f062510363b 100644 --- a/app/code/core/Mage/Sales/Block/Guest/Links.php +++ b/app/code/core/Mage/Sales/Block/Guest/Links.php @@ -27,7 +27,7 @@ class Mage_Sales_Block_Guest_Links extends Mage_Page_Block_Template_Links_Block */ public function __construct() { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { parent::__construct(); $this->_label = $this->__('Orders and Returns'); diff --git a/app/code/core/Mage/Sales/Block/Order/Creditmemo.php b/app/code/core/Mage/Sales/Block/Order/Creditmemo.php index cb5a195e537..25148dcd099 100644 --- a/app/code/core/Mage/Sales/Block/Order/Creditmemo.php +++ b/app/code/core/Mage/Sales/Block/Order/Creditmemo.php @@ -74,7 +74,7 @@ public function getOrder() */ public function getBackUrl() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::getUrl('*/*/history'); } return Mage::getUrl('*/*/form'); @@ -87,7 +87,7 @@ public function getBackUrl() */ public function getBackTitle() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::helper('sales')->__('Back to My Orders'); } return Mage::helper('sales')->__('View Another Order'); diff --git a/app/code/core/Mage/Sales/Block/Order/History.php b/app/code/core/Mage/Sales/Block/Order/History.php index 11bb4e93155..e1fbe61cf89 100644 --- a/app/code/core/Mage/Sales/Block/Order/History.php +++ b/app/code/core/Mage/Sales/Block/Order/History.php @@ -32,7 +32,7 @@ public function __construct() $orders = Mage::getResourceModel('sales/order_collection') ->addFieldToSelect('*') - ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId()) + ->addFieldToFilter('customer_id', $this->getCustomerSession()->getCustomer()->getId()) ->addFieldToFilter('state', ['in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()]) ->setOrder('created_at', 'desc') ; diff --git a/app/code/core/Mage/Sales/Block/Order/Info.php b/app/code/core/Mage/Sales/Block/Order/Info.php index 1d8cbffdab0..ef4c32c2c6f 100644 --- a/app/code/core/Mage/Sales/Block/Order/Info.php +++ b/app/code/core/Mage/Sales/Block/Order/Info.php @@ -131,7 +131,7 @@ private function checkLinks() */ public function getReorderUrl($order) { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { return $this->getUrl('sales/guest/reorder', ['order_id' => $order->getId()]); } return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]); @@ -146,7 +146,7 @@ public function getReorderUrl($order) */ public function getPrintUrl($order) { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { return $this->getUrl('sales/guest/print', ['order_id' => $order->getId()]); } return $this->getUrl('sales/order/print', ['order_id' => $order->getId()]); diff --git a/app/code/core/Mage/Sales/Block/Order/Info/Buttons.php b/app/code/core/Mage/Sales/Block/Order/Info/Buttons.php index 89ad7145e14..14444d90beb 100644 --- a/app/code/core/Mage/Sales/Block/Order/Info/Buttons.php +++ b/app/code/core/Mage/Sales/Block/Order/Info/Buttons.php @@ -46,7 +46,7 @@ public function getOrder() */ public function getPrintUrl($order) { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { return $this->getUrl('sales/guest/print', ['order_id' => $order->getId()]); } return $this->getUrl('sales/order/print', ['order_id' => $order->getId()]); @@ -60,7 +60,7 @@ public function getPrintUrl($order) */ public function getReorderUrl($order) { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { return $this->getUrl('sales/guest/reorder', ['order_id' => $order->getId()]); } return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]); diff --git a/app/code/core/Mage/Sales/Block/Order/Invoice.php b/app/code/core/Mage/Sales/Block/Order/Invoice.php index 48c3d8e82eb..c3835208f1d 100644 --- a/app/code/core/Mage/Sales/Block/Order/Invoice.php +++ b/app/code/core/Mage/Sales/Block/Order/Invoice.php @@ -74,7 +74,7 @@ public function getOrder() */ public function getBackUrl() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::getUrl('*/*/history'); } return Mage::getUrl('*/*/form'); @@ -87,7 +87,7 @@ public function getBackUrl() */ public function getBackTitle() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::helper('sales')->__('Back to My Orders'); } return Mage::helper('sales')->__('View Another Order'); diff --git a/app/code/core/Mage/Sales/Block/Order/Recent.php b/app/code/core/Mage/Sales/Block/Order/Recent.php index 1304ad5f721..dd297005bf1 100644 --- a/app/code/core/Mage/Sales/Block/Order/Recent.php +++ b/app/code/core/Mage/Sales/Block/Order/Recent.php @@ -55,7 +55,7 @@ public function __construct() ) ->addAttributeToFilter( 'customer_id', - Mage::getSingleton('customer/session')->getCustomer()->getId(), + $this->getCustomerSession()->getCustomer()->getId(), ) ->addAttributeToFilter( 'state', diff --git a/app/code/core/Mage/Sales/Block/Order/Shipment.php b/app/code/core/Mage/Sales/Block/Order/Shipment.php index c64c583e8ad..682f4cff91f 100644 --- a/app/code/core/Mage/Sales/Block/Order/Shipment.php +++ b/app/code/core/Mage/Sales/Block/Order/Shipment.php @@ -74,7 +74,7 @@ public function getOrder() */ public function getBackUrl() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::getUrl('*/*/history'); } return Mage::getUrl('*/*/form'); @@ -87,7 +87,7 @@ public function getBackUrl() */ public function getBackTitle() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::helper('sales')->__('Back to My Orders'); } return Mage::helper('sales')->__('View Another Order'); diff --git a/app/code/core/Mage/Sales/Block/Order/View.php b/app/code/core/Mage/Sales/Block/Order/View.php index 76aa4b43742..0157c0cb452 100644 --- a/app/code/core/Mage/Sales/Block/Order/View.php +++ b/app/code/core/Mage/Sales/Block/Order/View.php @@ -74,7 +74,7 @@ public function getOrder() */ public function getBackUrl() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::getUrl('*/*/history'); } return Mage::getUrl('*/*/form'); @@ -87,7 +87,7 @@ public function getBackUrl() */ public function getBackTitle() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return Mage::helper('sales')->__('Back to My Orders'); } return Mage::helper('sales')->__('View Another Order'); diff --git a/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php b/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php index 43f330533b7..9a0ad235edf 100644 --- a/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php +++ b/app/code/core/Mage/Sales/Block/Reorder/Sidebar.php @@ -138,10 +138,12 @@ protected function _toHtml() * Retrieve customer session instance * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getCustomerSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** diff --git a/app/code/core/Mage/Sales/Block/Widget/Guest/Form.php b/app/code/core/Mage/Sales/Block/Widget/Guest/Form.php index a7241658f87..9b3524f808c 100644 --- a/app/code/core/Mage/Sales/Block/Widget/Guest/Form.php +++ b/app/code/core/Mage/Sales/Block/Widget/Guest/Form.php @@ -29,7 +29,7 @@ class Mage_Sales_Block_Widget_Guest_Form extends Mage_Core_Block_Template implem */ public function isEnable() { - return !(Mage::getSingleton('customer/session')->isLoggedIn()); + return !$this->getCustomerSession()->isLoggedIn(); } /** diff --git a/app/code/core/Mage/Sales/Controller/Abstract.php b/app/code/core/Mage/Sales/Controller/Abstract.php index 318f4389fad..ac735434875 100644 --- a/app/code/core/Mage/Sales/Controller/Abstract.php +++ b/app/code/core/Mage/Sales/Controller/Abstract.php @@ -30,7 +30,7 @@ abstract class Mage_Sales_Controller_Abstract extends Mage_Core_Controller_Front */ protected function _canViewOrder($order) { - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); $availableStates = Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates(); if ($order->getId() && $order->getCustomerId() && ($order->getCustomerId() == $customerId) && in_array($order->getState(), $availableStates, $strict = true) @@ -50,7 +50,7 @@ protected function _viewAction() } $this->loadLayout(); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { @@ -135,14 +135,14 @@ public function reorderAction() try { $cart->addOrderItem($item); } catch (Mage_Core_Exception $e) { - if (Mage::getSingleton('checkout/session')->getUseNotice(true)) { - Mage::getSingleton('checkout/session')->addNotice($e->getMessage()); + if ($this->getCheckoutSession()->getUseNotice(true)) { + $this->getCheckoutSession()->addNotice($e->getMessage()); } else { - Mage::getSingleton('checkout/session')->addError($e->getMessage()); + $this->getCheckoutSession()->addError($e->getMessage()); } $this->_redirect('*/*/history'); } catch (Exception $e) { - Mage::getSingleton('checkout/session')->addException( + $this->getCheckoutSession()->addException( $e, Mage::helper('checkout')->__('Cannot add the item to shopping cart.'), ); @@ -188,7 +188,7 @@ public function printInvoiceAction() $this->loadLayout('print'); $this->renderLayout(); } else { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $this->_redirect('*/*/history'); } else { $this->_redirect('sales/guest/form'); @@ -217,7 +217,7 @@ public function printShipmentAction() $this->loadLayout('print'); $this->renderLayout(); } else { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $this->_redirect('*/*/history'); } else { $this->_redirect('sales/guest/form'); @@ -247,7 +247,7 @@ public function printCreditmemoAction() $this->loadLayout('print'); $this->renderLayout(); } else { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $this->_redirect('*/*/history'); } else { $this->_redirect('sales/guest/form'); diff --git a/app/code/core/Mage/Sales/Helper/Guest.php b/app/code/core/Mage/Sales/Helper/Guest.php index c3de548655c..c3965399375 100644 --- a/app/code/core/Mage/Sales/Helper/Guest.php +++ b/app/code/core/Mage/Sales/Helper/Guest.php @@ -37,7 +37,7 @@ class Mage_Sales_Helper_Guest extends Mage_Core_Helper_Data */ public function loadValidOrder() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { Mage::app()->getResponse()->setRedirect(Mage::getUrl('sales/order/history')); return false; } @@ -117,7 +117,7 @@ public function loadValidOrder() } if (!Mage::helper('core')->isRateLimitExceeded(true, false)) { - Mage::getSingleton('core/session')->addError($this->__($errorMessage)); + $this->getCoreSession()->addError($this->__($errorMessage)); } Mage::app()->getResponse()->setRedirect(Mage::getUrl('sales/guest/form')); diff --git a/app/code/core/Mage/Sales/Helper/Reorder.php b/app/code/core/Mage/Sales/Helper/Reorder.php index cab539c4348..7d6785f3762 100644 --- a/app/code/core/Mage/Sales/Helper/Reorder.php +++ b/app/code/core/Mage/Sales/Helper/Reorder.php @@ -56,7 +56,7 @@ public function canReorder(Mage_Sales_Model_Order $order) if (!$this->isAllowed($order->getStore())) { return false; } - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { return $order->canReorder(); } else { return true; diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php index 6863e0111bc..588534d1018 100644 --- a/app/code/core/Mage/Sales/Model/Observer.php +++ b/app/code/core/Mage/Sales/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_Sales */ -class Mage_Sales_Model_Observer +class Mage_Sales_Model_Observer extends Mage_Core_Model_Observer { /** * Expire quotes additional fields to filter @@ -286,7 +286,7 @@ public function restrictAdminBillingAgreementUsage($observer) if (!($methodInstance instanceof Mage_Sales_Model_Payment_Method_Billing_AgreementAbstract)) { return; } - if (!Mage::getSingleton('admin/session')->isAllowed('sales/billing_agreement/actions/use')) { + if (!$this->getAdminSession()->isAllowed('sales/billing_agreement/actions/use')) { $observer->getEvent()->getResult()->isAvailable = false; } } diff --git a/app/code/core/Mage/Sales/Model/Service/Quote.php b/app/code/core/Mage/Sales/Model/Service/Quote.php index 9019ca0b788..acb847af5cd 100644 --- a/app/code/core/Mage/Sales/Model/Service/Quote.php +++ b/app/code/core/Mage/Sales/Model/Service/Quote.php @@ -22,6 +22,8 @@ */ class Mage_Sales_Model_Service_Quote { + use Mage_Core_Trait_Session; + /** * Quote object * @@ -180,7 +182,7 @@ public function submitOrder() try { $transaction->save(); } catch (Exception $e) { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { + if (!$this->getCustomerSession()->isLoggedIn()) { // reset customer ID's on exception, because customer not saved $quote->getCustomer()->setId(null); } diff --git a/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php b/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php index 7098be3ac74..17a5ced9be0 100644 --- a/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php +++ b/app/code/core/Mage/Sales/controllers/Billing/AgreementController.php @@ -31,7 +31,7 @@ public function indexAction() { $this->_title($this->__('Billing Agreements')); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getAdminSessionStorage()); $this->renderLayout(); } @@ -75,7 +75,7 @@ public function viewAction() $this->_title($this->__('Billing Agreements')) ->_title($this->__('Billing Agreement # %s', $agreement->getReferenceId())); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { $navigationBlock->setActive('sales/billing_agreement/'); @@ -125,7 +125,7 @@ public function returnWizardAction() $agreement->setStoreId(Mage::app()->getStore()->getId()) ->setToken($token) ->setMethodCode($paymentCode) - ->setCustomer(Mage::getSingleton('customer/session')->getCustomer()) + ->setCustomer($this->getCustomerSession()->getCustomer()) ->place(); $this->_getSession()->addSuccess( $this->__('The billing agreement "%s" has been created.', $agreement->getReferenceId()), @@ -208,9 +208,11 @@ protected function _initAgreement() * Retrieve customer session model * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } } diff --git a/app/code/core/Mage/Sales/controllers/GuestController.php b/app/code/core/Mage/Sales/controllers/GuestController.php index cde3cbe5ef0..e75a30baec4 100644 --- a/app/code/core/Mage/Sales/controllers/GuestController.php +++ b/app/code/core/Mage/Sales/controllers/GuestController.php @@ -64,7 +64,7 @@ protected function _viewAction() */ public function formAction() { - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $this->_redirect('customer/account/'); return; } diff --git a/app/code/core/Mage/Sales/controllers/OrderController.php b/app/code/core/Mage/Sales/controllers/OrderController.php index c9df472a307..619cc7a6e8a 100644 --- a/app/code/core/Mage/Sales/controllers/OrderController.php +++ b/app/code/core/Mage/Sales/controllers/OrderController.php @@ -33,7 +33,7 @@ public function preDispatch() $action = $this->getRequest()->getActionName(); $loginUrl = Mage::helper('customer')->getLoginUrl(); - if (!Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) { + if (!$this->getCustomerSession()->authenticate($this, $loginUrl)) { $this->setFlag('', self::FLAG_NO_DISPATCH, true); } return $this; @@ -45,7 +45,7 @@ public function preDispatch() public function historyAction() { $this->loadLayout(); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $this->getLayout()->getBlock('head')->setTitle($this->__('My Orders')); diff --git a/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php b/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php index 4198af59339..aec0b5d7374 100644 --- a/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php +++ b/app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php @@ -39,7 +39,7 @@ public function preDispatch() if (!$this->getRequest()->isDispatched()) { return; } - $this->_session = Mage::getSingleton('customer/session'); + $this->_session = $this->getCustomerSession(); if (!$this->_session->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); } @@ -54,7 +54,7 @@ public function indexAction() { $this->_title($this->__('Recurring Profiles')); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $this->renderLayout(); } @@ -145,7 +145,7 @@ protected function _viewAction() $profile = $this->_initProfile(); $this->_title($this->__('Recurring Profiles'))->_title($this->__('Profile #%s', $profile->getReferenceId())); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { $navigationBlock->setActive('sales/recurring_profile/'); diff --git a/app/code/core/Mage/SalesRule/Model/Observer.php b/app/code/core/Mage/SalesRule/Model/Observer.php index c97c4f2336c..52ba8e721d3 100644 --- a/app/code/core/Mage/SalesRule/Model/Observer.php +++ b/app/code/core/Mage/SalesRule/Model/Observer.php @@ -20,7 +20,7 @@ * @category Mage * @package Mage_SalesRule */ -class Mage_SalesRule_Model_Observer +class Mage_SalesRule_Model_Observer extends Mage_Core_Model_Observer { /** * Sales Rule Validator @@ -217,7 +217,7 @@ protected function _checkSalesRulesAvailability($attributeCode) } if ($disabledRulesCount) { - Mage::getSingleton('adminhtml/session')->addWarning( + $this->getAdminhtmlSession()->addWarning( Mage::helper('salesrule')->__('%d Shopping Cart Price Rules based on "%s" attribute have been disabled.', $disabledRulesCount, $attributeCode), ); } @@ -293,7 +293,7 @@ public function addProductAttributes(Varien_Event_Observer $observer) $attributes = Mage::getResourceModel('salesrule/rule') ->getActiveAttributes( Mage::app()->getWebsite()->getId(), - Mage::getSingleton('customer/session')->getCustomer()->getGroupId(), + $this->getCustomerSession()->getCustomer()->getGroupId(), ); $result = []; foreach ($attributes as $attribute) { diff --git a/app/code/core/Mage/Shipping/Model/Shipping.php b/app/code/core/Mage/Shipping/Model/Shipping.php index a789a593244..1a31c0ef687 100644 --- a/app/code/core/Mage/Shipping/Model/Shipping.php +++ b/app/code/core/Mage/Shipping/Model/Shipping.php @@ -20,6 +20,8 @@ */ class Mage_Shipping_Model_Shipping { + use Mage_Core_Trait_Session; + /** * Store address */ @@ -424,7 +426,7 @@ public function getCarrierByCode($carrierCode, $storeId = null) */ public function requestToShipment(Mage_Sales_Model_Order_Shipment $orderShipment) { - $admin = Mage::getSingleton('admin/session')->getUser(); + $admin = $this->getAdminSession()->getUser(); $order = $orderShipment->getOrder(); $address = $order->getShippingAddress(); $shippingMethod = $order->getShippingMethod(true); diff --git a/app/code/core/Mage/Shipping/controllers/TrackingController.php b/app/code/core/Mage/Shipping/controllers/TrackingController.php index cacc93ce4bf..d4418d2c94b 100644 --- a/app/code/core/Mage/Shipping/controllers/TrackingController.php +++ b/app/code/core/Mage/Shipping/controllers/TrackingController.php @@ -71,7 +71,7 @@ protected function _initOrder() $id = $this->getRequest()->getParam('order_id'); $order = Mage::getModel('sales/order')->load($id); - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); if (!$order->getId() || !$customerId || $order->getCustomerId() != $customerId) { return false; diff --git a/app/code/core/Mage/Tag/Block/Customer/Recent.php b/app/code/core/Mage/Tag/Block/Customer/Recent.php index 52648e9fae9..13fe89d8f58 100644 --- a/app/code/core/Mage/Tag/Block/Customer/Recent.php +++ b/app/code/core/Mage/Tag/Block/Customer/Recent.php @@ -33,7 +33,7 @@ protected function _construct() $this->_collection = Mage::getModel('tag/tag')->getEntityCollection() ->addStoreFilter(Mage::app()->getStore()->getId()) - ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId()) + ->addCustomerFilter($this->getCustomerSession()->getCustomerId()) ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) ->setDescOrder() ->setPageSize(5) diff --git a/app/code/core/Mage/Tag/Block/Customer/Tags.php b/app/code/core/Mage/Tag/Block/Customer/Tags.php index 679a14c0d38..be8c5a0da99 100644 --- a/app/code/core/Mage/Tag/Block/Customer/Tags.php +++ b/app/code/core/Mage/Tag/Block/Customer/Tags.php @@ -34,7 +34,7 @@ protected function _loadTags() $tags = Mage::getResourceModel('tag/tag_collection') ->addPopularity() ->setOrder('popularity', 'DESC') - ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId()) + ->addCustomerFilter($this->getCustomerSession()->getCustomerId()) ->setActiveFilter() ->load() ->getItems(); diff --git a/app/code/core/Mage/Tag/Block/Customer/View.php b/app/code/core/Mage/Tag/Block/Customer/View.php index d3246a5140e..b50246c5faa 100644 --- a/app/code/core/Mage/Tag/Block/Customer/View.php +++ b/app/code/core/Mage/Tag/Block/Customer/View.php @@ -140,7 +140,7 @@ protected function _getCollection() $this->_collection = Mage::getModel('tag/tag') ->getEntityCollection() ->addTagFilter($this->getTagId()) - ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId()) + ->addCustomerFilter($this->getCustomerSession()->getCustomerId()) ->addStoreFilter(Mage::app()->getStore()->getId()) ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) ->setActiveFilter(); diff --git a/app/code/core/Mage/Tag/controllers/CustomerController.php b/app/code/core/Mage/Tag/controllers/CustomerController.php index fa423fdc030..11e3930501e 100644 --- a/app/code/core/Mage/Tag/controllers/CustomerController.php +++ b/app/code/core/Mage/Tag/controllers/CustomerController.php @@ -30,7 +30,7 @@ protected function _getTagId() { $tagId = (int) $this->getRequest()->getParam('tagId'); if ($tagId) { - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); $model = Mage::getModel('tag/tag_relation'); $model->loadByTagCustomer(null, $tagId, $customerId); Mage::register('tagModel', $model); @@ -41,14 +41,14 @@ protected function _getTagId() public function indexAction() { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { - Mage::getSingleton('customer/session')->authenticate($this); + if (!$this->getCustomerSession()->isLoggedIn()) { + $this->getCustomerSession()->authenticate($this); return; } $this->loadLayout(); - $this->_initLayoutMessages('tag/session'); - $this->_initLayoutMessages('catalog/session'); + $this->_initLayoutMessages($this->getTagSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { @@ -66,8 +66,8 @@ public function indexAction() public function viewAction() { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { - Mage::getSingleton('customer/session')->authenticate($this); + if (!$this->getCustomerSession()->isLoggedIn()) { + $this->getCustomerSession()->authenticate($this); return; } @@ -75,14 +75,14 @@ public function viewAction() if ($tagId) { Mage::register('tagId', $tagId); $this->loadLayout(); - $this->_initLayoutMessages('tag/session'); + $this->_initLayoutMessages($this->getTagSessionStorage()); $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { $navigationBlock->setActive('tag/customer'); } - $this->_initLayoutMessages('checkout/session'); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); $this->getLayout()->getBlock('head')->setTitle(Mage::helper('tag')->__('My Tags')); $this->renderLayout(); } else { @@ -102,8 +102,8 @@ public function editAction() public function removeAction() { - if (!Mage::getSingleton('customer/session')->isLoggedIn()) { - Mage::getSingleton('customer/session')->authenticate($this); + if (!$this->getCustomerSession()->isLoggedIn()) { + $this->getCustomerSession()->authenticate($this); return; } @@ -113,13 +113,13 @@ public function removeAction() $model = Mage::registry('tagModel'); $model->deactivate(); $tag = Mage::getModel('tag/tag')->load($tagId)->aggregate(); - Mage::getSingleton('tag/session')->addSuccess(Mage::helper('tag')->__('The tag has been deleted.')); + $this->getTagSession()->addSuccess(Mage::helper('tag')->__('The tag has been deleted.')); $this->getResponse()->setRedirect(Mage::getUrl('*/*/', [ self::PARAM_NAME_URL_ENCODED => Mage::helper('core')->urlEncode(Mage::getUrl('customer/account/')), ])); return; } catch (Exception $e) { - Mage::getSingleton('tag/session')->addError(Mage::helper('tag')->__('Unable to remove tag. Please, try again later.')); + $this->getTagSession()->addError(Mage::helper('tag')->__('Unable to remove tag. Please, try again later.')); } } else { $this->_forward('noRoute'); diff --git a/app/code/core/Mage/Tag/controllers/IndexController.php b/app/code/core/Mage/Tag/controllers/IndexController.php index 137250b18a2..67b227bdfe6 100644 --- a/app/code/core/Mage/Tag/controllers/IndexController.php +++ b/app/code/core/Mage/Tag/controllers/IndexController.php @@ -27,7 +27,7 @@ class Mage_Tag_IndexController extends Mage_Core_Controller_Front_Action */ public function saveAction() { - $customerSession = Mage::getSingleton('customer/session'); + $customerSession = $this->getCustomerSession(); if (!$customerSession->authenticate($this)) { return; } @@ -35,7 +35,7 @@ public function saveAction() $productId = (int) $this->getRequest()->getParam('product'); if (strlen($tagName) && $productId) { - $session = Mage::getSingleton('catalog/session'); + $session = $this->getCatalogSession(); $product = Mage::getModel('catalog/product') ->load($productId); if (!$product->getId()) { @@ -116,7 +116,7 @@ protected function _cleanTags(array $tagNamesArr) */ protected function _fillMessageBox($counter) { - $session = Mage::getSingleton('catalog/session'); + $session = $this->getCatalogSession(); $helper = Mage::helper('core'); if (count($counter[Mage_Tag_Model_Tag::ADD_STATUS_NEW])) { diff --git a/app/code/core/Mage/Tag/controllers/ProductController.php b/app/code/core/Mage/Tag/controllers/ProductController.php index 331deb86d98..b557d7e31a7 100644 --- a/app/code/core/Mage/Tag/controllers/ProductController.php +++ b/app/code/core/Mage/Tag/controllers/ProductController.php @@ -34,8 +34,8 @@ public function listAction() Mage::register('current_tag', $tag); $this->loadLayout(); - $this->_initLayoutMessages('checkout/session'); - $this->_initLayoutMessages('tag/session'); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); + $this->_initLayoutMessages($this->getTagSessionStorage()); $this->renderLayout(); } } diff --git a/app/code/core/Mage/Tax/Model/Calculation.php b/app/code/core/Mage/Tax/Model/Calculation.php index 31f4978736e..cc8beac9f99 100644 --- a/app/code/core/Mage/Tax/Model/Calculation.php +++ b/app/code/core/Mage/Tax/Model/Calculation.php @@ -169,7 +169,7 @@ public function getDefaultCustomerTaxClass($store = null) public function getCustomer() { if ($this->_customer === null) { - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); if ($session->isLoggedIn()) { $this->_customer = $session->getCustomer(); } elseif ($session->getCustomerId()) { diff --git a/app/code/core/Mage/Uploader/Model/Config/Abstract.php b/app/code/core/Mage/Uploader/Model/Config/Abstract.php index 0d0b2fa0dd2..f13e1951fa5 100644 --- a/app/code/core/Mage/Uploader/Model/Config/Abstract.php +++ b/app/code/core/Mage/Uploader/Model/Config/Abstract.php @@ -22,6 +22,8 @@ */ abstract class Mage_Uploader_Model_Config_Abstract extends Varien_Object { + use Mage_Core_Trait_Session; + /** * Get file helper * diff --git a/app/code/core/Mage/Uploader/Model/Config/Uploader.php b/app/code/core/Mage/Uploader/Model/Config/Uploader.php index 9d9e6f83844..325d6e09674 100644 --- a/app/code/core/Mage/Uploader/Model/Config/Uploader.php +++ b/app/code/core/Mage/Uploader/Model/Config/Uploader.php @@ -108,7 +108,7 @@ protected function _construct() ->setWithCredentials(false) ->setForceChunkSize(false) ->setQuery([ - 'form_key' => Mage::getSingleton('core/session')->getFormKey(), + 'form_key' => $this->getCoreSession()->getFormKey(), ]) ->setMethod(self::UPLOAD_TYPE) ->setSimultaneousUploads(1) diff --git a/app/code/core/Mage/Weee/Model/Observer.php b/app/code/core/Mage/Weee/Model/Observer.php index 0b86eab3b76..c9e0b1b5803 100644 --- a/app/code/core/Mage/Weee/Model/Observer.php +++ b/app/code/core/Mage/Weee/Model/Observer.php @@ -90,7 +90,7 @@ public function prepareCatalogIndexSelect(Varien_Event_Observer $observer) $table = $observer->getEvent()->getTable(); $websiteId = (int) Mage::app()->getStore($storeId)->getWebsiteId(); - $customerGroupId = (int) Mage::getSingleton('customer/session')->getCustomerGroupId(); + $customerGroupId = (int) $this->getCustomerSession()->getCustomerGroupId(); /** @var Varien_Object $response */ $response = $observer->getEvent()->getResponseObject(); diff --git a/app/code/core/Mage/Weee/Model/Tax.php b/app/code/core/Mage/Weee/Model/Tax.php index 06a1c3b462d..270f876d732 100644 --- a/app/code/core/Mage/Weee/Model/Tax.php +++ b/app/code/core/Mage/Weee/Model/Tax.php @@ -274,7 +274,7 @@ public function getProductWeeeAttributes( protected function _getDiscountPercentForProduct($product) { $website = Mage::app()->getStore()->getWebsiteId(); - $group = Mage::getSingleton('customer/session')->getCustomerGroupId(); + $group = $this->getCustomerSession()->getCustomerGroupId(); $key = implode('-', [$website, $group, $product->getId()]); if (!isset($this->_productDiscounts[$key])) { $this->_productDiscounts[$key] = (int) $this->getResource() diff --git a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php index f513de4a090..9e7b9bad414 100644 --- a/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php +++ b/app/code/core/Mage/Widget/controllers/Adminhtml/Widget/InstanceController.php @@ -32,10 +32,12 @@ class Mage_Widget_Adminhtml_Widget_InstanceController extends Mage_Adminhtml_Con * Session getter * * @return Mage_Adminhtml_Model_Session + * @deprecated + * @see getAdminhtmlSession() */ protected function _getSession() { - return Mage::getSingleton('adminhtml/session'); + return $this->getAdminhtmlSession(); } /** @@ -148,8 +150,8 @@ public function validateAction() $widgetInstance = $this->_initWidgetInstance(); $result = $widgetInstance->validate(); if ($result !== true && is_string($result)) { - $this->_getSession()->addError($result); - $this->_initLayoutMessages('adminhtml/session'); + $this->getAdminhtmlSession()->addError($result); + $this->_initLayoutMessages($this->getAdminhtmlSessionStorage()); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } diff --git a/app/code/core/Mage/Wishlist/Block/Abstract.php b/app/code/core/Mage/Wishlist/Block/Abstract.php index 7081e6cc6b4..ae7da6d00f3 100644 --- a/app/code/core/Mage/Wishlist/Block/Abstract.php +++ b/app/code/core/Mage/Wishlist/Block/Abstract.php @@ -74,10 +74,12 @@ protected function _getHelper() * Retrieve Customer Session instance * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getCustomerSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** diff --git a/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php b/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php index 36a22a37b51..ea92d48cdad 100644 --- a/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php +++ b/app/code/core/Mage/Wishlist/Block/Customer/Sharing.php @@ -62,7 +62,7 @@ public function getSendUrl() public function getEnteredData($key) { if (is_null($this->_enteredData)) { - $this->_enteredData = Mage::getSingleton('wishlist/session') + $this->_enteredData = $this->getWishlistSession() ->getData('sharing_form', true); } diff --git a/app/code/core/Mage/Wishlist/Controller/Abstract.php b/app/code/core/Mage/Wishlist/Controller/Abstract.php index 022b62b9881..7f465c74d03 100644 --- a/app/code/core/Mage/Wishlist/Controller/Abstract.php +++ b/app/code/core/Mage/Wishlist/Controller/Abstract.php @@ -73,7 +73,7 @@ public function allcartAction() $this->_forward('noRoute'); return; } - $isOwner = $wishlist->isOwner(Mage::getSingleton('customer/session')->getCustomerId()); + $isOwner = $wishlist->isOwner($this->getCustomerSession()->getCustomerId()); $messages = []; $addedItems = []; @@ -164,7 +164,7 @@ public function allcartAction() } $redirectUrl = $item->getProductUrl(); } else { - $wishlistSession = Mage::getSingleton('wishlist/session'); + $wishlistSession = $this->getWishlistSession(); foreach ($messages as $message) { $wishlistSession->addError($message); } @@ -177,7 +177,7 @@ public function allcartAction() try { $wishlist->save(); } catch (Exception $e) { - Mage::getSingleton('wishlist/session')->addError($this->__('Cannot update wishlist')); + $this->getWishlistSession()->addError($this->__('Cannot update wishlist')); $redirectUrl = $indexUrl; } @@ -186,7 +186,7 @@ public function allcartAction() $products[] = '"' . $product->getName() . '"'; } - Mage::getSingleton('checkout/session')->addSuccess( + $this->getCheckoutSession()->addSuccess( Mage::helper('wishlist')->__('%d product(s) have been added to shopping cart: %s.', count($addedItems), implode(', ', $products)), ); diff --git a/app/code/core/Mage/Wishlist/Helper/Data.php b/app/code/core/Mage/Wishlist/Helper/Data.php index ca70f7a563f..13a5cc664a7 100644 --- a/app/code/core/Mage/Wishlist/Helper/Data.php +++ b/app/code/core/Mage/Wishlist/Helper/Data.php @@ -64,10 +64,12 @@ class Mage_Wishlist_Helper_Data extends Mage_Core_Helper_Abstract * Retrieve customer session * * @return Mage_Customer_Model_Session + * @deprecated + * @see getCustomerSession() */ protected function _getCustomerSession() { - return Mage::getSingleton('customer/session'); + return $this->getCustomerSession(); } /** @@ -568,7 +570,7 @@ public function getAddUrlWithCustomParams($item, array $params = [], $addFormKey if ($productId) { $params['product'] = $productId; if ($addFormKey) { - $params[Mage_Core_Model_Url::FORM_KEY] = $this->_getSingletonModel('core/session')->getFormKey(); + $params[Mage_Core_Model_Url::FORM_KEY] = $this->getCoreSession()->getFormKey(); } return $this->_getUrlStore($item)->getUrl('wishlist/index/add', $params); } @@ -589,7 +591,7 @@ public function getRemoveUrlCustom($item, $addFormKey = true) 'item' => $item->getWishlistItemId(), ]; if ($addFormKey) { - $params[Mage_Core_Model_Url::FORM_KEY] = $this->_getSingletonModel('core/session')->getFormKey(); + $params[Mage_Core_Model_Url::FORM_KEY] = $this->getCoreSession()->getFormKey(); } return $this->_getUrl('wishlist/index/remove', $params); @@ -616,7 +618,7 @@ public function getAddToCartUrlCustom($item, $addFormKey = true) Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $continueUrl, ]; if ($addFormKey) { - $params[Mage_Core_Model_Url::FORM_KEY] = $this->_getSingletonModel('core/session')->getFormKey(); + $params[Mage_Core_Model_Url::FORM_KEY] = $this->getCoreSession()->getFormKey(); } return $this->_getUrlStore($item)->getUrl('wishlist/index/cart', $params); } diff --git a/app/code/core/Mage/Wishlist/Model/Observer.php b/app/code/core/Mage/Wishlist/Model/Observer.php index 4f858ff7f0f..5532295ee16 100644 --- a/app/code/core/Mage/Wishlist/Model/Observer.php +++ b/app/code/core/Mage/Wishlist/Model/Observer.php @@ -87,11 +87,11 @@ public function processAddToCart($observer) { /** @var Mage_Core_Controller_Request_Http $request */ $request = $observer->getEvent()->getRequest(); - $sharedWishlist = Mage::getSingleton('checkout/session')->getSharedWishlist(); - $messages = Mage::getSingleton('checkout/session')->getWishlistPendingMessages(); - $urls = Mage::getSingleton('checkout/session')->getWishlistPendingUrls(); - $wishlistIds = Mage::getSingleton('checkout/session')->getWishlistIds(); - $singleWishlistId = Mage::getSingleton('checkout/session')->getSingleWishlistId(); + $sharedWishlist = $this->getCheckoutSession()->getSharedWishlist(); + $messages = $this->getCheckoutSession()->getWishlistPendingMessages(); + $urls = $this->getCheckoutSession()->getWishlistPendingUrls(); + $wishlistIds = $this->getCheckoutSession()->getWishlistIds(); + $singleWishlistId = $this->getCheckoutSession()->getSingleWishlistId(); if ($singleWishlistId) { $wishlistIds = [$singleWishlistId]; @@ -100,9 +100,9 @@ public function processAddToCart($observer) if (!empty($wishlistIds) && $request->getParam('wishlist_next')) { $wishlistId = array_shift($wishlistIds); - if (Mage::getSingleton('customer/session')->isLoggedIn()) { + if ($this->getCustomerSession()->isLoggedIn()) { $wishlist = Mage::getModel('wishlist/wishlist') - ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer(), true); + ->loadByCustomer($this->getCustomerSession()->getCustomer(), true); } elseif ($sharedWishlist) { $wishlist = Mage::getModel('wishlist/wishlist')->loadByCode($sharedWishlist); } else { @@ -116,21 +116,21 @@ public function processAddToCart($observer) $wishlistItem->delete(); } } - Mage::getSingleton('checkout/session')->setWishlistIds($wishlistIds); - Mage::getSingleton('checkout/session')->setSingleWishlistId(null); + $this->getCheckoutSession()->setWishlistIds($wishlistIds); + $this->getCheckoutSession()->setSingleWishlistId(null); } if ($request->getParam('wishlist_next') && !empty($urls)) { $url = array_shift($urls); $message = array_shift($messages); - Mage::getSingleton('checkout/session')->setWishlistPendingUrls($urls); - Mage::getSingleton('checkout/session')->setWishlistPendingMessages($messages); + $this->getCheckoutSession()->setWishlistPendingUrls($urls); + $this->getCheckoutSession()->setWishlistPendingMessages($messages); - Mage::getSingleton('checkout/session')->addError($message); + $this->getCheckoutSession()->addError($message); $observer->getEvent()->getResponse()->setRedirect($url); - Mage::getSingleton('checkout/session')->setNoCartRedirect(true); + $this->getCheckoutSession()->setNoCartRedirect(true); } } @@ -153,7 +153,7 @@ public function customerLogin(Varien_Event_Observer $observer) */ public function customerLogout(Varien_Event_Observer $observer) { - Mage::getSingleton('customer/session')->setWishlistItemCount(0); + $this->getCustomerSession()->setWishlistItemCount(0); return $this; } diff --git a/app/code/core/Mage/Wishlist/controllers/IndexController.php b/app/code/core/Mage/Wishlist/controllers/IndexController.php index 73634edfaa4..0f637ec431b 100644 --- a/app/code/core/Mage/Wishlist/controllers/IndexController.php +++ b/app/code/core/Mage/Wishlist/controllers/IndexController.php @@ -48,12 +48,12 @@ public function preDispatch() { parent::preDispatch(); - if (!$this->_skipAuthentication && !Mage::getSingleton('customer/session')->authenticate($this)) { + if (!$this->_skipAuthentication && !$this->getCustomerSession()->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); - if (!Mage::getSingleton('customer/session')->getBeforeWishlistUrl()) { - Mage::getSingleton('customer/session')->setBeforeWishlistUrl($this->_getRefererUrl()); + if (!$this->getCustomerSession()->getBeforeWishlistUrl()) { + $this->getCustomerSession()->setBeforeWishlistUrl($this->_getRefererUrl()); } - Mage::getSingleton('customer/session')->setBeforeWishlistRequest($this->getRequest()->getParams()); + $this->getCustomerSession()->setBeforeWishlistRequest($this->getRequest()->getParams()); } if (!Mage::getStoreConfigFlag('wishlist/general/active')) { $this->norouteAction(); @@ -89,7 +89,7 @@ protected function _getWishlist($wishlistId = null) if (!$wishlistId) { $wishlistId = $this->getRequest()->getParam('wishlist_id'); } - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); $wishlist = Mage::getModel('wishlist/wishlist'); if ($wishlistId) { $wishlist->load($wishlistId); @@ -106,10 +106,10 @@ protected function _getWishlist($wishlistId = null) Mage::register('wishlist', $wishlist); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('wishlist/session')->addError($e->getMessage()); + $this->getWishlistSession()->addError($e->getMessage()); return false; } catch (Exception $e) { - Mage::getSingleton('wishlist/session')->addException( + $this->getWishlistSession()->addException( $e, Mage::helper('wishlist')->__('Wishlist could not be created.'), ); @@ -133,13 +133,13 @@ public function indexAction() $this->loadLayout(); if ($this->_isFormKeyEnabled() && strpos($this->_getRefererUrl(), 'login')) { - Mage::getSingleton('core/session')->addError(Mage::helper('wishlist')->__( + $this->getCoreSession()->addError(Mage::helper('wishlist')->__( 'Please add product to wishlist again.', )); - return $this->_redirectUrl(Mage::getSingleton('customer/session')->getBeforeWishlistUrl()); + return $this->_redirectUrl($this->getCustomerSession()->getBeforeWishlistUrl()); } - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); $block = $this->getLayout()->getBlock('customer.wishlist'); $referer = $session->getAddActionReferer(true); if ($block) { @@ -149,10 +149,10 @@ public function indexAction() } } - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('checkout/session'); - $this->_initLayoutMessages('catalog/session'); - $this->_initLayoutMessages('wishlist/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); + $this->_initLayoutMessages($this->getCatalogSessionStorage()); + $this->_initLayoutMessages($this->getWishlistSessionStorage()); $this->renderLayout(); } @@ -184,7 +184,7 @@ protected function _addItemToWishList() return; } - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); $productId = (int) $this->getRequest()->getParam('product'); if (!$productId) { @@ -288,11 +288,11 @@ public function configureAction() $params->setBuyRequest($buyRequest); Mage::helper('catalog/product_view')->prepareAndRender($item->getProductId(), $this, $params); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('customer/session')->addError($e->getMessage()); + $this->getCustomerSession()->addError($e->getMessage()); $this->_redirect('*'); return; } catch (Exception $e) { - Mage::getSingleton('customer/session')->addError($this->__('Cannot configure product')); + $this->getCustomerSession()->addError($this->__('Cannot configure product')); Mage::logException($e); $this->_redirect('*'); return; @@ -304,7 +304,7 @@ public function configureAction() */ public function updateItemOptionsAction() { - $session = Mage::getSingleton('customer/session'); + $session = $this->getCustomerSession(); $productId = (int) $this->getRequest()->getParam('product'); if (!$productId) { $this->_redirect('*/'); @@ -402,7 +402,7 @@ public function updateAction() $item->delete(); } catch (Exception $e) { Mage::logException($e); - Mage::getSingleton('customer/session')->addError( + $this->getCustomerSession()->addError( $this->__('Can\'t delete item from wishlist'), ); } @@ -419,7 +419,7 @@ public function updateAction() ->save(); $updatedItems++; } catch (Exception $e) { - Mage::getSingleton('customer/session')->addError( + $this->getCustomerSession()->addError( $this->__('Can\'t save description %s', Mage::helper('core')->escapeHtml($description)), ); } @@ -431,7 +431,7 @@ public function updateAction() $wishlist->save(); Mage::helper('wishlist')->calculate(); } catch (Exception $e) { - Mage::getSingleton('customer/session')->addError($this->__('Can\'t update wishlist')); + $this->getCustomerSession()->addError($this->__('Can\'t update wishlist')); } } @@ -468,11 +468,11 @@ public function removeAction() $item->delete(); $wishlist->save(); } catch (Mage_Core_Exception $e) { - Mage::getSingleton('customer/session')->addError( + $this->getCustomerSession()->addError( $this->__('An error occurred while deleting the item from wishlist: %s', $e->getMessage()), ); } catch (Exception $e) { - Mage::getSingleton('customer/session')->addError( + $this->getCustomerSession()->addError( $this->__('An error occurred while deleting the item from wishlist.'), ); } @@ -515,8 +515,7 @@ public function cartAction() $item->setQty($qty); } - /** @var Mage_Wishlist_Model_Session $session */ - $session = Mage::getSingleton('wishlist/session'); + $session = $this->getWishlistSession(); $cart = Mage::getSingleton('checkout/cart'); $redirectUrl = Mage::getUrl('*/*'); @@ -549,15 +548,15 @@ public function cartAction() ->load($item->getProductId()); $productName = Mage::helper('core')->escapeHtml($product->getName()); $message = $this->__('%s was added to your shopping cart.', $productName); - Mage::getSingleton('catalog/session')->addSuccess($message); + $this->getCatalogSession()->addSuccess($message); } catch (Mage_Core_Exception $e) { if ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_NOT_SALABLE) { $session->addError($this->__('This product(s) is currently out of stock')); } elseif ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) { - Mage::getSingleton('catalog/session')->addNotice($e->getMessage()); + $this->getCatalogSession()->addNotice($e->getMessage()); $redirectUrl = Mage::getUrl('*/*/configure/', ['id' => $item->getId()]); } else { - Mage::getSingleton('catalog/session')->addNotice($e->getMessage()); + $this->getCatalogSession()->addNotice($e->getMessage()); $redirectUrl = Mage::getUrl('*/*/configure/', ['id' => $item->getId()]); } } catch (Exception $e) { @@ -586,7 +585,7 @@ public function fromcartAction() /** @var Mage_Checkout_Model_Cart $cart */ $cart = Mage::getSingleton('checkout/cart'); - $session = Mage::getSingleton('checkout/session'); + $session = $this->getCheckoutSession(); try { $item = $cart->getQuote()->getItemById($itemId); @@ -626,8 +625,8 @@ public function shareAction() { $this->_getWishlist(); $this->loadLayout(); - $this->_initLayoutMessages('customer/session'); - $this->_initLayoutMessages('wishlist/session'); + $this->_initLayoutMessages($this->getCustomerSessionStorage()); + $this->_initLayoutMessages($this->getWishlistSessionStorage()); $this->renderLayout(); } @@ -666,8 +665,8 @@ public function sendAction() } } if ($error) { - Mage::getSingleton('wishlist/session')->addError($error); - Mage::getSingleton('wishlist/session')->setSharingForm($this->getRequest()->getPost()); + $this->getWishlistSession()->addError($error); + $this->getWishlistSession()->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); return; } @@ -677,7 +676,7 @@ public function sendAction() $translate->setTranslateInline(false); try { - $customer = Mage::getSingleton('customer/session')->getCustomer(); + $customer = $this->getCustomerSession()->getCustomer(); /*if share rss added rss feed to email template*/ if ($this->getRequest()->getParam('rss_url')) { @@ -717,15 +716,15 @@ public function sendAction() $translate->setTranslateInline(true); Mage::dispatchEvent('wishlist_share', ['wishlist' => $wishlist]); - Mage::getSingleton('customer/session')->addSuccess( + $this->getCustomerSession()->addSuccess( $this->__('Your Wishlist has been shared.'), ); $this->_redirect('*/*', ['wishlist_id' => $wishlist->getId()]); } catch (Exception $e) { $translate->setTranslateInline(true); - Mage::getSingleton('wishlist/session')->addError($e->getMessage()); - Mage::getSingleton('wishlist/session')->setSharingForm($this->getRequest()->getPost()); + $this->getWishlistSession()->addError($e->getMessage()); + $this->getWishlistSession()->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); } } diff --git a/app/code/core/Mage/Wishlist/controllers/SharedController.php b/app/code/core/Mage/Wishlist/controllers/SharedController.php index 42c5db5e336..7ccf7e50f48 100644 --- a/app/code/core/Mage/Wishlist/controllers/SharedController.php +++ b/app/code/core/Mage/Wishlist/controllers/SharedController.php @@ -45,7 +45,7 @@ protected function _getWishlist() return false; } - Mage::getSingleton('checkout/session')->setSharedWishlist($code); + $this->getCheckoutSession()->setSharedWishlist($code); return $wishlist; } @@ -57,7 +57,7 @@ protected function _getWishlist() public function indexAction() { $wishlist = $this->_getWishlist(); - $customerId = Mage::getSingleton('customer/session')->getCustomerId(); + $customerId = $this->getCustomerSession()->getCustomerId(); if ($wishlist && $wishlist->getCustomerId() && $wishlist->getCustomerId() == $customerId) { $this->_redirectUrl(Mage::helper('wishlist')->getListUrl($wishlist->getId())); @@ -67,8 +67,8 @@ public function indexAction() Mage::register('shared_wishlist', $wishlist); $this->loadLayout(); - $this->_initLayoutMessages('checkout/session'); - $this->_initLayoutMessages('wishlist/session'); + $this->_initLayoutMessages($this->getCheckoutSessionStorage()); + $this->_initLayoutMessages($this->getWishlistSessionStorage()); $this->renderLayout(); } @@ -89,8 +89,7 @@ public function cartAction() $wishlist = Mage::getModel('wishlist/wishlist')->loadByCode($code); $redirectUrl = Mage::getUrl('*/*/index', ['code' => $code]); - /** @var Mage_Wishlist_Model_Session $session */ - $session = Mage::getSingleton('wishlist/session'); + $session = $this->getWishlistSession(); $cart = Mage::getSingleton('checkout/cart'); try { @@ -110,12 +109,12 @@ public function cartAction() } elseif ($e->getCode() == Mage_Wishlist_Model_Item::EXCEPTION_CODE_NOT_SPECIFIED_PRODUCT) { if (!$wishlist->getItemsCount()) { $redirectUrl = Mage::helper('checkout/cart')->getCartUrl(); - $session = Mage::getSingleton('catalog/session'); + $session = $this->getCatalogSession(); } $message = Mage::helper('wishlist')->__('Cannot add the selected product to shopping cart because the product was removed from the wishlist'); $session->addNotice($message); } else { - Mage::getSingleton('catalog/session')->addNotice($e->getMessage()); + $this->getCatalogSession()->addNotice($e->getMessage()); $redirectUrl = $item->getProductUrl(); } } catch (Exception $e) {