php - Magento - 在整页上列出畅销产品仅加载 3 个产品

标签 php magento

尝试加载畅销书,但此脚本仅加载我 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; ?>

最佳答案

替换了$_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');

现在我得到了所有畅销产品。无论如何,谢谢大家

关于php - Magento - 在整页上列出畅销产品仅加载 3 个产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8348128/

相关文章:

php - REMI 存储库 RPM 已验证或测试?

php - 在 PHP 中使用正则表达式替换空格

magento - 我无法在 Magento 产品页面上找到可配置选项?

php - Magento 永久购物车不工作,不清除购物车项目?

php - 在启用 BLOCK_HTML 缓存的情况下检测 Magento .phtml 中的主页

php - 如何在 PHP 中捕获对对象的任何方法调用?

javascript - 禁用 HTML5 弹出表单验证消息

php - 什么是解析 ajax 成功函数接收到的数据的更清晰/更好的方法?

php - Magento:如何在购物车中获取属性选项名称(代码)而不仅仅是标签和值

php - Magneto 将数据插入 Wordpress wp_users 和 wp_usermeta 表