Monday 22 September 2014

magento product collection with specific id


magento product collection with specific id

    $productIds = array(1,3,2);
    $products = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter('entity_id', array('in' => $productIds));

Tuesday 2 September 2014

Magento Product Collection random in limit


 <?php
                            $c=0;
                            $category = Mage::getModel('catalog/category')->load(3);//3 is category id where we assign the products for men
                            $products = Mage::getModel('catalog/product')->getCollection()
                            ->addCategoryFilter($category);
                           
                            $products->addAttributeToSelect('*');
                           
                            $products->getSelect()->order('RAND()');
                            $products->getSelect()->limit(5);//to show only three products randomly
                           
                            $total = $products->count();
                            foreach ($products as $_product) {
                                $c++; ?>
                            <li class="item <?php if($total== $c){ echo "last"; }?>">
                                <a href="<?php echo $_product->getProductUrl() ?>">
                                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(375,281)?>" alt="" />
                                </a>
                                <?php echo $_product->getName() ?>
                               
                                <div class="price-box">
                                        <span class="regular-price" >
                                            <span class="price"><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();?> <?php echo number_format($_product->getPrice(),2);?></span>
                                        </span>
                                </div>
                               
                               
                            </li>
                            <?php } ?>