2

I have been bit of trouble trying to figure this out.

Essentially on homepage I'm trying to to pull 3 products from 4 different categories.

Category 1
- Product 1
- Product 2
- Product 3

Category 2
- Product 1
- Product 2
- Product 3

Category 3
- Product 1
- Product 2
- Product 3

Category 4
- Product 1
- Product 2
- Product 3

I'll be using jquery/css to make a tabbed component like first example here: http://refills.bourbon.io/

I'm having a real difficult time figuring out how to loop through though.

1
  • Are you talking about a rotation of products - you want to be able to rotate the products? – Rebel Feb 24 '17 at 23:43
0

try below code

<?php
$categories = array(1,2,3,4);
$category = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('entity_id', array('in'=>$categories));
?>
<ul class="accordion-tabs">
<?php
foreach($category as $cat) { ?>
    <li class="tab-header-and-content">
        <a href="javascript:void(0)" class="is-active tab-link"><?php  echo $cat->getName() ?></a>
        <div class="tab-content">
            <?php
            $products = Mage::getModel('catalog/category')->load($cat->getId())
                ->getProductCollection()
                ->addAttributeToSelect('*') 
                ->addAttributeToFilter('status', 1)
                ->getSelect()->limit(3);

            foreach($products as $product)
            {
                echo $product->getName()."</br>";
                echo $product->getFinalPrice()."</br>";
            }
            ?>
        </div>
    </li>

<?php } ?>
</ul>
2
  • this seems to be working but for some reason the price isn't rendering. I'm supposed to use <?php echo $this->getPriceHtml($_product, true); ?> right? – kkyang Mar 9 '17 at 18:23
  • @kkyang find updated answer and if you find this answer helpful then upvote it and mark it as accept to close the question – Gopal Patel Mar 9 '17 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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