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.