Install CMS blocks with your module

You can do this as shown in the following example:

<?php

/* @var $installer Mage_Core_Model_Resource_Setup */
$oInstaller = $this;

$oInstaller->startSetup();


$oCmsBlocks = [
    [
        'title'      => 'Footer bar for benefits',
        'identifier' => 'footer-bar',
        'content'    => <<<HTML
<ul>
    <li>Shop Benefit 1</li>
     <li>Shop Benefit 2</li>
     <li>Shop Benefit 3</li>
     <li>Shop Benefit 4</li>
     <li>Customer Service (D): 
        <a href="tel:08008828838" class="tel">0800 - 882 883 8</a>
    </li>
 </ul>
HTML
        ,
        'is_active'  => 1,
        'stores'     => 0
    ],
    [
        'title'      => 'Footer payment methods',
        'identifier' => 'footer-left',
        'content'    => <<<HTML
<p>Payment methods:</p>
<ul class="img-list">
    <li>
        <img src="{{skin url='images/payment/visa.png'}}"
             alt="Visa"></li>
    <li>
        <img src="{{skin url='images/payment/paypal.png'}}"
             alt="PayPal"></li>
    <li>
        <img src="{{skin url='images/payment/mastercard.png'}}"
             alt="MasterCard"></li>
    <li>
        <img src="{{skin url='images/payment/ec.png'}}"
             alt="EC"></li>
</ul>
HTML
        ,
        'is_active'  => 1,
        'stores'     => 0
    ],
    [
        'title'      => 'Footer social media',
        'identifier' => 'footer-right',
        'content'    => <<<HTML
<p>Visit us on Facebook</p>
<ul class="social-media">
    <li>
        <a href="http://www.facebook.com/LAMYGermany"
           target="_blank">
            <img class="social-media-logo"
                 title="Facebook" alt="Facebook"
                 src="{{skin url='images/social/facebook.svg'}}">
            Facebook
        </a>
    </li>
</ul>
HTML
        ,
        'is_active'  => 1,
        'stores'     => 0
    ]
];


foreach ($aCmsBlocks as $aData) {
    /* @var Mage_Cms_Model_Block $oBlock */
    $oBlock = Mage::getModel('cms/block')->load(
        $aData['identifier'], 'identifier'
    );
    if ($oBlock->getId()) {
        $aData['block_id'] = $oBlock->getId();
        $oBlock->setData($aData)
            ->save();
    } else {
        Mage::getModel('cms/block')->setData($aData)->save();
    }
}
$oInstaller->endSetup();

For more examples have a look at the folder mage/app/code/core/Mage/Cms/data/cms_setup.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.