3

顧客が製品のレビューを送信すると、レビューは自動的に承認される必要があります。管理者による承認は必要ありません。

4

2 に答える 2

3

このアプローチを試すことができます。

更新: リンクが無効になったため、Web アーカイブからリンクを投稿しました。

于 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 つのフォルダーを作成します コントローラーなどおよびヘルパー ステップ 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 に答える