Display magento products by category ID

后端 未结 4 1191
滥情空心
滥情空心 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:49

    get Product from specific category

    $categoryIds = array(2,4);//category id
    
    $collection = Mage::getModel('catalog/product')
                                 ->getCollection()
                                 ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                                 ->addAttributeToSelect('*')
                                 ->addAttributeToFilter('category_id', array('in' => $categoryIds))
    

    get Product for specific product id

    $productids = array(52,62);//product ids
    $collection = Mage::getResourceModel('catalog/product_collection');
    $collection->addFieldToFilter('entity_id',array( 'in' => $productids));
    

    then write this in phtml

    count() ?>
        getColumnCount(); ?>
        
            
            
    • <?php echo $product->getName()?>

      getName() ?>

      currency($product->getPrice(),true,false);?>
      isSaleable()): ?>

      __('Out of stock') ?>

    hope this help you

提交回复
热议问题