
最新写个magento获取评价的插件,获取全部评价的代码分享下。
如下代码片段如下,仅供参考:
Block中的代码如下
class Hellokeykey_Allreviews_Block_Allreviews extends Mage_Core_Block_Template { protected $_collection; protected function _construct() { $this->_collection = Mage::getModel('review/review')->getProductCollection(); $this->_collection ->addStoreFilter(Mage::app()->getStore()->getId()) //->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId()) ->addStatusFilter(1) //const STATUS_APPROVED = 1; ->setDateOrder(); } // add by lee public function getReviewsSummaryHtml(Mage_Catalog_Model_Product $product, $templateType = false, $displayIfNoReviews = false) { return $this->getLayout()->createBlock('rating/entity_detailed') ->setEntityId($this->getProduct()->getId()) ->toHtml() . $this->getLayout()->getBlock('product_review_list.count') ->assign('count', $this->getReviewsCollection()->getSize()) ->toHtml() ; } /** * Gets collection items count * * @return int */ public function count() { return $this->_collection->getSize(); } /** * Get html code for toolbar * * @return string */ public function getToolbarHtml() { return $this->getChildHtml('toolbar'); } /** * Initializes toolbar * * @return Mage_Core_Block_Abstract */ protected function _prepareLayout() { $toolbar = $this->getLayout()->createBlock('page/html_pager', 'customer_review_list.toolbar') ->setCollection($this->getCollection()); $this->setChild('toolbar', $toolbar); return parent::_prepareLayout(); } /** * Get collection * * @return Mage_Review_Model_Resource_Review_Product_Collection */ protected function _getCollection() { return $this->_collection; } /** * Get collection * * @return Mage_Review_Model_Resource_Review_Product_Collection */ public function getCollection() { return $this->_getCollection(); } /** * Get product link * * @return string */ public function getProductReviewLink() { return Mage::getUrl('review/product/list/id/'); } /** * Format date in short format * * @param $date * @return string */ public function dateFormat($date) { return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM); } protected function _beforeToHtml() { $this->_getCollection() ->load() ->addReviewSummary(); return parent::_beforeToHtml(); } }
上面代码来自核心代码的修改,注意的地方就是去掉用户筛选出状态是通过的评价
maegnto模板文件中输出,模板文件中的代码如下
<?php if( $this->getCollection() && $this->count()): ?> <?php echo $this->getToolbarHtml() ?> <table class="data-table" id="my-reviews-table"> <col width="1" /> <col width="210" /> <col width="1" /> <col /> <tbody> <?php foreach ($this->getCollection() as $_review): ?> <?php $_product = Mage::getModel('catalog/product')->load($_review->getEntityPkValue()); $storeId = Mage::app()->getStore()->getId(); //$reviewsCount = Mage::getModel('review/review')->getTotalReviews($_review->getEntityPkValue(), true , $storeId); ?> <tr> <td> <P><strong><?php echo $_review->getNickname(); ?></strong></P> <span class="nobr"><?php echo $this->dateFormat($_review->getReviewCreatedAt()); ?></span> </td> <td> <a href="<?php echo $_product->getProductUrl(); ?>" target="_blank"><?php echo $this->htmlEscape($_review->getName()) ?></a> <img src="<?php echo $_product->getImageUrl() ?>" /> </td> <td> <?php if($_review->getSum()): ?> <div class="rating-box"> <div class="rating" style="width:<?php echo ( $_review->getSum() / $_review->getCount() ) ?>%;"></div> </div> <a href="<?php echo $this->getProductReviewLink() ?>id/<?php echo $_review->getEntityPkValue() ?>" target="_blank"><?php echo $_review->getCount() ?> <?php echo $this->__('reviews') ?></a> <?php endif; ?> </td> <td><?php echo $this->helper('review')->getDetailHtml($_review->getDetail()) ?></td> </tr> <?php endforeach; ?> </tbody> </table> <script type="text/javascript">decorateTable('my-reviews-table')</script> <?php echo $this->getToolbarHtml() ?> <?php else: ?> <p><?php echo $this->__('You have submitted no reviews.') ?></p> <?php endif; ?>
此为magento 1.7.2.0测试代码,不建议用于生产环境。大家根据自己magento版本和经验适当修改。
转载标明出处:www.hellokeykey.com
我想让客户在评论那里上传自己的图片,在magento里面怎么实现呢?求解答。。。
找个插件,或者找人开发
我做到一半了呢, 现在的问题是图片路径不能保存到数据库, 因为不知道保存到数据库的sql语句在哪里 真是头疼!!评论这块的结构你是不是很清楚呢??