2012-10-16 47 views

回答

2

产品ID是递增的。通过降序排列并将收集限制为8个,您将拥有8个最后产品。

$collection = Mage::getModel('catalog/product')->getCollection(); 
$collection->getSelect()->order('entity_id desc')->limit(8); 

/* just for testing 
Mage::log($collection->getSelect()->assemble()); 

foreach ($collection as $product) { 
    Mage::log($product->getSku()); 
} */ 

有了你可以做任何你需要的,为了做到这一点,你需要使用该命令的创建日期添加的知名度和地位等过滤

+0

我需要diaplay的是最新的产品的所有细节。怎么样?像价格,图片.... – KarSho

0

集合。键显示所有产品的信息如价格,名称等对我们->addAttributeToSelect('*')下面是脚本:

$store_id = Mage::app()->getStore()->getId(); 
$_products = Mage::getResourceModel('reports/product_collection') 
    ->addStoreFilter($store_id) 
    ->addAttributeToFilter('visibility', 4) 
    ->addAttributeToFilter('status', 1) 
    ->addAttributeToSelect('*') 
    ->setVisibility(array(2,3,4))       
    ->setOrder('created_at', 'desc') 
    ->setPage(1, 9); 
相关问题