2012-04-23 18 views

答えて

3

this approachを試すことができます。

UPDATE:リンクは有効ではなくなりました。ウェブアーカイブからリンクを投稿しました。

+0

おかげで –

+0

が、これは、Magentoの1.7上で動作します取り組んでいます をWebFlakeStudio?私は1.7バージョンを使用しているので。それは動作していません。私は他のアプローチを提案できますか? –

+0

@ジョン - そのリンクのために、私はReviewカスタムモジュールをAutoreviewに改名しました。それは私のために働きました。私はMagento 1.8を使用しています。 –

1

新しいモジュールを作成することは、そのシンプルで簡単な最適なアプローチです。 ステップ1:アプリの/ etc /ローカルでDPC ステップ3と呼ばれるフォルダを作成します: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と呼ばれるアプリケーションの/ etc /モジュールにモジュール宣言ファイルを作成しますアプリケーション内/ etc/local/Dpc /新しいフォルダを作成する ステップ3:アプリケーション内で/ 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:アプリ内側:アプリ/コード内部/ローカル/ DPC /レビュー/ヘルパーData.php

と呼ばれるファイル

<?php 
 

 
/** 
 
* Class Dpc_Review_Helper_Data 
 
*/ 
 
class Dpc_Review_Helper_Data extends Mage_Review_Helper_Data 
 
{ 
 

 
}

ステップ6を作成します/ 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(); 
 
    } 
 

 
}

関連する問題