Skip to main content

Randomize Collection In magento

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
}

Comments

Popular posts from this blog

Is covid virus really airborne?

  If airborne transmission is a significant factor in the pandemic, especially in crowded spaces with poor ventilation, the consequences for containment will be significant. How did the experts reach this conclusion? Reviewing existing research, the six experts from the UK, US and Canada identified 10 streams of evidence that collectively support the hypothesis that SARS-CoV-2 primarily transmits through the airborne route. 1. Super-spreading events account for substantial SARS-CoV-2 transmission. Indeed, the authors wrote, such events may be the  pandemic ’s primary drivers. Detailed analyses of human behaviours and other variables in concerts, cruise ships etc have shown patterns “consistent with airborne spread of SARS-CoV-2 that cannot be adequately explained by droplets or fomites”, they wrote. 2. Long-range transmission of SARS-CoV-2 between people in adjacent rooms has been documented in quarantine hotels, but never in each other’s presence. 3. Asymptomatic or pre-sympt...

How to display Image in grid

Write this code in Grid.php:- $this->addColumn("data", array( "header" => Mage::helper("userdesign")->__("Design"), "index" => "image", 'align'     =>'center', 'renderer'  => 'userdesign/Adminhtml_Userdesign_Renderer_Image' )); Then make a "Renderer" folder in module( location - Grid.php) In Renderer Make a PHP file , Named Image.php and put this code <?php class Userdesign_Userdesign_Block_Adminhtml_Userdesign_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{           public function render(Varien_Object $row)     { $designUrl=Mage::getBaseUrl('web').'design/designs/';         $html = '<img width="75" height="75" ';          $value = $row->getData('designId');       $html.= 'src="' . Mage::getBaseUrl('web')....