Add additional text field to magento review

这一生的挚爱 提交于 2019-12-21 21:44:09

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7941032/add-additional-text-field-to-magento-review

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!