Get stores id of static block on Magento 1.x
-
03-10-2020 - |
質問
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 ?
解決
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());
}
所属していません magento.stackexchange