Magento Themes and Magento Extensions

Magento (How to fix): One or more of the Cache Types are invalidated: Blocks HTML output.

Share

Somewhere around Magento 1.5, message from the title of this post begun to pop on every product save.
Although quite anoying, it is quite easy to fix and it seems that’s not a BUG, it is a feature – implemented without automatic block html cache refresh :)
I have tested it on Professional Edition and to be completely honest, I’m not sure if it will actually work on Magento CE,
but there is no reason why not (Please comment if it does).

Ok, what is the catch?!
Here we go:
Add this in your module config.xml:

1
2
3
4
5
6
7
8
9
<global>
<models>
<catalogrule>
<rewrite>
<rule>Yourpackage_Yourmodule_Model_Rule</rule>
</rewrite>
</catalogrule>
</models>
</global>

Create file called Rule.php in YOUR module Model directory.

Add this code in newly created file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Yourpackage_Yourmodule_Model_Rule extends Mage_CatalogRule_Model_Rule
{
/**
* Apply all price rules to product
*
* @param int|Mage_Catalog_Model_Product $product
* @return Mage_CatalogRule_Model_Rule
*/
public function applyAllRulesToProduct($product)
{
$this->_getResource()->applyAllRulesForDateRange(NULL, NULL, $product);
$this->_invalidateCache();
//Notice this little line
Mage::app()->getCacheInstance()->cleanType('block_html');
$indexProcess = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_price');
if ($indexProcess) {
$indexProcess->reindexAll();
}
}
}

Well…. that’s it :)
I hope it works for you as it works for me.

Leave a Reply

You must be logged in to post a comment.