-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathObserver.php
96 lines (92 loc) · 2.79 KB
/
Observer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* see http://de.slideshare.net/ivanchepurnyi/magento-performance
*
* PHP version 5
*
* @category FireGento
* @package FireGento_PerformanceTweaks
* @author FireGento Team <[email protected]>
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/
/**
* FireGento_PerformanceTweaks_Model_Observer
*
* @category FireGento
* @package FireGento_PerformanceTweaks
* @author FireGento Team <[email protected]>
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/
class FireGento_PerformanceTweaks_Model_Observer
{
/**
* Magento adds on every category and product page a layout handle with its
* entity id, so you have layout cache unique for each product or category
*
* CAUTION: Widgets based on category id and product id handles WILL NOT WORK
* SOLUTION: Use "custom layout update xml" attribute on entity level instead!
*
* @param Varien_Observer $observer Observer
*
* @return null
*/
public function removeEntityIdFromLayout($observer)
{
$update = $observer->getLayout()->getUpdate();
foreach ($update->getHandles() as $handle) {
if ($this->_isCategoryHandle($handle)
|| $this->_isProductHandle($handle)
) {
$update->removeHandle($handle);
}
}
}
/**
* Magento does not cache CMS blocks by default.
*
* @param Varien_Observer $observer Observer
*
* @return null
*/
public function enableCmsBlockCaching($observer)
{
$block = $observer->getBlock();
if ($block instanceof Mage_Cms_Block_Widget_Block
|| $block instanceof Mage_Cms_Block_Block
) {
$cacheKeyData = array(
Mage_Cms_Model_Block::CACHE_TAG,
$block->getBlockId(),
Mage::app()->getStore()->getId(),
intval(Mage::app()->getStore()->isCurrentlySecure())
);
$block->setCacheKey(implode('_', $cacheKeyData));
$block->setCacheTags(array(Mage_Cms_Model_Block::CACHE_TAG));
$block->setCacheLifetime(false);
}
}
/**
* if layout update handle is a category handle
*
* @param string $handle Layout handle
*
* @return boolean
*/
protected function _isCategoryHandle($handle)
{
return (0 === strpos($handle, 'CATEGORY_'));
}
/**
* if layout update handle is a product handle
*
* @param string $handle Layout handle
*
* @return boolean
*/
protected function _isProductHandle($handle)
{
return (0 === strpos($handle, 'PRODUCT_')
&& false === strpos($handle, 'PRODUCT_TYPE_')
);
}
}