Prestashop 1.6模块错误:文件prestashop16 \ tools \ smarty \ sysplugins \ smarty_internal_templatebase.php中第719行的注意事项

时间:2015-05-27 00:58:02

标签: php smarty e-commerce prestashop prestashop-1.6

我正在开发一个模块并扩展了AdminFeaturesController.php以显示我的自定义字段添加/编辑功能值,但它在弹出窗口中显示以下错误:

  

注意文件中的第719行   d:\ XAMPP \ htdocs中\ prestashop16 \工具\智者\ sysplugins \ smarty_internal_templatebase.php(157)   :eval()' d code [8] Undefined index:value

我认为这是因为我在AdminFeaturesController.php文件中覆盖了函数initFormFeatureValue()并添加了一个新字段。这是代码:

public function initFormFeatureValue()
    {
        $this->setTypeValue();

        $this->fields_form[0]['form'] = array(
            'legend' => array(
                'title' => $this->l('Feature value'),
                'icon' => 'icon-info-sign'
            ),
            'input' => array(
                array(
                    'type' => 'select',
                    'label' => $this->l('Feature'),
                    'name' => 'id_feature',
                    'options' => array(
                        'query' => Feature::getFeatures($this->context->language->id),
                        'id' => 'id_feature',
                        'name' => 'name'
                    ),
                    'required' => true
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Value'),
                    'name' => 'value',
                    'lang' => true,
                    'size' => 33,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
                    'required' => true
                ),
                array(
                    'type' => 'select',
                    'label' => $this->l('Parent Feature Value'),
                    'name' => 'parent_id_feature_value',
                    'options' => array(
                        'query' => FeatureValue::getFeatureValues((int)Tools::getValue('id_feature')),
                        'id' => 'id_feature_value',
                        'name' => 'value'
                    ),
                    'required' => true
                ),
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            ),
            'buttons' => array(
                'save-and-stay' => array(
                    'title' => $this->l('Save then add another value mamu'),
                    'name' => 'submitAdd'.$this->table.'AndStay',
                    'type' => 'submit',
                    'class' => 'btn btn-default pull-right',
                    'icon' => 'process-icon-save'
                )
            )
        );

        $this->fields_value['id_feature'] = (int)Tools::getValue('id_feature');

        // Create Object FeatureValue
        $feature_value = new FeatureValue(Tools::getValue('id_feature_value'));

        $this->tpl_vars = array(
            'feature_value' => $feature_value,
        );

        $this->getlanguages();
        $helper = new HelperForm();
        $helper->show_cancel_button = true;

        $back = Tools::safeOutput(Tools::getValue('back', ''));
        if (empty($back))
            $back = self::$currentIndex.'&token='.$this->token;
        if (!Validate::isCleanHtml($back))
            die(Tools::displayError());

        $helper->back_url = $back;
        $helper->currentIndex = self::$currentIndex;
        $helper->token = $this->token;
        $helper->table = $this->table;
        $helper->identifier = $this->identifier;
        $helper->override_folder = 'feature_value/';
        $helper->id = $feature_value->id;
        $helper->toolbar_scroll = false;
        $helper->tpl_vars = $this->tpl_vars;
        $helper->languages = $this->_languages;
        $helper->default_form_language = $this->default_form_language;
        $helper->allow_employee_form_lang = $this->allow_employee_form_lang;
        $helper->fields_value = $this->getFieldsValue($feature_value);
        $helper->toolbar_btn = $this->toolbar_btn;
        $helper->title = $this->l('Add a new feature value');
        $this->content .= $helper->generateForm($this->fields_form);
    }

知道它出现此错误的原因吗?此外,它不会填充我的自定义字段。

1 个答案:

答案 0 :(得分:0)

好的,我修好了。问题出在我的新字段数组中的options数组。以下是正确的。

array(
                'type' => 'select',
                'label' => $this->l('Parent Feature Value'),
                'name' => 'parent_id_feature_value',
                'options' => array(
                    'query' => FeatureValue::getFeatureValuesWithLang($this->context->language->id, $parent_id),
                    'id' => 'id_feature_value',
                    'name' => 'value'
                ),
                'required' => true
            ),

这里我必须覆盖FeatureValue类并添加getFeatureValuesWithLang()函数。

public static function getFeatureValuesWithLang($id_lang, $id_feature, $custom = false)
{
    return Db::getInstance()->executeS('
        SELECT *
        FROM `'._DB_PREFIX_.'feature_value` v
        LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl
            ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.')
        WHERE v.`id_feature` = '.(int)$id_feature.'
            '.(!$custom ? 'AND (v.`custom` IS NULL OR v.`custom` = 0)' : '').'
        ORDER BY v.`position` ASC
    ', true, false);
}

实际上是做了什么,它找到了&#39;价值&#39;查询结果中不存在的字段。所以,我重写FeatureValue类并添加上面的方法并调用它。它解决了这个问题。