Translate Magento Cookie Notice

Thanks to DSGVO some customers want to have a cookie notice:

Magento has this feature already built in. You can turn it on in the backend:

System > Configuration > General > Web > Session Cookie Management > Cookie Restriction Mode: YES

Beside this you can define what the customer sees in the CMS block: cookie_restriction_notice_block.

Magento can have the same cms block identifier for different stores. Unfortunately this doesn't work for this feature.

The reason is:

class Mage_Page_Block_Html_CookieNotice extends Mage_Core_Block_Template
{
    public function getCookieRestrictionBlockContent()
    {
        $blockIdentifier = Mage::helper('core/cookie')->getCookieRestrictionNoticeCmsBlockIdentifier();
        $block = Mage::getModel('cms/block')->load($blockIdentifier, 'identifier');
        //             [...]
    }
}

load() doesn't care about the store mapping and takes the first block with the identifier it finds - which is for every store the same.

I fixed the problem with a rewrite on the block and replaced the method with:

public function getCookieRestrictionBlockContent()
{
    $blockIdentifier = Mage::helper('core/cookie')->getCookieRestrictionNoticeCmsBlockIdentifier();
    $block = Mage::getModel('cms/block')
        // ADDED store filter
        ->setStoreId(Mage::app()->getStore()->getId()) 
        ->load($blockIdentifier);

    $html = '';
    if ($block->getIsActive()) {
        /* @var $helper Mage_Cms_Helper_Data */
        $helper = Mage::helper('cms');
        $processor = $helper->getBlockTemplateProcessor();
        $html = $processor->filter($block->getContent());
    }

    return $html;
}