Skip to content

Instantly share code, notes, and snippets.

@jklance
Created May 22, 2015 14:38
Show Gist options
  • Save jklance/e862564ef4a9e427dd7b to your computer and use it in GitHub Desktop.
Save jklance/e862564ef4a9e427dd7b to your computer and use it in GitHub Desktop.
Magento - Create a CMS block in an upgrade script
$content = 'BLOCK CONTENT HERE';
//if you want one block for each store view, get the store collection
$stores = Mage::getModel('core/store')->getCollection()->addFieldToFilter('store_id', array('gt'=>0))->getAllIds();
//if you want one general block for all the store viwes, uncomment the line below
//$stores = array(0);
foreach ($stores as $store){
$block = Mage::getModel('cms/block');
$block->setTitle('Block title here');
$block->setIdentifier('block_identifier_here');
$block->setStores(array($store));
$block->setIsActive(1);
$block->setContent($content);
$block->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment