Magento 1.9.2.0 static block display issues

69

13

I have a website with multiple static blocks which was working in 1.9.1.0, but with 1.9.2.0 the static blocks start displaying sporadically, as they sometimes show the wrong block rather than the correct block. Sometimes they display as desired. Does anyone know how to solve this issue which may be related to this issue?

w.k

Posted 2015-07-08T15:39:49.060

Reputation: 448

just replace mage/cms folder with old version folder.it will resolve automatically – user2358082 – 2015-10-22T09:18:56.110

Totally sounds like a legit solution. Do you have any source to back it up? – Julien Lachal – 2015-10-22T09:41:20.300

1

This bug is still apparent in 1.9.2.4. Added scenario/details to bug tracker comments.

– zigojacko – 2016-08-09T15:48:30.933

@zigojacko any idea what the fix is for 1.9.2.4? – Akif – 2016-09-16T09:58:49.410

No, sorry @Akif. All I did for now as a workaround was to disable block caching until someone releases a working fix or I have more time to look into this again. – zigojacko – 2016-09-16T12:06:52.350

This sounds unreproducable and crazy. If you have a better explanation we might help you, but so I see no way, sorry. – Fabian Blechschmidt – 2015-07-08T16:04:44.613

im having two version of the website one with 1.9.1.0 and one with 1.9.2.0 in 1.9.1.0 every thing as it supposed but with 1.9.2.0 it gone crazy – w.k – 2015-07-08T16:17:38.683

2I can confirm this. Encountered it on one shop. Cache keys are identical between the 2 blocks – Sander Mangel – 2015-07-08T16:53:44.273

8

There is an open bug for this http://www.magentocommerce.com/bug-tracking/issue/index/id/870

– Steve Robbins – 2015-07-08T19:00:43.603

The open bug contains steps to reproduce this. http://www.magentocommerce.com/bug-tracking/issue/index/id/870

– Andrew Kett – 2015-07-08T21:49:26.267

I voted to reopen due to the attention this question is receiving, as it's obvious the related question is not being found by up-voters seeking a similar solution. – Tim Hallman – 2015-07-09T12:44:01.540

Reopened as this question has received workable solutions. – benmarks – 2015-07-09T13:24:22.957

9According to Piotr this is now a confirmed bug and is being looked into by Magento core team. – benmarks – 2015-07-09T15:07:43.040

Answers

57

I had this problem with EE 1.14.2 and it looks like the same issue has come up in CE 1.9.2. I documented my problem and solution on this SE question.

Basically due to the following code being added to the constructor of Mage_Cms_Block_Block:

$this->setCacheTags(array(Mage_Cms_Model_Block::CACHE_TAG));
$this->setCacheLifetime(false);

CMS static blocks are now cached. The problem arises from how the cache key info is generated. It falls back to the Mage_Core_Block_Abstract behavior of using the blocks name in layout. If the block hasn't been added with layout, e.g on a cms page, this name doesn't exist. This can result in static blocks sharing the same cache key and getting mixed up in cache.

My solution was to override the Mage_Cms_Block_Block class and set the cache key info based on the block id and current store.

/**
 * Override cms/block to add cache key. This started being a problem as of EE 1.14.2 and CE 1.9.2 when the _construct
 * method was added which turns on caching for cms blocks
 */
class Mysite_Cms_Block_Block extends Mage_Cms_Block_Block
{

    /**
     * If this block has a block id, use that as the cache key.
     *
     * @return array
     */
    public function getCacheKeyInfo()
    {
        if ($this->getBlockId()) {
            return array(
                Mage_Cms_Model_Block::CACHE_TAG,
                Mage::app()->getStore()->getId(),
                $this->getBlockId(),
                (int) Mage::app()->getStore()->isCurrentlySecure()
            );
        } else {
            return parent::getCacheKeyInfo();
        }
    }
}

