2014-09-26 105 views
0

开发人员在我的magento网站上创建了一个自定义模块,该模块列出了网页上每个类别中最便宜的产品。Magento产品列表

这很棒,但现在页面太长,添加了额外的内容。我怎样才能将显示的类别数量限制为10,甚至更好 - 到10我可以指定顺序?

换句话说,我想以同样的方式显示所有内容,但将类别数量限制为10,并使用类别ID指定它们的顺序。

这里是原代码:

$helper = Mage::helper('catalog/category'); 
$helperOutput = Mage::helper('catalog/output'); 
$categories = $helper->getStoreCategories('name', true, true); 
?> 
<div class="specials_list"> 
<? 
// Iterate all categories in store 
foreach ($categories as $curr){ 

    // If category is Active 
    if($curr->getIsActive()){ 
     $info = Mage::getModel('catalog/category')->load($curr->getId()); 

     $product = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($info)->addAttributeToSelect('small_image'); 
     $product->addMinimalPrice(); 
     $product->getSelect()->order("price", "ASC")->limit(1); 
     $product->load(); 
     foreach($product as $temp){} 
     $product = $temp; 
     if($product){ 
      ?> 
      <div class="product"> 
       <a href="<?php echo $helper->getCategoryUrl($curr)?>"> 
        <img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(135, 135); ?>" width="135" alt="<?php echo $product->getName() ?>" /> 
        <div class="price">From <span class="amount"><? echo Mage::helper('core')->currency($product->getPrice(),true,false); ?></span></div> 
        <div class="view">View All &gt;&gt;</div> 
        <div class="name"><?php echo strtoupper($curr->getName()); ?></div> 

       </a> 
      </div> 
      <? 
     }   
    } 
} 
?> 
<br class="clear"/> 
</div> 

我试图切片数组,但显然这不是一个正常的数组。也试图使用循环,而不是foreach没有给我带来积极的结果。

你有什么想法来解决这个问题吗?先谢谢你。

回答

0

只需计算您的foreach循环中的行数,并在达到所需数量时退出或继续?