Skip to content

Commit

Permalink
put session params into observer
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonLesti committed Jan 3, 2015
1 parent 9b2c523 commit ba91c11
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
19 changes: 1 addition & 18 deletions app/code/community/Lesti/Fpc/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Lesti_Fpc_Helper_Data extends Lesti_Fpc_Helper_Abstract
{
const XML_PATH_CACHEABLE_ACTIONS = 'system/fpc/cache_actions';
const XML_PATH_BYPASS_HANDLES = 'system/fpc/bypass_handles';
const XML_PATH_SESSION_PARAMS = 'system/fpc/session_params';
const XML_PATH_URI_PARAMS = 'system/fpc/uri_params';
const XML_PATH_CUSTOMER_GROUPS = 'system/fpc/customer_groups';
const XML_PATH_REFRESH_ACTIONS = 'system/fpc/refresh_actions';
Expand Down Expand Up @@ -88,15 +87,7 @@ protected function _getParams()
$params['customer_group_id'] = $customerSession
->getCustomerGroupId();
}
if ($this->getFullActionName() === 'catalog_category_view') {
$sessionParams = $this->_getSessionParams();
$catalogSession = Mage::getSingleton('catalog/session');
foreach ($sessionParams as $param) {
if ($data = $catalogSession->getData($param)) {
$params['session_' . $param] = $data;
}
}
}

// edit parameters via event
$parameters = new Varien_Object();
$parameters->setValue($params);
Expand Down Expand Up @@ -137,14 +128,6 @@ public function _getUriParams()
return $this->getCSStoreConfigs(self::XML_PATH_URI_PARAMS);
}

/**
* @return array
*/
protected function _getSessionParams()
{
return $this->getCSStoreConfigs(self::XML_PATH_SESSION_PARAMS);
}

/**
* @return array
*/
Expand Down
23 changes: 23 additions & 0 deletions app/code/community/Lesti/Fpc/Model/Observer/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class Lesti_Fpc_Model_Observer_Parameters
{
const XML_PATH_SESSION_PARAMS = 'system/fpc/session_params';

/**
* @param $observer
*/
Expand All @@ -36,10 +38,31 @@ public function fpcHelperCollectParams($observer)
$design = Mage::getDesign();
$params['design'] = $design->getPackageName().'_'.
$design->getTheme('template');
// session paramaters
/** @var Lesti_Fpc_Helper_Data $helper */
$helper = Mage::helper('fpc');
if ($helper->getFullActionName() === 'catalog_category_view') {
$sessionParams = $this->_getSessionParams();
$catalogSession = Mage::getSingleton('catalog/session');
foreach ($sessionParams as $param) {
if ($data = $catalogSession->getData($param)) {
$params['session_' . $param] = $data;
}
}
}

$parameters = $observer->getEvent()->getParameters();
$additionalParams = $parameters->getValue();
$additionalParams = array_merge($additionalParams, $params);
$parameters->setValue($additionalParams);
}

/**
* @return array
*/
protected function _getSessionParams()
{
$helper = Mage::helper('fpc');
return $helper->getCSStoreConfigs(self::XML_PATH_SESSION_PARAMS);
}
}
10 changes: 10 additions & 0 deletions app/code/community/Lesti/Fpc/Test/Model/Observer/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ class Lesti_Fpc_Test_Model_Observer_Parameters extends Lesti_Fpc_Test_TestCase
{
/**
* @test
* @loadFixture fpc_helper_collect_params.yaml
*/
public function testFpcHelperCollectParams()
{
Mage::app()->getRequest()->setRouteName('catalog');
Mage::app()->getRequest()->setControllerName('category');
Mage::app()->getRequest()->setActionName('view');

/** @var Mage_Catalog_Model_Session $catalogSession */
$catalogSession = Mage::getSingleton('catalog/session');
$catalogSession->setData('fpc', 'cool');

$expectedResult = array(
'fpc' => 'cool',
'store' => Mage::app()->getStore(true)->getCode(),
'currency' => Mage::app()->getStore()->getCurrentCurrencyCode(),
'design' => Mage::getDesign()->getPackageName().'_'.
Mage::getDesign()->getTheme('template'),
'session_fpc' => 'cool',
);
$params = array('fpc' => 'cool');
$object = new Varien_Object();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config:
default/system/fpc/session_params: >
magento,
fpc

0 comments on commit ba91c11

Please sign in to comment.