How to get products from a particular category in magento ecommerce

后端 未结 6 1330
广开言路
广开言路 2020-12-05 11:50

I\'d like to get a list of random products from the same category as the current product for displaying within the product view - so far all I\'ve dug up is

Magento

6条回答
  •  盖世英雄少女心
    2020-12-05 12:47

    This code will helps you to get products from category id 2. And also here uses a template file list_home.phtml for the product listing.

     echo $this->getLayout()->createBlock("catalog/product_list")
        ->setCategoryId(2)->setTemplate("catalog/product/list_home.phtml")->toHtml();
    

    list_home.phtml

    getChild('toolbar')->setCurrentMode('list'); //uses list mode
    $_productCollection = $this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
        ?>
    
        count()): ?>
            

    __('There are no products matching the selection.') ?>

    --use code for listing---

提交回复
热议问题