4

在我的项目中,我location在管理面板的“产品评论”中添加了一个新字段,按照许多博客中的说明执行以下步骤。

  • 在数据库表中创建了一个新字段review_detaillocation.
  • 在中添加以下代码app/code/code/Mage/Adminhtml/Block/Review/Edit/Form.php

        $fieldset->addField('location', 'text', array(
                'name'  => 'location',
                'label' => Mage::helper('adminhtml')->__('Location'),
                'required' => false
            )
        ); 
    

就在上面:

    $fieldset->addField('nickname', 'text', array(
        'label'     => Mage::helper('review')->__('Nickname'),
        'required'  => true,
        'name'      => 'nickname'
    ));
  • .添加以下代码app/code/core/Mage/Review/Model/Resource/Review.php

    $detail = array(
        'title'     => $object->getTitle(),
        'detail'    => $object->getDetail(),
        'nickname'  => $object->getNickname(),
        'location'  => $object->getLocation()   /* added */
    );
    
  • 在下面的函数数组中添加了“位置”。在文件中:app/code/core/Mage/Review/Model/Resource/Review/Collection.php

    protected function _initSelect()
    {
        parent::_initSelect();
        $this->getSelect()
            ->join(array('detail' => $this->_reviewDetailTable),
                'main_table.review_id = detail.review_id',
                array('detail_id', 'title', 'detail', 'nickname', 'customer_id','location'));
        return $this;
    }
    
  • 在 中添加了以下内容{$mytheme}/template/review/form.phtml

    <li>
          <label for="location_field" class="required"><em>*</em><?php echo $this->__('Location') ?></label>
          <div class="input-box">
               <input type="text" name="nickname" id="location_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getLocation()) ?>" />
          </div>
    </li>   
    

我的问题是,虽然我可以在管理面板中看到一个新字段,但每当我提交评论表单时,它并没有被提交/存储在数据库中。

我什至重新索引并清除了缓存。

我应该进行哪些更改才能使其正常工作?

请帮忙......我在magento 1.8上。

PS:我知道核心文件不应该改变。一旦我在这个问题上取得成功,我将把它覆盖到新模块。

4

3 回答 3

2

我确实遵循了问题中解释的确切步骤。并发现它工作正常。

我面临的唯一问题是{$mytheme}/template/review/form.phtml

您已name="nickname"为位置字段定义,而不是name="location"

纠正这一点,如果您仍然面临同样的问题,然后检查模块类是否被覆盖。

于 2013-12-08T08:31:51.290 回答
0

试试这个,先备份数据库。从 core_resource 表中删除表条目并加载站点。简而言之,尝试使用您的列“位置”重新创建数据库表。我不知道,当我们以各种形式添加新字段时,setter 有什么问题,它们无法正常工作。

我希望这会奏效。

于 2013-12-08T13:28:28.567 回答
0

查看在浏览器中创建的 html 代码。检查:

  • 您的字段是否包含在 -tags 中?
  • 动作类型和目标设置是否正确?
  • 使用您选择的浏览器控制台(例如 chrome F12)确保正确设置字段并真正发送表单。
于 2013-12-07T22:53:33.937 回答