Magento随机产品

时间:2012-10-02 13:55:40

标签: magento

您好我使用脚本在我的主页上显示随机产品,但它并没有显示我的价格。哪里有问题?

http://magentoabid.blogspot.sk/2012/06/display-random-products-from-category.html

1 个答案:

答案 0 :(得分:1)

不确定为什么不起作用,但如果你想要尝试其他解决方案

  1. http://dx3webs.com/front/2010/10/how-to-create-a-random-featured-product-list-on-home-page-in-magento/

  2. 更新上面的代码

    将前15行替换为:

    $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
    $collection = Mage::getResourceModel('catalog/product_collection');
    Mage::getModel('catalog/layer')->prepareProductCollection($collection);
    $collection->getSelect()->Limit($this->getNumProducts())->order('rand()');
    $collection->addStoreFilter();
    $collection->addCategoryFilter($category);
    //print_r($collection);
    

    替换:

    <?php for ($i=0; $i < $number_of_products; $i++): ?> 
    

    with:

    <?php foreach($collection as $product) :  ?>  //need to end foreach with <?php endforeach; ?>
    

    替换这样的东西:

    $displayed_products[$random_products[$i]]->getName();
    

    使用:

    $product->getName();
    

    (使用“$ product”查找并替换“$ displayed_products [$ random_products [$ i]]”)

相关问题