Blocks HTML Cache & Sub Category Display
-
13-12-2019 - |
Question
So I've moved my store up to 1.9.2.1 Everything is looking good except for the Blocks HTML Cache.
I'll try to explain this as best I can.
I have the common setup of using a static block calling a script to display sub-categories within a parent category. Something similar to this tutorial
It's always worked without any hitches...Until I upgraded. The issue I'm seeing is that any category pages using this static block script to display sub-categories are failing, resulting in all of these categories displaying the same cached sub-categories page. It's like it's not re-caching and just serving up the same content to all of these pages. It means customers can't navigate through to the correct layers of the site because any Category using the sub-category script will see the same cached layout with incorrect sub categories.
I've run a Mage cleanup script to reset any strange permission issues but with no avail. As a temporary fix so my customers can actually browse the site, I've disabled the Blocks HTML Cache which fixes the issue straight away. So clearly the issue is with the Cache not serving up the content correctly or in fact, realising that a re-cache is required. How do I go about fixing this? Is there a more efficient way of serving sub-categories within parent categories that do no list individual products?
Here is the code I am using to display sub categories in a nice grid (Pastbin):
<div class='category-grid'>
<?php
if($_collectionSize):
$i=0;
$layer = Mage::getSingleton('catalog/layer');
?>
<ul class="products-grid">
<?php
foreach ($_categories as $_category):
$layer->setCurrentCategory($_category);
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$products = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($_category)
->addAttributeToSort('price', 'asc')
->setPageSize(1)
->load();
$prod = $products->getFirstItem();
$lowestProductPrice = $taxHelper->getPrice($prod, $prod->getPrice(), true, null, null, null, null, false);
$formattedPrice = Mage::helper('core')->currency($lowestProductPrice, true, false);
//$originalCategory->getThumbnail();
$_img = ($_category->getThumbnail()) ? "/media/catalog/category/".$_category->getThumbnail() : "/media/placeholders/small.jpg";
$_img = Mage::getBaseUrl() . $_img;
?>
<li class="item <?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_category->getUrl(); ?>" title="<?php echo $_category->getName(); ?>" class="product-image">
<?php if($_img):?>
<img src="<?php echo $_img; ?>" alt="<?php echo $_category->getName();?>" />
<?php else:?>
<?php echo $_category->getName();?>
<?php endif;?>
</a>
<div class="product-detail">
<h2 class="product-name"><a href="<?php echo $helper->getCategoryUrl($_category); ?>" title="<?php echo $this->stripTags($_category->getName(), null, true) ?>"><?php echo $_category->getName(); ?></a></h2>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p><?php echo $this->__('No categories found.'); ?></p>
<?php endif ?>
</div>
Solution
You may well be experiencing the static block cache bug introduced with 1.9.2, although reported as fixed in 1.9.2.1 I have still experienced caching problems with static blocks. More information available here
Magento 1.9.2.0 static block display issues
A good fix/workaround for this bug is this module