0

我想将自定义变量添加到 Magento 的所见即所得编辑器(TinyMCE)的“插入变量”弹出窗口中

上网查了,没找到解决办法,可以吗?任何人?

插入变量

4

2 回答 2

1

您可以在 Magento 后端添加自定义变量:

System -> Custom Variable -> Add New Variable

您可以在此处添加 HTML 或纯文本变量。

变量代码是标识符。变量名称将显示什么。

要以编程方式添加自定义变量,请参阅此博客:

http://incho.net/ecommerce/magento/injecting-variables-into-a-magento-cms-static-block/

于 2014-05-23T13:21:41.017 回答
1

请关注下方。

在自定义模块表单 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;
    }

}

app\code\local\Namespace\Module\Adminhtml\VariableController.php

<?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));
    }    
}

app\code\local\Namespace\Module\Model\Variables\Process.php

<?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;
    }

}
于 2016-06-17T13:39:19.297 回答