当我给出类别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>
在管理面板它显示模块激活..但我没有找到正确的网址来运行模型文件.. 我需要为此创建一个视图文件?
谁能帮助我在此......如果有这种错误,请注明他们..提前
感谢
对不起..在主文件中,它是正确的。你可以通过在URL中仅提供产品ID来告诉我通过这个查询上述评级模型的网址吗? – 2013-02-20 04:30:36