Obviously this would need to be added in your own module with a config.xml file and block override etc. Alternatively you could copy Mage_Cms_Block_Block to the local code pool and add the cache key there.

You can see the new lines added in 1.9.2 here

Andrew Kett

Posted 2015-07-08T15:39:49.060

Reputation: 2 381

This does not work for version 1.9.2.4. The problem still exsists, does anyone know a fix? – Akif – 2016-09-16T10:21:53.957

What exactly has to be added to the config.xml? – Max – 2016-11-11T13:21:13.737

How are you instantiating these static blocks? If you do it through layout xml, you can just add a unique name to your block and it should cache fine. In which scenario would you not give a name to your block (widgets perhaps?) – Erfan – 2015-07-09T03:36:38.077

1@Erfan This problem happens when adding blocks to CMS pages like this {{block type="cms/block" block_id="block_id"}} or when loading a static block directly in a template – Andrew Kett – 2015-07-09T04:13:54.853

6

here is a free extension for this wierd problem. Hope it will benefit everyone who face this problem. https://github.com/progammer-rkt/Rkt_SbCache

– Rajeev K Tomy – 2015-07-09T09:36:52.887

@Rajeev Which versions of Magento is it compatible with? Will also work correct with Mage 1.6.x? – zitix – 2015-07-14T16:57:55.140

@zitix : I didnt test that on 1.6x. But it will work I think. I can give you 99% guarantee. – Rajeev K Tomy – 2015-07-14T17:06:06.343

A file based override in the local pool of the core class might be safe enough, and work when other blocks extend via class name – Robbie Averill – 2015-07-15T11:04:55.957

1

I created a gist for a temporary solution out of andrewkett's answer. Just add this app/code/local/Mage/Cms/Block/Block.php to your Magento directory and the problem will be solved. Just remember to remove the file before you perform your next Magento update (assuming they include the fix in the next update).

– Jay El-Kaake – 2015-07-21T05:03:11.300

13

I just upgraded to 1.9.2.0 and I'm experiencing this too. Categories that are set to display Static Blocks + Products are randomly displaying the wrong Static Block. This did not exist prior to my 1.9.2.0 upgrade.

Temporary Fix Disable the Blocks HTML output cache and the blocks displayed are correctly.

studio2f

Posted 2015-07-08T15:39:49.060

Reputation: 193

Im facing this also at the home page and in the product pages – w.k – 2015-07-08T16:18:41.890

This work for now but should be a bitter solution – w.k – 2015-07-08T16:49:28.127

Yep, this is what I did for now. – Sharif – 2015-07-14T14:22:51.430

13

Here we go with local module based solution as above solution does not provide whole steps. We need to create Custom module because you all know that Magento Boogieman will get you! if change the core :)

You will need to following files: app/etc/modules/Bhupendra_Cms.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Bhupendra_Cms>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Cms/>
            </depends>
        </Bhupendra_Cms>
    </modules>
</config>

app/code/local/Bhupendra/Cms/etc/config.xml

<?xml version="1.0"?>
<config>
        <modules>
            <Bhupendra_Cms>
                <version>1.0.0</version>
            </Bhupendra_Cms>
        </modules>
        <global>
            <blocks>
                <cms>
                    <rewrite>
                        <block>Bhupendra_Cms_Block_Block</block>
                        <widget_block>Bhupendra_Cms_Block_Widget_Block</widget_block>
                    </rewrite>
                </cms>
            </blocks>
        </global>
</config>

app/code/local/Bhupendra/Cms/Block/Block.php

<?php
class Bhupendra_Cms_Block_Block extends Mage_Cms_Block_Block {

   public function getCacheKeyInfo()
    {

      $blockId = $this->getBlockId();
      if ($blockId) {
            $result = array(
                $blockId,
                Mage::app()->getStore()->getCode(),
            );
      } else {
           $result = parent::getCacheKeyInfo();
       }
       return $result;
   }

}

app/code/local/Bhupendra/Cms/Block/Widget/Block.php

