2011-06-09 65 views

回答

13

在您的应用程序/设计/前端/ {your-interface}/{您的主题} /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> 
+0

感谢您的回答,我在left.phtml中添加了新代码并清除了缓存,但它没有显示任何内容,但是有最新的产品。 – Arasu 2011-06-09 07:17:43

+0

我更新了文件app/design/frontend/base/default/template/catalog/navigation/left.phtml – Arasu 2011-06-09 07:22:15

+0

它可以工作,但是我在app/design/frontend/base/default/template/callouts/left_col.phtml中更改了。非常感谢。 – Arasu 2011-06-09 07:36:33

1

这extesnsion是您的需求非常有益的。您可以从以下网址安装该扩展: http://www.magentocommerce.com/magento-connect/mageoutsourcing/extension/6669/bnm

安装后在你的Magento,有点恰克成XML,这有助于在其他左侧显示最畅销的产品。 你应该改变布局的xml:

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <default> 
     <reference name="right"> 
      <block type="bnm/bestsellingproduct" name="bestsellingproduct.sidebar" after="cart_sidebar" template="bnm/bestselling-sidebar.phtml"/>   
     </reference> 
    </default>  
</layout> 

为:前(和)之后 - 这是一个结构块中位置的内容块的方式有两种:

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <default> 
     <reference name="left"> 
      <block type="bnm/bestsellingproduct" name="bestsellingproduct.sidebar" after="-" template="bnm/bestselling-sidebar.phtml"/>   
     </reference> 
    </default>  
</layout> 

注意。之前=“ - ”和之后=“ - ”是用于将块定位在结构块的顶部或底部的命令。