Add additional text field to magento review

2019-04-14 22:25发布

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?

2条回答
ら.Afraid
2楼-- · 2019-04-14 22:36

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

查看更多
你好瞎i
3楼-- · 2019-04-14 22:44

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.

查看更多
登录 后发表回答