class Bhupendra_Cms_Block_Widget_Block extends Mage_Cms_Block_Widget_Block
{
       /**
     * Storage for used widgets
     *
     * @var array
     */
    static protected $_widgetUsageMap = array();

    /**
     * Prepare block text and determine whether block output enabled or not
     * Prevent blocks recursion if needed
     *
     * @return Mage_Cms_Block_Widget_Block
     */
    protected function _beforeToHtml()
    {
        parent::_beforeToHtml();
        $blockId = $this->getData('block_id');
        $blockHash = get_class($this) . $blockId;

        if (isset(self::$_widgetUsageMap[$blockHash])) {
            return $this;
        }
        self::$_widgetUsageMap[$blockHash] = true;

        if ($blockId) {
            $block = Mage::getModel('cms/block')
                ->setStoreId(Mage::app()->getStore()->getId())
                ->load($blockId);
            if ($block->getIsActive()) {
                /* @var $helper Mage_Cms_Helper_Data */
                $helper = Mage::helper('cms');
                $processor = $helper->getBlockTemplateProcessor();
                $this->setText($processor->filter($block->getContent()));
                $this->addModelTags($block);
            }
        }

        unset(self::$_widgetUsageMap[$blockHash]);
        return $this;
    }

     /**
     * Retrieve values of properties that unambiguously identify unique content
     *
     * @return array
     */
    public function getCacheKeyInfo()
    {
        $result = parent::getCacheKeyInfo();
        $blockId = $this->getBlockId();
        if ($blockId) {
            $result[] = $blockId;
       }
        return $result;
   }
}

For more information you can visit following link and also download from it https://www.milople.com/blogs/ecommerce/solved-magento-static-block-display-issue.html

Bhupendra Jadeja

Posted 2015-07-08T15:39:49.060

Reputation: 2 026

Setup the module and it didn't help - my issue is that CMS blocks assigned to category disappear, they don't show at all. – Haim – 2016-03-20T14:51:22.830

@Haim if you are using 1.9.2.2 then you need make entry into System->permission - > cms block of that particular block – Bhupendra Jadeja – 2016-03-21T07:12:51.603

i'm using Magento ver. 1.9.2.0 - but again my issue is slightly different, I set a CMS block to show on a category page and the CMS block just doesn't show - if i refresh the cache it shows until the next time it just dissapears – Haim – 2016-03-21T16:17:32.477

I suggest you to update magento version i think it has been now. – Bhupendra Jadeja – 2016-03-22T06:15:12.883

7

There is no official patch for this, however, it was resolved in CE 1.9.2.1

diff -r magento-CE-1.9.2.0/app/code/core/Mage/Cms/Block/Block.php magento-CE-1.9.2.1/app/code/core/Mage/Cms/Block/Block.php
74a75,94
> 
>     /**
>      * Retrieve values of properties that unambiguously identify unique content
>      *
>      * @return array
>      */
>     public function getCacheKeyInfo()
>     {
>         $blockId = $this->getBlockId();
>         if ($blockId) {
>             $result = array(
>                 'CMS_BLOCK',
>                 $blockId,
>                 Mage::app()->getStore()->getCode(),
>             );
>         } else {
>             $result = parent::getCacheKeyInfo();
>         }
>         return $result;
>     }
diff -r magento-CE-1.9.2.0/app/code/core/Mage/Cms/Block/Widget/Block.php magento-CE-1.9.2.1/app/code/core/Mage/Cms/Block/Widget/Block.php
84a85
>                 $this->addModelTags($block);
90a92,106
> 
>     /**
>      * Retrieve values of properties that unambiguously identify unique content
>      *
>      * @return array
>      */
>     public function getCacheKeyInfo()
>     {
>         $result = parent::getCacheKeyInfo();
>         $blockId = $this->getBlockId();
>         if ($blockId) {
>             $result[] = $blockId;
>         }
>         return $result;
>     }

