3

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.

3

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 – vinothavn Aug 28 '15 at 10:57
  • 1
    @vinothavn. Yep. it should – Marius Aug 28 '15 at 11:04
  • Thats great. Tanq – vinothavn Aug 28 '15 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.