Skip to content

Instantly share code, notes, and snippets.

@markshust
Created July 9, 2015 12:39
Show Gist options
  • Save markshust/8eddf4329397c4e7978c to your computer and use it in GitHub Desktop.
Save markshust/8eddf4329397c4e7978c to your computer and use it in GitHub Desktop.
update magento static block programmatically through upgrade scripts
<?php
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$connection = $installer->getConnection();
$identifier = 'id-goes-here';
$title = 'Title Goes Here';
$contentCmsBlock = <<<EOT
<div id="$identifier">
<p>Put your content here.</p>
</div>
EOT;
$cmsBlock = Mage::getModel('cms/block')->load($identifier);
if ($cmsBlock->isObjectNew()) {
$cmsBlock->setTitle($title)
->setContent($contentCmsBlock)
->setIdentifier($identifier)
->setStores(0)
->setIsActive(true);
} else {
$cmsBlock->setTitle($title)
->setContent($contentCmsBlock)
->setStores(0)
->setIsActive(true);
}
$cmsBlock->save();
$installer->endSetup();
@glavertu
Copy link

glavertu commented Jun 1, 2017

setStores() must get an array as a parameter, or use setStoreId() to give only a unique Id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment