2011-06-09 64 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> 

注意。之前=「 - 」和之後=「 - 」是用於將塊定位在結構塊的頂部或底部的命令。