2013-02-19 33 views
0

當我給出類別ID並且結果應該是JSON格式時,我想要獲得產品的評級(超出magento)。我想在瀏覽器頁面中獲取JSON數據。爲此,我擴展了位於app/code/core/mage/Rating/Model/Rating.php的Rating.php運行擴展評級功能的URL可以是什麼

根據inchoo網站,我剛剛將模型文件複製並粘貼到app/code/local/mynamespace/appname/Model/Rating.php。我在app/code/local/mynamespace/appname/etc/config.xml中創建了一個config.xml文件,並在應用程序/ etc/modules中創建了一個xml文件。

在他們告訴添加'var_dump(get_class($ this))行的網站中;出口();'在所需的功能。但我嘗試的URL多​​種途徑獲得收視率,但是沒有用......的文件是爲folows:

Rating.php在應用程序/代碼/本地/ myNameSpace對象

<?php 

class mnamespace_appname_Model_Rating extends Mage_Core_Model_Abstract 
{ 
    /** 
    * rating entity codes 
    * 
    */ 
    const ENTITY_PRODUCT_CODE   = 'product'; 
    const ENTITY_PRODUCT_REVIEW_CODE = 'product_review'; 
    const ENTITY_REVIEW_CODE   = 'review'; 

    /** 
    * Define resource model 
    * 
    * @return void 
    */ 
    protected function _construct() 
    { 
     $this->_init('rating/rating'); 
    } 

    public function addOptionVote($optionId, $entityPkValue) 
    { 
     Mage::getModel('rating/rating_option')->setOptionId($optionId) 
      ->setRatingId($this->getId()) 
      ->setReviewId($this->getReviewId()) 
      ->setEntityPkValue($entityPkValue) 
      ->addVote(); 
     return $this; 
    } 

    public function updateOptionVote($optionId) 
    { 
     Mage::getModel('rating/rating_option')->setOptionId($optionId) 
      ->setVoteId($this->getVoteId()) 
      ->setReviewId($this->getReviewId()) 
      ->setDoUpdate(1) 
      ->addVote(); 
     return $this; 
    } 

    /** 
    * retrieve rating options 
    * 
    * @return array 
    */ 
    public function getOptions() 

    { 
     if ($options = $this->getData('options')) { 
      return $options; 
     } 
     elseif ($id = $this->getId()) { 
      return Mage::getResourceModel('rating/rating_option_collection') 
       ->addRatingFilter($id) 
       ->setPositionOrder() 
       ->load() 
       ->getItems(); 
     } 
     return array(); 

    } 


    public function getEntitySummary($entityPkValue, $onlyForCurrentStore = true) 
    { 
     $this->setEntityPkValue($entityPkValue); 
     return $this->_getResource()->getEntitySummary($this, $onlyForCurrentStore); 
    } 

    public function getReviewSummary($reviewId, $onlyForCurrentStore = true) 
    { 
     $this->setReviewId($reviewId); 
     return json_encode($this->_getResource()->getReviewSummary($this, $onlyForCurrentStore)); 
    var_dump(get_class($this)); //these are the lines added specially 
    exit();      //these two lines(upline also) 
    } 

    /** 
    * Get rating entity type id by code 
    * 
    * @param string $entityCode 
    * @return int 
    */ 
    public function getEntityIdByCode($entityCode) 
    { 
     return $this->getResource()->getEntityIdByCode($entityCode); 
    } 
} 

config.xml文件/Appname/etc/cnfig.xml在app/etc/modules中

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Mynamespace_Appname> 
      <version>0.1</version> 
     </Mynamespace_Appname> 
    </modules> 
    <global> 
     <models> 
      <Appname> 
       <rewrite> 
        <item>Mynamespace_Appname_Model_Rating</item> 
       </rewrite> 
      </Appname> 
     </models> 
    </global> 
</config> 

文件/ Mynamespace_Appname.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Mynamespace_Appname> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Mynamespace_Appname> 
    </modules> 
</config> 

在管理面板它顯示模塊激活..但我沒有找到正確的網址來運行模型文件.. 我需要爲此創建一個視圖文件?

誰能幫助我在此......如果有這種錯誤,請註明他們..提前

感謝

回答

0

更改您的類名:class Mynamespace_Appname_Model_Rating

製作確保你的文件路徑也匹配的情況下(即myname與我的名字)

+0

對不起..在主文件中,它是正確的。你可以通過在URL中僅提供產品ID來告訴我通過這個查詢上述評級模型的網址嗎? – 2013-02-20 04:30:36