Display magento products by category ID

后端 未结 4 1177
滥情空心
滥情空心 2020-12-16 08:24

I need to know how can I display products in a page like (cart, below total) only few products by ID. Eg: products with id 2,3,4 and 5.

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 08:55

    // print_r($productslist)
     $category_id = 14; // if you know static category then enter number
    
    $catagory_model = Mage::getModel('catalog/category')->load($category_id); 
    
    $collection = Mage::getResourceModel('catalog/product_collection');
    
    $collection->addCategoryFilter($catagory_model); //category filter
    
    $collection->addAttributeToFilter('status',1); //only enabled product
    
    $collection->addAttributeToSelect(array('name','url','small_image')); //add product attribute to be fetched
    
    //$collection->getSelect()->order('rand()'); //uncomment to get products in random order     
    
    $collection->addStoreFilter();          
    
    if(!empty($collection))
    
    {
    
            foreach ($collection as $_product):?>
    
                 
    
     

提交回复
热议问题