当任何客户对产品提交评论时,评论必须自动获得批准。无需管理员批准。
问问题
3492 次
2 回答
3
你可以试试这种方法。
更新:链接不再有效,所以我从网络档案中发布了一个。
于 2012-04-23T12:36:39.413 回答
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();
}
}
于 2014-10-20T20:13:43.003 回答