在您的 app/design/frontend/{your-interface}/{your-theme}/template/catalog/navigation/left.phtml 中,为最新产品添加以下代码:
<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4))
->setOrder('created_at', 'desc')
->setPage(1, 5);
?>
<h2>Latest Products</h2>
<ul>
<?php foreach($_productCollection as $_product) : ?>
<li><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
评分最高的产品有点复杂。使用以下代码:
<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4));
$_productCollection->joinField('rating_summary', 'review/review_aggregate', 'rating_summary', 'entity_pk_value=entity_id', array('entity_type' => 1, 'store_id' => Mage::app()->getStore()->getId()), 'left');
$_productCollection->setOrder('rating_summary', 'desc');
$_productCollection->setPage(1, 5);
?>
<h2>Latest Products</h2>
<ul>
<?php foreach($_productCollection as $_product) : ?>
<li><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
不确定你所说的最好的产品是什么意思,但如果是畅销产品,这里是代码:
<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4));
$select = $_productCollection->getSelect();
$sqlSelectColumns = $select->getPart('columns');
$sqlSelectColumns[] = array(
'',
new Zend_Db_Expr('(
SELECT SUM(order_item.qty_invoiced - order_item.qty_refunded)
FROM ' . Mage::getSingleton('core/resource')->getTableName('sales/order_item') . ' AS order_item
WHERE order_item.product_id = e.entity_id)
'),
'ordered_qty'
);
$select->setPart('columns', $sqlSelectColumns);
$_productCollection->setOrder('ordered_qty', 'desc');
$_productCollection->setPage(1, 5);
?>
<h2>Top Selling Products</h2>
<ul>
<?php foreach($_productCollection as $_product) : ?>
<li><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></li>
<?php endforeach; ?>
</ul>