当任何客户提交产品评论时,必须自动批准审核。无需经管理员批准。
答案 0 :(得分:3)
您可以尝试this approach。
更新:该链接不再有效,因此我在网络存档中发布了该链接。
答案 1 :(得分:1)
创建新模块是最好的方法,它简单易行。 第1步:在app / etc / modules中创建一个名为Dpc_Review.xml的模块声明文件
<?xml version="1.0"?>
<config>
<modules>
<Dpc_Review>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Review/>
</depends>
</Dpc_Review>
</modules>
</config>
步骤2:在app / etc / local中创建一个名为Dpc的文件夹 第3步:在app / etc / local / Dpc /里面创建一个新的文件夹Review 第3步:在app / etc / local / Dpc / Review内部创建3个文件夹控制器等和Helper 第4步:在app / etc / local / Dpc / Review / etc /里面创建一个名为config.xml的文件
<?xml version="1.0"?>
<config>
<modules>
<Dpc_Review>
<version>0.0.1</version>
</Dpc_Review>
</modules>
<frontend>
<routers>
<review>
<args>
<modules>
<Dpc_Review before="Mage_Review">Dpc_Review</Dpc_Review>
</modules>
</args>
</review>
</routers>
</frontend>
<global>
<helpers>
<dpc_review>
<class>Dpc_Review_Helper</class>
</dpc_review>
<review>
<rewrite>
<data>Dpc_Review_Helper_Data</data>
</rewrite>
</review>
</helpers>
</global>
</config>
第5步:在app / code / local / Dpc / Review / Helper里面创建一个名为Data.php的文件
<?php
/**
* Class Dpc_Review_Helper_Data
*/
class Dpc_Review_Helper_Data extends Mage_Review_Helper_Data
{
}
第6步:在app / code / local / Dpc / Review / controllers /里面创建一个名为ProductController.php的文件
<?php
require_once 'Mage' . DS . 'Review' . DS . 'controllers' . DS . 'ProductController.php';
/**
* Class Dpc_Review_ProductController
*/
class Dpc_Review_ProductController extends Mage_Review_ProductController
{
/**
* Submit new review action
*
*/
public function postAction()
{
if (!$this->_validateFormKey()) {
// returns to the product item page
$this->_redirectReferer();
return;
}
if ($data = Mage::getSingleton('review/session')->getFormData(true)) {
$rating = array();
if (isset($data['ratings']) && is_array($data['ratings'])) {
$rating = $data['ratings'];
}
} else {
$data = $this->getRequest()->getPost();
$rating = $this->getRequest()->getParam('ratings', array());
}
if (($product = $this->_initProduct()) && !empty($data)) {
$session = Mage::getSingleton('core/session');
/* @var $session Mage_Core_Model_Session */
$review = Mage::getModel('review/review')->setData($data);
/* @var $review Mage_Review_Model_Review */
$validate = $review->validate();
if ($validate === true) {
try {
/****** This is the spot where we are now setting the value to STATUS_APPROVED *******/
$review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE))
->setEntityPkValue($product->getId())
->setStatusId(Mage_Review_Model_Review::STATUS_APPROVED)
->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
->setStoreId(Mage::app()->getStore()->getId())
->setStores(array(Mage::app()->getStore()->getId()))
->save();
foreach ($rating as $ratingId => $optionId) {
Mage::getModel('rating/rating')
->setRatingId($ratingId)
->setReviewId($review->getId())
->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
->addOptionVote($optionId, $product->getId());
}
$review->aggregate();
$session->addSuccess($this->__('Your review has been accepted'));
}
catch (Exception $e) {
$session->setFormData($data);
$session->addError($this->__('Unable to post the review.'));
}
}
else {
$session->setFormData($data);
if (is_array($validate)) {
foreach ($validate as $errorMessage) {
$session->addError($errorMessage);
}
}
else {
$session->addError($this->__('Unable to post the review.'));
}
}
}
// this is my own custom need, feel free to do whatever you want here
$product_url = $product->getUrlPath();
if ($product_url) {
$this->_redirect($product_url);
return;
}
$this->_redirectReferer();
}
}