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.

Marius
199k55 gold badges431 silver badges837 bronze badges
asked Aug 28, 2015 at 10:28

1 Answer 1

4

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;
}
answered Aug 28, 2015 at 10:48
3
  • 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
    @vinothavn. Yep. it should Commented Aug 28, 2015 at 11:04
  • Thats great. Tanq Commented Aug 28, 2015 at 11:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.