Skip to content

Commit ba91c11

Browse files
committed
put session params into observer
1 parent 9b2c523 commit ba91c11

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

app/code/community/Lesti/Fpc/Helper/Data.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Lesti_Fpc_Helper_Data extends Lesti_Fpc_Helper_Abstract
1818
{
1919
const XML_PATH_CACHEABLE_ACTIONS = 'system/fpc/cache_actions';
2020
const XML_PATH_BYPASS_HANDLES = 'system/fpc/bypass_handles';
21-
const XML_PATH_SESSION_PARAMS = 'system/fpc/session_params';
2221
const XML_PATH_URI_PARAMS = 'system/fpc/uri_params';
2322
const XML_PATH_CUSTOMER_GROUPS = 'system/fpc/customer_groups';
2423
const XML_PATH_REFRESH_ACTIONS = 'system/fpc/refresh_actions';
@@ -88,15 +87,7 @@ protected function _getParams()
8887
$params['customer_group_id'] = $customerSession
8988
->getCustomerGroupId();
9089
}
91-
if ($this->getFullActionName() === 'catalog_category_view') {
92-
$sessionParams = $this->_getSessionParams();
93-
$catalogSession = Mage::getSingleton('catalog/session');
94-
foreach ($sessionParams as $param) {
95-
if ($data = $catalogSession->getData($param)) {
96-
$params['session_' . $param] = $data;
97-
}
98-
}
99-
}
90+
10091
// edit parameters via event
10192
$parameters = new Varien_Object();
10293
$parameters->setValue($params);
@@ -137,14 +128,6 @@ public function _getUriParams()
137128
return $this->getCSStoreConfigs(self::XML_PATH_URI_PARAMS);
138129
}
139130

140-
/**
141-
* @return array
142-
*/
143-
protected function _getSessionParams()
144-
{
145-
return $this->getCSStoreConfigs(self::XML_PATH_SESSION_PARAMS);
146-
}
147-
148131
/**
149132
* @return array
150133
*/

app/code/community/Lesti/Fpc/Model/Observer/Parameters.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
class Lesti_Fpc_Model_Observer_Parameters
1818
{
19+
const XML_PATH_SESSION_PARAMS = 'system/fpc/session_params';
20+
1921
/**
2022
* @param $observer
2123
*/
@@ -36,10 +38,31 @@ public function fpcHelperCollectParams($observer)
3638
$design = Mage::getDesign();
3739
$params['design'] = $design->getPackageName().'_'.
3840
$design->getTheme('template');
41+
// session paramaters
42+
/** @var Lesti_Fpc_Helper_Data $helper */
43+
$helper = Mage::helper('fpc');
44+
if ($helper->getFullActionName() === 'catalog_category_view') {
45+
$sessionParams = $this->_getSessionParams();
46+
$catalogSession = Mage::getSingleton('catalog/session');
47+
foreach ($sessionParams as $param) {
48+
if ($data = $catalogSession->getData($param)) {
49+
$params['session_' . $param] = $data;
50+
}
51+
}
52+
}
3953

4054
$parameters = $observer->getEvent()->getParameters();
4155
$additionalParams = $parameters->getValue();
4256
$additionalParams = array_merge($additionalParams, $params);
4357
$parameters->setValue($additionalParams);
4458
}
59+
60+
/**
61+
* @return array
62+
*/
63+
protected function _getSessionParams()
64+
{
65+
$helper = Mage::helper('fpc');
66+
return $helper->getCSStoreConfigs(self::XML_PATH_SESSION_PARAMS);
67+
}
4568
}

app/code/community/Lesti/Fpc/Test/Model/Observer/Parameters.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,25 @@ class Lesti_Fpc_Test_Model_Observer_Parameters extends Lesti_Fpc_Test_TestCase
1818
{
1919
/**
2020
* @test
21+
* @loadFixture fpc_helper_collect_params.yaml
2122
*/
2223
public function testFpcHelperCollectParams()
2324
{
25+
Mage::app()->getRequest()->setRouteName('catalog');
26+
Mage::app()->getRequest()->setControllerName('category');
27+
Mage::app()->getRequest()->setActionName('view');
28+
29+
/** @var Mage_Catalog_Model_Session $catalogSession */
30+
$catalogSession = Mage::getSingleton('catalog/session');
31+
$catalogSession->setData('fpc', 'cool');
32+
2433
$expectedResult = array(
2534
'fpc' => 'cool',
2635
'store' => Mage::app()->getStore(true)->getCode(),
2736
'currency' => Mage::app()->getStore()->getCurrentCurrencyCode(),
2837
'design' => Mage::getDesign()->getPackageName().'_'.
2938
Mage::getDesign()->getTheme('template'),
39+
'session_fpc' => 'cool',
3040
);
3141
$params = array('fpc' => 'cool');
3242
$object = new Varien_Object();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
config:
2+
default/system/fpc/session_params: >
3+
magento,
4+
fpc

0 commit comments

Comments
 (0)