尝试加载畅销书,但这个脚本只加载了3个产品,无论我做什么,任何人都可以给我一个提示,这样我就可以显示至少16个产品吗?
问题在于$_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; ?>
答案 0 :(得分: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');
现在我得到了所有畅销产品。无论如何,伙计们
答案 1 :(得分:0)
您是否尝试重新编制产品数据索引以跟上产品变化? Magento为性能做了大量的缓存和索引。
尝试进入管理区域,转到系统 - &gt;索引管理并检查是否有任何红色“需要重新索引”状态。您必须通过单击它们旁边的链接重新索引数据,特别是“类别产品”数据。
答案 2 :(得分:0)
Checkout XML,您可以在其中定义此块。我猜有一些限制参数设置或未设置,默认为3.或者您应该直接检查返回产品集合的块。
在1.6中我没有找到标准畅销书块,所以它必须是一些自定义模块或类似的东西?