【问题标题】:Set product reviews auto approve in magento在magento中设置产品评论自动批准
【发布时间】:2012-04-23 11:24:13
【问题描述】:

当任何客户对产品提交评论时,评论必须自动获得批准。无需管理员批准。

【问题讨论】:

    标签: magento review


    【解决方案1】:

    你可以试试this approach

    更新:链接不再有效,所以我发布了来自网络存档的链接。

    【讨论】:

    • 这适用于 Magento 1.7 吗?因为我使用的是 1.7 版本。它不工作。你能建议我任何其他方法吗?
    • @John - 对于该链接,我将 Review 自定义模块重命名为 Autoreview。它对我有用。我正在使用 Magento 1.8。
    • 请在您的答案中包含解决方案,而不仅仅是一个链接。
    • 现在你的链接坏了,你必须总结或做一些事情,而不是仅仅链接。
    • @wordpressure 我发布了一个新链接
    【解决方案2】:

    创建一个新模块是最好的方法,它简单易行。 第一步:在 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 个文件夹 controllers,etc 和 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();
        }
    
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多