Note: It's been reported that there are still issues with CMS pages on multiple store views:

Magento CE 1.9.2.1 fixes this only partially.

The problem still persists for CMS Pages on multiple store views. Here is an Updated Hotfix (Note this is not an official patch): https://gist.github.com/tux-rampage/77b286f7973336877f7b#file-luka-mce20150805-1-9-2-1-caching-hotfix-patch

Source: http://www.magentocommerce.com/products/bug-tracking/issue/index/id/870

Steve Robbins

Posted 2015-07-08T15:39:49.060

Reputation: 1 958

1

X-Ref: http://blog.fabian-blechschmidt.de/magento-cache-bug/

– hakre – 2015-12-17T16:22:55.200

4

I can confirm this issue too.

To reproduce:

  1. Using the CMS -> Widgets, create a widget to add a static block to the left sidebar.

  2. Then create second widget to add second static block (different block than in step 1) to the left sidebar.

  3. If cache is disabled, both static blocks are correctly displayed in the sidebar.

  4. But if you enable cache, you will see the static block from step 1 displayed twice.

zitix

Posted 2015-07-08T15:39:49.060

Reputation: 955

Hi Zitix I face the same issue like you can you tell me how you solve this – Jaimin – 2017-08-23T06:53:39.163

3

Piotr from Magento has published a non-official patch for this issue for the time being: https://gist.github.com/piotrekkaminski/ecd245e8c9390e4020db

Seems to do the trick. Yes, it's editing the core, but fixes the issue until Magento releases the official patch or next version...

Rob Mangiafico

Posted 2015-07-08T15:39:49.060

Reputation: 1 233

This trick is used on the newer version 1.9.3.3. however it doesnt fix my issue. – Rebel – 2017-07-17T22:03:26.227

3

Upgrade Magento to 1.9.2.1

I did it and enabled cache for Blocks HTML output and it seems to be fixed.

As well as some security issues are addressed in new release.

Sharif

Posted 2015-07-08T15:39:49.060

Reputation: 425

3

In latest version of Magento enhances it with new security features . you can add permissions in system->permissions to static block.

user32751

Posted 2015-07-08T15:39:49.060

Reputation: 39

2in magento 1.9.2.0 there is a problem in caching static block , you are talking about something different. – w.k – 2015-11-12T15:20:58.063

Nice , I was not aware of this feature – amit_game – 2016-03-20T15:22:00.190

I like this. :) – zed Blackbeard – 2017-01-16T07:13:09.820

2

I had the same issue with my shop. The best workaround I have found out so far is to deactivate caching for the affected blocks. You can do so by setting the cache lifetime of the blocks to null.

Globally disabling the "Blocks HTML output" cache on a live site is not a good idea as it unnecessarily impacts site performance.

Disabling the cache for one block in xml:

<block ... >
    ...
    <action method="unsetData"><key>cache_lifetime</key></action>
    <action method="unsetData"><key>cache_tags</key></action>
</block>

Disabling the cache for one block in php:

$this->getLayout()->createBlock('cms/block')
    ->setCacheLifetime(null)
    ->setBlockId('block-id')
    ->toHtml();

Do not set the cache lifetime to "0" as pointed out in this article

Andreas Riedmüller

Posted 2015-07-08T15:39:49.060

Reputation: 143

Andreas - I'm curious what is the impact of using the technique described in that article and what how do the two alternatives you provide here avoid the negative consequences you outline? – Bryan 'BJ' Hoffpauir Jr. – 2015-07-21T20:59:49.170

1the first approach is not going to work because, magento will interpret that layout update as lik this $block-&gt;setCacheLifeTime("null"); Note NULL and "null" are two different things (later one is a string) and hence expected result will not obtain. – Rajeev K Tomy – 2015-07-22T12:39:08.000

