如何在编辑页面给属性添加所见即所得编辑器的按钮

1,控制器里定义

1
2
3
4
5
6
7
8
class Magestore_Bannerslider_Adminhtml_BannerController extends Mage_Adminhtml_Controller_Action {
public function editAction() {
....
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
....

}
}

2,block定义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Magestore_Bannerslider_Block_Adminhtml_Banner_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {

protected function _prepareForm() {
$form = new Varien_Data_Form();
$fieldset->addField('description', 'editor', array(
'label' => Mage::helper('bannerslider')->__('Description'),
'name' => 'description',
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true,
));
}

protected function _prepareLayout() {
$return = parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
return $return;
}
}

3,大功告成

 

4,更新

1
2
3
4
5
6
7
8
9
10
11
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
$categoryEntityTypeId = $installer->getEntityTypeId('catalog_category');
$productEntityTypeId = $installer->getEntityTypeId('catalog_product');
$installer->updateAttribute($categoryEntityTypeId, 'description', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($categoryEntityTypeId, 'description', 'is_html_allowed_on_front', 1);
$installer->updateAttribute($productEntityTypeId, 'description', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($productEntityTypeId, 'description', 'is_html_allowed_on_front', 1);
$installer->updateAttribute($productEntityTypeId, 'short_description', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($productEntityTypeId, 'short_description', 'is_html_allowed_on_front', 1);
$installer->endSetup();

 

5,创建产品属性并自动启用可视化编辑器

比如创建属性’description2_backup’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();

$values = array(
'type' => 'text',
'label' => 'Description2 Backup',
'input' => 'textarea',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
);

$installer->addAttribute(
'catalog_product',
'description2_backup',
$values
);
$productEntityTypeId = $installer->getEntityTypeId('catalog_product');
$installer->updateAttribute($productEntityTypeId, 'description2_backup', 'is_wysiwyg_enabled', 1);
$installer->updateAttribute($productEntityTypeId, 'description2_backup', 'is_html_allowed_on_front', 1);
$installer->endSetup();
坚持原创技术分享,您的支持将鼓励我继续创作!