Created
March 19, 2015 12:52
-
-
Save mborodov/6f9fcd1926e68365d8eb to your computer and use it in GitHub Desktop.
Right way create/update cms pages and static blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Installation script for create about block | |
*/ | |
$installer = $this; | |
$installer->startSetup(); | |
// Block content | |
$blockContent = <<<EOD | |
<div class="about"> | |
<div class="container"> | |
<div class="list-about clearfix bg-white"> | |
<div class="about-item"> | |
<a href="{{store url="payment"}}"> | |
<div class="about-pict"><img class="img-front" alt="" src="{{skin url=includes/main/extmedia/exmedia2911_icon1-1.png}}" /> <img class="img-profile" alt="" src="{{skin url=includes/main/extmedia/exmedia2931_icon1-2.png}}" /></div> | |
<h4 class="about-title text-left">Более 500 магазинов</h4> | |
</a> | |
</div> | |
<div class="about-item"> | |
<a href="{{store url="payment"}}"> | |
<div class="about-pict"><img class="img-front" alt="" src="{{skin url=includes/main/extmedia/exmedia2913_icon2-1.png}}" /> <img class="img-profile" alt="" src="{{skin url=includes/main/extmedia/exmedia2927_icon2-2.png}}" /></div> | |
<h4 class="about-title">Бесплатная доставка по всей РФ от 2000</h4> | |
</a> | |
</div> | |
<div class="about-item"> | |
<a href="{{store url="payment"}}"> | |
<div class="about-pict"><img class="img-front" alt="" src="{{skin url=includes/main/extmedia/exmedia2915_icon3-1.png}}" /> <img class="img-profile" alt="" src="{{skin url=includes/main/extmedia/exmedia2930_icon3-2.png}}" /></div> | |
<h4 class="about-title">Возможность забрать заказ в магазине</h4> | |
</a> | |
</div> | |
<div class="about-item"> | |
<a href="{{store url="payment"}}"> | |
<div class="about-pict"><img class="img-front" alt="" src="{{skin url=includes/main/extmedia/exmedia2917_icon4-1.png}}" /> <img class="img-profile" alt="" src="{{skin url=includes/main/extmedia/exmedia2929_icon4-2.png}}" /></div> | |
<h4 class="about-title">Одинаково ТВОЕ</h4> | |
</a> | |
</div> | |
<div class="about-item"> | |
<a href="{{store url="payment"}}"> | |
<div class="about-pict"><img class="img-front" alt="" src="{{skin url=includes/main/extmedia/exmedia2919_icon5-1.png}}" /> <img class="img-profile" alt="" src="{{skin url=includes/main/extmedia/exmedia2928_icon5-2.png}}" /></div> | |
<h4 class="about-title">Экология</h4> | |
</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
EOD; | |
// Page content | |
$pageContent = <<<EOD | |
{{block type="cms/block" block_id="home_page_about_block"}} | |
EOD; | |
// Create static block | |
$staticBlock = array( | |
'title' => 'Home Page About Block', | |
'identifier' => 'home_page_about_block', | |
'content' => $blockContent, | |
'is_active' => 1, | |
'stores' => array(0) | |
); | |
$cmsPage = array( | |
'title' => 'Home page', | |
'identifier' => 'home', | |
'content' => $pageContent, | |
'is_active' => 1, | |
'stores' => array(0), | |
'root_template' => 'one_column' | |
); | |
// Create/Update static block | |
$block = Mage::getModel('cms/block')->load($staticBlock['identifier']); | |
if ($block->getId()) { | |
$block->setContent($staticBlock ['content']); | |
$block->setTitle($staticBlock ['title']); | |
$block->save(); | |
} else { | |
Mage::getModel('cms/block')->setData($staticBlock )->save(); | |
} | |
// Create/Update CMS Page | |
$page = Mage::getModel('cms/page')->load($cmsPage ['identifier']); | |
if ($page->getId()) { | |
$page->setContent($cmsPage ['content']); | |
$page->setTitle($cmsPage ['title']); | |
$page->save(); | |
} else { | |
Mage::getModel('cms/page')->setData($cmsPage )->save(); | |
} | |
$installer->endSetup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment