5
votes

So we have put the "recently viewed" block into our product view. Everything seems to look fine at first but I'm now seeing weird errors that have to do with null layouts. If i turn caching off it works fine, but with full page caching enabled it fails when calling $this->getColumnCount(); in the template.

What I have done to enable recently viewed on the product page was:

in catalog.xml inside the content block of catalog_product_view:

            <block type="reports/product_viewed" name="reports.product.viewed" as="recently_viewed" template="reports/product_viewed.phtml">
                <action method="setColumnCount"><columns>4</columns></action>
                <action method="setItemLimit"><type>recently_viewed</type><limit>4</limit></action>
            </block>

in the template file: catalog/product/view.phtml:

             <?php echo $this->getChildHtml('recently_viewed') ?>

everything loads fine the first time, but then if i click on another product view, then reload the page it errors out. I traced the error down to the class: Mage_Page_Helper_Layout.

the function getCurrentPageLayout(), has a line:

 $this->getLayout()->getBlock('root')

and $this->getLayout is returning null which causes the getBlock call to throw an exception.
if i disabled caching no errors come up and everything works fine.

4
Is that in Enterprise Edition? If you look in app/code/core/Enterprise/PageCache/etc/cache.xml it seems to provide a workaround for that block but I'm unfamiliar with the feature or how it works.clockworkgeek
yeah its enterprise edition. thanks for the pointer. i'm looking into that code but can't seem a way to turn off the caching entirely for that block. even if i set the cache_lifetime to 1 it still gives me the same error, and if i take out that xml block from the cache.xml it just caches that page indefinitely and doesn't update when i click on other items.GeekPride

4 Answers

1
votes

Which version are you running ? As far as I known, Magento Enterprise 1.9 have serious problems with Full Page Caching. Sorry I can't be more helpful.

1
votes

Have you just disabled caching in admin or actually deleted /var/cache? Magento might use old cached pages when you enable it again causing errors. There is button for flushing caches in cache management or you can do it manually.

1
votes

I have just applied your changes to a stock installation of Magento EE 1.9.1 and I can't experience the error you reported.

The block is correctly updated with as long as I visit my catalog and it doesn't trigger any exceptions when I refresh the page multiple times.

1
votes

Take this patch from Varien for 1.9.1.1 and it will work:

    Index: app/code/core/Enterprise/PageCache/Model/Container/Catalognavigation.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Catalognavigation.php    (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Catalognavigation.php    (working copy)
@@ -133,6 +133,7 @@
             $category = Mage::getModel('catalog/category')->load($categoryId);
             Mage::register('current_category', $category);
         }
+        $block->setLayout(Mage::app()->getLayout());

         return $block->toHtml();
     }
Index: app/code/core/Enterprise/PageCache/Model/Container/Accountlinks.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Accountlinks.php (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Accountlinks.php (working copy)
@@ -71,6 +71,7 @@
                     $linkInfo['li_params'], $linkInfo['a_params'], $linkInfo['before_text'], $linkInfo['after_text']);
             }
         }
+        $block->setLayout(Mage::app()->getLayout());

         return $block->toHtml();
     }
Index: app/code/core/Enterprise/PageCache/Model/Container/Orders.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Orders.php   (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Orders.php   (working copy)
@@ -63,6 +63,7 @@

         $block = new $block;
         $block->setTemplate($template);
+        $block->setLayout(Mage::app()->getLayout());

         return $block->toHtml();
     }
Index: app/code/core/Enterprise/PageCache/Model/Container/Sidebar/Recentlycompared.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Sidebar/Recentlycompared.php (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Sidebar/Recentlycompared.php (working copy)
@@ -62,6 +62,7 @@

         $block = new $block;
         $block->setTemplate($template);
+        $block->setLayout(Mage::app()->getLayout());

         return $block->toHtml();
     }
Index: app/code/core/Enterprise/PageCache/Model/Container/Sidebar/Comparelist.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Sidebar/Comparelist.php  (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Sidebar/Comparelist.php  (working copy)
@@ -60,6 +60,7 @@

         $block = Mage::app()->getLayout()->createBlock('catalog/product_compare_list');
         $block->setTemplate($template);
+        $block->setLayout(Mage::app()->getLayout());

         return $block->toHtml();
     }
Index: app/code/core/Enterprise/PageCache/Model/Container/Messages.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Messages.php (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Messages.php (working copy)
@@ -81,6 +81,7 @@
         foreach ($this->_messageStoreTypes as $type) {
             $this->_addMessagesToBlock($type, $block);
         }
+        $block->setLayout(Mage::app()->getLayout());

         return $block->toHtml();
     }
Index: app/code/core/Enterprise/PageCache/Model/Container/Viewedproducts.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Viewedproducts.php   (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Viewedproducts.php   (working copy)
@@ -76,6 +76,7 @@
         $block = new $block;
         $block->setTemplate($template);
         $block->setProductIds($productIds);
+        $block->setLayout(Mage::app()->getLayout());

         return $block->toHtml();
     }
Index: app/code/core/Enterprise/PageCache/Model/Container/Wishlistlinks.php
===================================================================
--- app/code/core/Enterprise/PageCache/Model/Container/Wishlistlinks.php    (revision 87812)
+++ app/code/core/Enterprise/PageCache/Model/Container/Wishlistlinks.php    (working copy)
@@ -59,6 +59,7 @@
     {
         $block = $this->_placeholder->getAttribute('block');
         $block = new $block;
+        $block->setLayout(Mage::app()->getLayout());
         return $block->toHtml();
     }
 }