如何以编程方式在Magento';所见即所得编辑器
我想在Magento所见即所得编辑器(TinyMCE)的“插入变量”弹出窗口中添加自定义变量 在互联网上搜索但找不到任何解决方案,这可能吗?有人吗如何以编程方式在Magento';所见即所得编辑器,magento,tinymce,wysiwyg,magento-1.8,transactional-email,Magento,Tinymce,Wysiwyg,Magento 1.8,Transactional Email,我想在Magento所见即所得编辑器(TinyMCE)的“插入变量”弹出窗口中添加自定义变量 在互联网上搜索但找不到任何解决方案,这可能吗?有人吗 您可以在Magento后端添加自定义变量: System -> Custom Variable -> Add New Variable 您可以在此处添加HTML或纯文本变量 变量代码是标识符。 变量名称将显示的内容 有关以编程方式添加自定义变量的信息,请参阅本博客: 请按照下面的说明操作 在自定义模块窗体中添加字段 app\code\l
您可以在Magento后端添加自定义变量:
System -> Custom Variable -> Add New Variable
您可以在此处添加HTML或纯文本变量
变量代码是标识符。
变量名称将显示的内容
有关以编程方式添加自定义变量的信息,请参阅本博客:
请按照下面的说明操作
在自定义模块窗体中添加字段
app\code\local\Namespace\Module\Block\Adminhtml\Template\Email\Edit\Tabs\Form.php
$editor = Mage::getSingleton('namespace/wysiwyg_config')->getConfig(array('tab_id' => $this->getTabId()));
$fieldset->addField('body', 'editor', array(
'name' => 'body',
'label' => Mage::helper('module')->__('Body'),
'title' => Mage::helper('module')->__('Body'),
'style' => 'width:700px; height:500px;',
'config' => $editor,
'wysiwyg' => true,
'required' => true,
));
app\code\local\Namespace\Module\Model\Wysiwyg\Config.php
<?php
class Namespace_Module_Model_Wysiwyg_Config extends Mage_Cms_Model_Wysiwyg_Config
{
/**
*
* @param Varien_Object
* @return Varien_Object
*/
public function getConfig($data = array())
{
$config = parent::getConfig($data);
$newOptiones = Mage::getSingleton('namespace/variables_options')->getWysiwygPluginSettings($config);
if (isset($newOptiones['plugins'][1]) && is_array($newOptiones['plugins'][1])) {
$config->setData('plugins', array($newOptiones['plugins'][1]));
}
$config->setData('files_browser_window_url', Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg_images/index/'));
$config->setData('directives_url', Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive'));
$config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
$config->setData('widget_window_url', Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/widget/index'));
$config->setData('add_variables', true);
return $config;
}
}
实际上,我想通过我的自定义模块以编程方式添加新变量。我按照这些说明操作,但并不适用于我,我正在CMS页面和块中插入{{var customer_email}},但它不会呈现到当前用户的电子邮件中。请帮忙
<?php
class Namespace_Module_Adminhtml_VariableController extends Mage_Adminhtml_Controller_Action
{
/**
* WYSIWYG Plugin Action
*
*/
public function wysiwygPluginAction()
{
$customVariables = Mage::getModel('namespace/variables_process')->getVariablesOptionArray(true);
$this->getResponse()->setBody(Zend_Json::encode($customVariables));
}
}
<?php
class Namespace_Module_Model_Variables_Process extends Mage_Core_Model_Variable
{
public function getVariablesOptionArray($withGroup = false)
{
$collection = $this->getCollection();/*Custom Module Collection*/
$variables = array();
foreach ($collection->toOptionArray() as $variable) {
$variables[] = array(
'value' => '{{customVar code=' . $variable['value'] . '}}',
'label' => Mage::helper('core')->__('%s', $variable['label'])
);
}
if ($withGroup && $variables) {
$variables = array(
'label' => Mage::helper('core')->__('Custom Variables'),
'value' => $variables
);
}
$allVars = array(
$variables
);
return $allVars;
}
}