简体   繁体   中英

Magento - Listing Bestseller products on a full page loads only 3 products

Trying to loading the Bestsellers, but this script loads me only 3 products, no matter what i do, can anyone give me a hint so i can display at least 16 products?

The problem here is with the $_productCollection = $this->getProductCollection(); function, when i count it, it is receiving only 3 products, how can i change it so i can receivei more products through this function?

<?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; ?>

replaced the $_productCollection = $this->getProductCollection(); function

for this:

$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');

now i am getting all my bestseller products. tks anyway guys

Have you tried re-indexing your product data in order to keep up with the product changes? Magento does a lot of caching and indexing for performance.

Try going into the Admin area, go to System->Index Management and check if any have a red "Reindex Required" status. You'll have to re-index the data by clicking the links next to them, in particular the "Category Products" data.

Checkout XML where you define this block. I guess there is some limit param set or not set, and default is 3. OR you should directly check block which returns you product collection.

In 1.6 I didn't found standard bestsellers block,so it must be some custom module or something like that?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM