I need to create static blocks programmatically. How to assign a block to selected store views?
I've found tutorials about creating static blocks, but they all add the block to all store views, like this:
public function createCmsBlock()
{
// $this->blockFactory is of type: \Magento\Cms\Model\BlockFactory
$cmsBlock = $this->blockFactory->create();
$cmsBlock->setIdentifier('block-identifier')
->setTitle('Block Title')
->setContent('Block Content')
->setIsActive(true)
->setStores([0]);
$cmsBlock->save();
}
As far as I understand the line ->setStores([0]);
adds the block to all store views. But how to force it to add our block only to selected store views? And how to retrieve list of such store views?
Magento\Store\Model\StoreManagerInterface
from u get storeId