How to make Product Spotlight Choose Items Randomly?

Is it possible for the Product Spotlight to choose products randomly? Currently, I have about 10 featured products, and I notice that the Product Spotlight only uses the last 3 items I made featured products instead of randomly selecting from all featured products.

Does anyone here know how to do this?

Thanks

11 answers

Profile photo of JA Developer 0.00 $tone July 16, 2009
Public

Hi there,

I am sorry for my delay.
For your case, please kindly try with my guider:

+ Open app\code\local\JoomlArt\JmProductsSpotlight\Block\ List.php file, at about line 258, find following code:

Code:

 ->where("ea.attribute_code='featured'");

and change to:

Code:

->where("ea.attribute_code='featured'")

->order("rand()");

Hope it helps.

#4
Profile photo of JA Developer 0.00 $tone July 16, 2009
Public

Hi dwpegues,

In this function, find following code:

Code:

$list = $this->getListBestBuyProducts( 'updated_at', 'desc', $product_ids);

and change to:

Code:

$list = $this->getListBestBuyProducts( 'rand()', '', $product_ids);
#7
Profile photo of JA Developer 0.00 $tone July 16, 2009
Public

Hi

I solved this issue to help you.

Please see my code:

Code:

function getListBestBuyProducts($fieldorder='ordered_qty', $order='desc', $product_ids='', $perPage=NULL, $currentPage=1){							
		$list = null;				
		/* 
			Always set de $perPage, by template or by config 
			if $perPage eq 0 (zero) not limit the list
		*/
		if($perPage === NULL) $perPage	= (int) $this->_config['qty'];
		/*
			Show all the product list in the current store
			order by ordered_qty, showing the bestsellers first
		*/
		$storeId = Mage::app()->getStore()->getId();
		$products = Mage::getResourceModel('catalog/product_collection')
					->setStoreId($storeId)
					->addAttributeToSelect('*')
					->addStoreFilter($storeId)
					->setOrder($fieldorder, $order);	
		$products->getSelect()->order('rand()');	
		if ($product_ids) {
			$products->getSelect()->where("e.entity_id in ($product_ids)");
					
		}

		/*
			Filter list of product showing only the active and 
			visible product
		*/
		Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
		Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);

		$products->setPageSize($perPage)->setCurPage($currentPage);
		
		$this->setProductCollection($products);
			
		if (($_products = $this->getProductCollection()) && $_products->getSize()){
			$list = $_products;
		}	
		
		return $list;
	}
#9
Profile photo of Daniel Pegues 0.00 $tone July 16, 2009
Public

There it is… you posted the solution as I wrote my last email. In your post, it does not have the option to ‘Mark Best Answer’

I have checked on my site, and it works perfectly.

By any chance will you sticky this? I am sure there are a lot of others that will want to do this.

Thanks so much again!!!

#11

This question is now closed

Written By

Comments