Magento Solutions

  • Solved: Magento 1.9.2.0 static block display issue

    While upgrading a Magento store version we found a bug in Magento 1.9.2.0 and here, we are giving a solution for this bug.

    Bug Description: While inserting two different CMS blocks in a page, Magento 1.9.2 displays static blocks sporadically which sometimes shows the wrong block rather than the correct one and sometimes displays the same block twice.

    Reason: The problem occurs due to generation of caching key info for CMS static blocks using the names rather thank block ID. Thus static blocks shares the same cache key and get mixed up in cache.

    If you want to reproduce the issue to better understand, perform following steps.

    * Create a static block with identifier “test_1? and content “This is test block 1? * Create a static block with identifier “test_2? and content “This is test block 2? * Edit the CMS home page. Using the widget selector, add “test_1? and “test_2? cms blocks * Enable cache.

    Expected Result: This is test block 1 This is test block 2

    Actual Result due to bug: This is test block 1 This is test block 1

    We have resolved this bug in Magento 1.9.2.0 and here is the solution explained.

    This happens 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);

    It adds cache functionality to static blocks. But cache key info is generated in Mage_Core_Block_Abstract, which use block name in layout. Block name does not exist since static block are not added though layout, and as a result they have the same cache key.

    Solution 1: To fix it we have created simple extension. It override Mage_Cms_Block_Block to generate correct cache key info for each static block based on store id, block id and secure connection.

    1. Create /app/etc/modules/NameSpace_Modulename.xml.
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      <?xml version="1.0"?>
      <config>
          <modules>
              <NameSpace_Modulename>
                  <active>true</active>
                  <codePool>local</codePool>
                  <depends>
                      <Mage_Cms/>
                  </depends>
              </NameSpace_Modulename>
          </modules>
      </config>
    2. Create /app/code/local/NameSpace/Modulename/etc/config.xml
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      <?xml version="1.0"?>
      <config>
          <modules>
              <NameSpace_Modulename>
                  <version>1.0.0</version>
              </NameSpace_Modulename>
          </modules>
          <global>
              <blocks>
                  <cms>
                      <rewrite>
                          <block>NameSpace_Modulename_Block_Block</block>
                          <widget_block>NameSpace_Modulename_Block_Widget_Block</widget_block>
                      </rewrite>
                  </cms>
              </blocks>
          </global>
      </config>
    3. Create /app/code/local/NameSpace/Modulename/Block/Block.php
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      <?php class NameSpace_Modulename_Block_Block extends Mage_Cms_Block_Block {
                 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();
              }
            }
      }
    4. Create /app/code/local/NameSpace/Modulename/Block/Widget/Block.php
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      <?php class NameSpace_Modulename_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;
         }
      }
    5. Thats it. CMS static blocks issue solved.

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

    cachemanagement
  • Change admin routers after Installing Security Patch Supee 6788

    The latest Magento Security Patch, SUPEE-6788 is now available for Magento Community Edition 1.7 and later releases.

    Magento also released Magento Community Edition 1.9.2.2 and Magento Enterprise Edition 1.14.2.2 which includes SUPEE-6788.

    BACKWARD COMPATIBILITY

    This patch breaks backward compatibility in three ways that can affect extensions and customizations. For example, changes to admin routing can make extensions and customizations inaccessible from the admin panel if they are not using proper routing.

    To help address concerns about the admin routing changes, these changes in the patch are turned off by default. This means that the patch will include the fix, but that it will be disabled when installed.

    Need To Make Following Modifications In Custom modules For Making Compitible with the Magento patch SUPEE-6788

    1. \app\code\community\[NameSpace]\[Modulename]\etc\config.xml
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      <admin>
          <routers>
              <modulename>
                  <use>admin</use>
                      <args>
                          <module>NameSpace_Modulename</module>
                          <frontName>modulename</frontName>
                      </args>
              </modulename>
          </routers>
      </admin>

      Need to changed it to this:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      <admin>
          <routers>
              <adminhtml>
                  <args>
                      <modules>
                          <modulename after="Mage_Adminhtml">NameSpace_Modulename_Adminhtml</modulename>
                      </modules>
                  </args>
              </adminhtml>
          </routers>       
      </admin>
    2. Need To Change Menu Action modulename/adminhtml_controllername/action To adminhtml/controllername/action.
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      <menu>
          <modulename translate="title" module="modulename">
              <title>Modulename</title>
                  <sort_order>10</sort_order>
              <children>
                  <modulename translate="title" module="modulename">
                      <title>Manage Item</title>
                      <sort_order>10</sort_order>
                      <action>modulename/adminhtml_controllername/action</action>
                  </modulename>
              </children>
          </modulename>
      </menu>

      Need to changed it to this:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      <menu>
          <modulename translate="title" module="modulename">
              <title>Modulename</title>
                  <sort_order>10</sort_order>
              <children>
                  <modulename translate="title" module="modulename">
                      <title>Manage Item</title>
                      <sort_order>10</sort_order>
                      <action>adminhtml/controllername/action</action>
                  </modulename>
              </children>
          </modulename>
      </menu>
    3. Now Need to Modified your module layouts files. \app\design\adminhtml\default\default\layout\custommodule.xml
      1
      2
      3
      4
      5
      6
      7
      8
      <?xml version="1.0"?>
      <layout version="0.1.0">
          <modulename_adminhtml_controllername_action>
              <reference name="content">
                  ...
              </reference>
          </modulename_adminhtml_controllername_action>
      </layout>

      Need to changed it to this:

      1
      2
      3
      4
      5
      6
      7
      8
      <?xml version="1.0"?>
      <layout version="0.1.0">
          <adminhtml_controllername_action>
              <reference name="content">
                  ...
              </reference>
          </adminhtml_controllername_action>
      </layout>
    4. Plugin which Use Custom Block and Variables

    SUPEE-6788 Custom Blocks (and Variables) Issue
    Issue:

    • Some blocks are not shown on CMS pages, home page, category pages, landing pages in your Magento installation after installing SUPEE-6788 patch, page layout is broken.
    • Some transactional emails, order notification emails are broken, incomplete or have some data missing after installing SUPEE-6788 patch.

    Solutions:

    By default, only two blocks (core/template and catalog/product_new) are allowed for inclusion. So we need to add our extension’s custom block in blocks permission table.
    Upgrade your custom module’s sql script as follow.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?php $installer = $this; $installer->startSetup();
     
    if(in_array($this->getTable('permission_block'),$installer->getConnection()->listTables())){
    $installer->run("
        INSERT INTO {$this->getTable('permission_block')} (block_name,is_allowed) values ('custommodule/customblock','1');
        INSERT INTO {$this->getTable('permission_variable')} (variable_name,is_allowed) values ('custom_variable_name','1');
    ");
    }
    $installer->endSetup();
    ?>

    You can manually add custom block and custom variable values which we need to use in the CMS > Pages or CMS > Static Blocks or System > Transactional Emails.
    For Adding Custom block or Custom variable Go To System > Permissions > Blocks and Click On Add New block.

    1. Add block Name like “custommodule/customblock”.
    2. Set Is Allowed “Yes”.

2 Item(s)