Magento清空数据库log和var缓存文件脚本

magento清空log与var脚本
magento清空log与var脚本

Magento的数据库,用久了,很多log表会变的非常巨大,数据库体积也越来越大,这会严重影响到数据库的运行。

此脚本可以自动清空数据库log表。如果你的log表有用,可以按照实际情况修改此脚本。

将文件上传至你的magento文件根目录,然后用如下地址执行清空命令:

清空数据库log表:http://你网站的网址/clear-magento.php?clean=log

清空magento缓存文件:http://你网站的网址/clear-magento.php?clean=var

如果你的数据库log表比较大,那么使用如上命令清log可能会失败,或者用去很长时间,你可以手动清空,在脚本代码中的log表有:

‘dataflow_batch_export’,
‘dataflow_batch_import’,
‘log_customer’,
‘log_quote’,
‘log_summary’,
‘log_summary_type’,
‘log_url’,
‘log_url_info’,
‘log_visitor’,
‘log_visitor_info’,
‘log_visitor_online’,
‘index_event’,
‘report_event’,
‘report_compared_product_index’,
‘report_viewed_product_index’,
‘catalog_compare_item’,
‘catalogindex_aggregation’,
‘catalogindex_aggregation_tag’,
‘catalogindex_aggregation_to_tag’,
‘catalogsearch_query’,
‘catalogsearch_fulltext’,
‘catalogsearch_result’

清空var缓存文件一般不会花费太多时间,缓存文件在脚本中路径分别为:

继续阅读“Magento清空数据库log和var缓存文件脚本”

获取magento全部商品评价reviews

magento-all-reviews
magento-all-reviews

最新写个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版本和经验适当修改。

继续阅读“获取magento全部商品评价reviews”