Magento: moving “Recently Viewed” to a product page creates a strange caching error

So, we put the block "recently viewed" in our product. Everything seems to be looking good at first, but now I see strange errors related to null layouts. If I turn off caching, it works fine, but with full page caching it doesn't work when $ this-> getColumnCount () is called; in the template.

What I did for a recent view on the product page was:

in the .xml directory inside the product_view directory content block:

            <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') ?>

all load for the first time, but then if I click on another type of product, reload the page where it will fail. I traced the error to the class: Mage_Page_Helper_Layout.

getCurrentPageLayout() :

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

$this- > getLayout null, getBlock .
, , .

+5
4

? , Magento Enterprise 1.9 . , .

+1

admin /var/cache? Magento , , . , .

+1

I just applied your changes to the Magento EE 1.9.1 stock installation and I cannot get the error message.

The block is correctly updated as long as I visit my directory, and it does not raise any exceptions when I refresh the page several times.

+1
source

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();
     }
 }
+1
source

All Articles