2011-12-01 66 views
2

试图加载畅销书,但这个脚本加载了我只有3个产品,不管我做什么,任何人都可以给我一个提示,所以我可以显示至少16产品?Magento - 在整个页面上列出畅销书产品只加载3个产品

这里的问题与$_productCollection = $this->getProductCollection();功能有关,当我算它的时候,它只接收3个产品,我如何改变它,所以我可以通过这个函数接收更多的产品?

<?php 
// You can pass a $totalToFetch parametar to the fetchBestsellers() 
// $_productCollection = $this->fetchBestsellers(5); 
$_productCollection = $this->getProductCollection(); 
?> 






<?php if(!$_productCollection->count()): ?> 

<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p> 
<?php else: ?> 


    <div class="title-list-product"><h1><?php echo $this->__('MAIS VENDIDOS')?></h1></div> 
    <?php // Grid Mode ?> 
    <div class="shadow"> 
    <div class="product-list-detail"> 
        <?php 
    $currentUrl = $this->helper('core/url')->getCurrentUrl(); 
    $baseurl = Mage::app()->getStore()->getBaseUrl(); 
    if ($currentUrl == $baseurl){$break=3;} else {$break=16;} 
    ?> 
    <?php $_columnCount = $this->getColumnCount(); ?> 
    <?php $i=0; foreach ($_productCollection as $_product): ?> 
      <?php if ($i >=$break) break; ?> 
      <?php $_product = $model = Mage::getModel('catalog/product')->load($_product->getId());?> 
     <?php if ($i++%$_columnCount==0): ?> 
     <ul class="products-grid" style="height:auto;"> 
     <?php endif ?> 
      <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif(($i%$_columnCount==0) ||($i==$_collectionSize)): ?> last<?php endif; ?>"> 
       <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(155); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a> 
       <div class="name-sku-price"> 
        <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>)"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></a></h2> 
        <?php $ids = $_product->getCategoryIds(); $cat = Mage::getModel('catalog/category')->load($ids[0]); ?> 
        <span class="sku"><a href="<?php echo $cat->getUrl();?>"><?php echo $cat->getName(); ?></a></span> 
        <?php echo $this->getPriceHtml($_product, true) ?> 

        <?php echo $this->getReviewsSummaryHtml($_product,'short') ?> 

       </div> 
       <!--div class="actions"> 
        <?php if($_product->isSaleable()): ?> 
         <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button> 
        <?php else: ?> 
         <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> 
        <?php endif; ?> 
        <ul class="add-to-links"> 
         <?php if ($this->helper('wishlist')->isAllow()) : ?> 
          <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li> 
         <?php endif; ?> 
         <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?> 
          <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li> 
         <?php endif; ?> 
        </ul> 
       </div--> 
      </li> 
     <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?> 
     </ul> 
     <?php endif ?> 
     <?php endforeach ?> 
     </div> 
     </div> 
<?php endif; ?> 

回答

5

取代$_productCollection = $this->getProductCollection();功能

此:

$visibility = array(
         Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, 
         Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG 
       ); 

$_productCollection = Mage::getResourceModel('reports/product_collection') 
           ->addAttributeToSelect('*') 
           ->addOrderedQty() 
           ->addAttributeToFilter('visibility', $visibility) 
           ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)) 
           ->setOrder('ordered_qty', 'desc'); 

现在我让我所有的畅销产品。 tks无论如何球员

0

您是否尝试过重新索引产品数据以跟上产品变化? Magento为性能做了很多缓存和索引。

尝试进入管理区域,进入系统 - >索引管理,并检查是否有红色的“需要重建索引”状态。您必须通过点击旁边的链接重新为数据编制索引,特别是“类别产品”数据。

+0

嘿莱斯,已经做到了。它甚至没有要求任何reindex(红色状态),但我反正没有改变。但tks的提示。 –

0

签出XML,您可以在其中定义此块。我想有一些限制参数设置或没有设置,默认值是3.或者你应该直接检查返回你产品收集的块。

在1.6我没有找到标准畅销书封锁,所以它必须是一些自定义模块或类似的东西?

+0

我检查了它,而不是XML文件... –

相关问题