调用方法
showtotal是总共显示多少条数据,category_id是显示某个分类下的产品
$totalPerPage = ($this->show_total) ? $this->show_total : 6;
$counter = 1;
$catalogid = ($this->category_id) ? $this->category_id : 29;
$_featcategory = Mage::getModel('catalog/category')->load($catalogid);
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$storeId= Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addOrderedQty()
->addAttributeToFilter('visibility', $visibility)
->addCategoryFilter($_featcategory)
->setOrder('ordered_qty', 'desc');
核心代码就是最后两句了....通过分类ID来过滤分类,通过订单数量来排序
<?php foreach($_productCollectionas$product): ?>
<?php if($counter<= $totalPerPage): ?>
<?php $productUrl= $product->getProductUrl(); ?>
<a href="<?php echo $productUrl ?>"title="View <?php echo $product->name ?>">
<h4><?php echo$product->name ?></h4>
</a>
<small>已售出: <?php echo(int)$product->ordered_qty ?></small><br />
<a href="<?php echo $productUrl ?>"title="View <?php echo $product->name ?>">
<img src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(120); ?>"alt="Product image" />
</a>
<br />
<?php endif; ?>
<?php endforeach; ?>
还能实现已经售出多少件商品的功能
magento获取某个分类下产品的销售排行
2013年1月15日星期二 Asia/Shanghai下午5:43:05
Posted By