I want to display the static block list in magento admin product creation page.
I referred this link http://www.milessebesta.com/web-design/magento-use-custom-product-attributes-to-add-cms-static-block-to-product-page/
But it shows manual entry of static block names in custom options.
I want to show the static block option list dropdown as dynamic.
1 Answer
You can find here and explanation of how you can add a product attribute with a custom source model.
The idea is to add a simple attribute like any others (via an install script) and fill in the field source_model
with the alias of a model.
This way, when the options are retrieved, the method getAllOptions
from the source model class is called. And that method can contain anything.
In your case, you just need to change in the example I linked the method getAllOptions
and make it look like this:
public function getAllOptions($withEmpty = false)
{
if (is_null($this->_options)){
$this->_options = array();
$collection = Mage::getModel('cms/block')->getCollection();
foreach ($collection as $block) {
$this->_options[] = array('label'=> $block->getTitle(), value => $block->getId());
}
}
$options = $this->_options;
if ($withEmpty) {
array_unshift($options, array('value'=>'', 'label'=>''));
}
return $options;
}
-
After implementing the module, If we add a new static block, will that be displayed along with the drop down list?? @marius Commented Aug 28, 2015 at 10:57
-
1
-