1@BJ Hoffpauir: If the cache for a cms/block block is activated, the same cached cms/block will be used for all store views. If you have an english(store view) and german(store view) version for the same block-identifier either the english or the german one will be used for both store views. Disabling the cache for this block solves the problem. If you still want to cache the block you can do so by putting the block into another block and cache this block instead. – Andreas Riedmüller – 2015-07-23T09:18:04.080

1

@Rajeev Thanks, I found this method in several posts, but I am pretty sure you are right. I changed the method to disable the cache in xml. The previous method was an accepted answer here though: http://stackoverflow.com/questions/27684236/magento-disable-cache-for-price-block

– Andreas Riedmüller – 2015-07-23T09:24:34.177

2

I was able to fix this issue by updating the existing extensions in Magento Connection Manager. After looking into it, I was under the impression that the problem exists in the Magento caching system.

By default Magento has several packages related to its caching technologies. They include adapters and libraries for Zend and Redis.

Instead of trying to find the appropriate package, I chose to update all the packages in my installation.

Then I chose the checkmark on: Mage_All_Latest Which is a Metapackage for the latest stable Magento 1.9.0.0 release.

It may be possible to fix the issue by upgrading only the right packages. I felt this was the better way to go because I am under suspicion that this method also applies security patches.

Coffee123

Posted 2015-07-08T15:39:49.060

Reputation: 67

1

You will have to do a full upgrade, or backport 1.9.2.0

CMS Block and Widget caching changes in 1.9.2.1

magento-1921/app/code/core/Mage/Cms/Block/Block.php

diff -r magento-1920/app/code/core/Mage/Cms/Block/Block.php magento-1921/app/code/core/Mage/Cms/Block/Block.php
74a75,94
> 
>     /**
>      * Retrieve values of properties that unambiguously identify unique content
>      *
>      * @return array
>      */
>     public function getCacheKeyInfo()
>     {
>         $blockId = $this->getBlockId();
>         if ($blockId) {
>             $result = array(
>                 'CMS_BLOCK',
>                 $blockId,
>                 Mage::app()->getStore()->getCode(),
>             );
>         } else {
>             $result = parent::getCacheKeyInfo();
>         }
>         return $result;
>     }

magento-1921/app/code/core/Mage/Cms/Block/Widget/Block.php

diff -r magento-1920/app/code/core/Mage/Cms/Block/Widget/Block.php magento-1921/app/code/core/Mage/Cms/Block/Widget/Block.php
84a85
>                 $this->addModelTags($block);
89a91,105
>     }
> 
>     /**
>      * Retrieve values of properties that unambiguously identify unique content
>      *
>      * @return array
>      */
>     public function getCacheKeyInfo()
>     {
>         $result = parent::getCacheKeyInfo();
>         $blockId = $this->getBlockId();
>         if ($blockId) {
>             $result[] = $blockId;
>         }
>         return $result;

Fiasco Labs

Posted 2015-07-08T15:39:49.060

Reputation: 5 998

-1

This is confirmed bug in 1.9.2 version, for time being you can resolve this problem by just disabling "Blocks HTML output" cache from admin -> cache management section

Hope it helps

user28171

Posted 2015-07-08T15:39:49.060

Reputation:

Never edit or change CORE classes. – Muhammad Ahsan Horani – 2016-09-14T10:11:28.337

studio2f had mention thie answer, u can use @andrewkett or click on "this issue" in the main question this will help u also – w.k – 2015-07-16T08:28:42.513

2

I would say that disabling all of block caching to address a problem that only manifests itself on some specific blocks is a bit like chopping off one's entire hand if you develop frostbite on a finger. Chopping off the finger, while also unpleasant, would at least be a more proportionate response to the malady. Andrewkett's (http://magento.stackexchange.com/users/527/andrewkett) answer is a more reasonable approach: http://magento.stackexchange.com/questions/73685/magento-1-9-2-0-static-block-display-issues/73694#73694

– Bryan 'BJ' Hoffpauir Jr. – 2015-07-21T22:13:41.667