本文介绍了Magento随机产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用脚本在首页上显示随机产品,但没有显示价格.哪里有问题?

Hi I use a script for showing random products on my homepage, but it doesnt show me price. Where is a problem?

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

推荐答案

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

Not sure why that isn't working, but if you want you try some other solutions

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

更新上面的代码

用以下内容替换前15行:

Replace the first ~15 lines with:

$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++): ?>

与:

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

替换这样的东西:

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

使用:

$product->getName();

((将"$ displayed_products [$ random_products [$ i]]"替换为"$ product")

(find and replace "$displayed_products[$random_products[$i]]" with "$product")

这篇关于Magento随机产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多