Question

For programatically create a static block I use a function that behaves like this pieces of code

    $block = Mage::getModel('cms/block');
    $block->setTitle($title);
    $block->setIdentifier($identifier);
    $block->setStores(array($storeId));
    $block->setIsActive($isActive);
    $block->setContent($content);
    $block->save(); 

But if I want to know the stores of a static block what I want to do. I try innocently to call getStores on block but this not works

    $blockCollection = Mage::getModel('cms/block')->getCollection();
    foreach($blockCollection as $block) {
        var_dump($block->getIdentifier());
        var_dump($block->getStores());
    }

there is something wrong that I forget ?

Was it helpful?

Solution

The stores are stored in a different table cms_block_store.

To lookup the store ids you can do the following:

$blockCollection = Mage::getModel('cms/block')->getCollection();
foreach($blockCollection as $block) {
    $storeIds = $block->getResource()->lookupStoreIds($block->getBlockId());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top