0

Well, I am working on my first Magento website. I am using Magento 1.9.2 & lunxury theme 1.2.X

I am trying to add products in left navigation bar manually.

What I have done so far

In my app\design\frontend\mgstheme\luxury\template\mgs\mpanel\template\category-navigation.phtml File I put this code.

<?php
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
?>


<ul id="content-navigation">
       <?php echo $_menu ?>
        <li>
            <ul>
              <?php foreach ($products as $_product) { ?>
                    <li><?php echo $_product->getName(); ?></li>
                <?php } ?>
            </ul>
        </li>
    </ul>

for now, its printing all products but I want all products under their category name.

I am attaching screenshot for reference here jemmy proof lock to cupboard are the categories and after that its loading all products enter image description here enter image description here

5
  • pls check my answer : you need to pass category id for the specific category product Commented Oct 21, 2016 at 10:24
  • do i writing code in correct file? because its printing product after completion of my category list
    – parish
    Commented Oct 21, 2016 at 10:32
  • check where to come $_menu and there you need to change as i told you. Commented Oct 21, 2016 at 10:35
  • I guess \app\code\core\Mage\Catalog\Block\navigation.php this file may have code... Help me to editing it
    – parish
    Commented Oct 21, 2016 at 10:43
  • You need to override this block into one custom extension. In that you have to create menu like you want, means currently it return only category but you need to do code for adding product into list with category. Commented Oct 21, 2016 at 13:59

1 Answer 1

-1

Try this:

$_product = Mage::getModel('catalog/category')->load($category_id)
 ->getProductCollection()
 ->addAttributeToSelect('*')
 ->addAttributeToFilter('status', 1) // enabled
 ->addAttributeToFilter('visibility', 4) //visibility in catalog,search
 ->setOrder('price', 'ASC'); //sets the order by price
2
  • So if there are X categories on the page, you plan on loading X times a category model, and X times a collection of products? This will destroy the page load time. Commented Oct 21, 2016 at 10:36
  • @Mayers if you have any good idea then pls help to parish. Commented Oct 21, 2016 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.