添加额外的文本字段到 magento review

发布于 2024-12-12 19:06:54 字数 129 浏览 0 评论 0原文

我正在尝试向 magento 的产品评论添加一个额外的文本字段。看来这可能需要存在于“review_detail”表中,但除了在数据库中创建列并将字段添加到模板文件之外,我不确定如何添加此字段以便将其集成到审查制度。谁能让我朝着正确的方向开始?

I'm trying to add an additional text field to magento's product review. It looks like maybe this would need to live in the 'review_detail' table, but beyond creating the column in the db and adding the field to the template file, I'm not sure how to add this field so that it will be integrated into the review system. Can anyone get me started in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤千羽 2024-12-19 19:06:54

我在评论表单中添加了 2 个额外字段,只需转到 frontend\base\default\template\review/form.phtml 添加两个字段作为其他文本字段。

现在转到 app\code\core\Mage\Review\Model\Mysql4\Review.php

protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), // New field 1
'fname' => $object->getFname(), // New field 2
);

现在在数据库的 review_detail 表中添加电子邮件、fname 也转到 app\code\core\Mage\Adminhtml\Block\Review\Edit \Form.php 还添加 :

$fieldset->addField('fname', 'text', array( // New field 2
'label' => Mage::helper('review')->__('First Name'),
'required' => true,
'name' => 'fname'
));

$fieldset->addField('email', 'text', array( // New field 1
'label' => Mage::helper('review')->__('Email'),
'required' => true,
'name' => 'email'
));

之前,

$fieldset->addField('nickname', 'text', array(
'label' => Mage::helper('review')->__('Nickname'),
'required' => true,
'name' => 'nickname'
));

我希望现在您可以在审核表单中添加额外的字段。

谢谢

I have added 2 extra field in review form just go to the frontend\base\default\template\review/form.phtml add two field as other text field.

Now go to app\code\core\Mage\Review\Model\Mysql4\Review.php

protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), // New field 1
'fname' => $object->getFname(), // New field 2
);

Now add email,fname in the review_detail table in the database also go to app\code\core\Mage\Adminhtml\Block\Review\Edit\Form.php also add :

$fieldset->addField('fname', 'text', array( // New field 2
'label' => Mage::helper('review')->__('First Name'),
'required' => true,
'name' => 'fname'
));

$fieldset->addField('email', 'text', array( // New field 1
'label' => Mage::helper('review')->__('Email'),
'required' => true,
'name' => 'email'
));

before to

$fieldset->addField('nickname', 'text', array(
'label' => Mage::helper('review')->__('Nickname'),
'required' => true,
'name' => 'nickname'
));

I hope now you can add extra fields in review form.

Thanks

只为一人 2024-12-19 19:06:54

对于“无法发布评论”错误,您需要在 app\code\core\Mage\Review\controllers\ProductController.php 的 _cropReviewData 函数中添加这 2 个新字段,

protected function _cropReviewData(array $reviewData)
{
    $croppedValues = array();
    $allowedKeys = array_fill_keys(array('detail', 'title', 'nickname', 'email', 'fname), true);

    foreach ($reviewData as $key => $value) {
        if (isset($allowedKeys[$key])) {
            $croppedValues[$key] = $value;
        }
    }

    return $croppedValues;
}

希望这会有所帮助。

For the "Unable to post the review" error, you need to add this 2 new fields in the function _cropReviewData in app\code\core\Mage\Review\controllers\ProductController.php

protected function _cropReviewData(array $reviewData)
{
    $croppedValues = array();
    $allowedKeys = array_fill_keys(array('detail', 'title', 'nickname', 'email', 'fname), true);

    foreach ($reviewData as $key => $value) {
        if (isset($allowedKeys[$key])) {
            $croppedValues[$key] = $value;
        }
    }

    return $croppedValues;
}

I hope this will help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文