Randomize Collection In magento <?php $_model = Mage::getModel('catalog/category'); // Using the "catalog/navigation" Block Classes, we can invoke the getStoreCategories() method to get all Store Cats. $storeId = Mage::app()->getStore()->getId(); $_categories = Mage::getModel('catalog/category') ->getCollection() ->addAttributeToSelect('*') ->addIsActiveFilter() ->addLevelFilter(2) ->setStoreId($storeId); $_categories->getSelect()->order(new Zend_Db_Expr('RAND()')); $new="";$new2=""; // We'll loop through the returned Category Object foreach( $_categories as $_category ) { //this gives random order of products }
<?php $obj = new Mage_Catalog_Block_Navigation(); $store_cats = $obj -> getStoreCategories (); $current_cat = $obj -> getCurrentCategory (); $current_cat = ( is_object ( $current_cat ) ? $current_cat -> getName () : '' ); foreach ( $store_cats as $cat ) { if ( $cat -> getName () == $current_cat ) { echo '<li><a href="' . $this -> getCategoryUrl ( $cat ) . '">' . $cat -> getName () . "</a> \n <ul> \n " ; foreach ( $obj -> getCurrentChildCategories () as $subcat ) { echo '<li><a href="' . $this -> getCategoryUrl ( $subcat ) . '">' . $subcat -> getName () . "</a></li> \n " ; } echo "</ul> \n </li> \n " ; } else { echo '<li><a href="' . $this -> getCategoryUrl ( $cat ) . '">' . $cat -> getName () . "</a></li> \n...
Comments
Post a Comment