是的,它是可能的,但你要在運行問題,當您嘗試應用過濾器(如按價格從低到高等排序)
我認爲更好的方法是按日期進行隨機這樣每個人在特定的一天都會得到相同的產品訂單。
下面是我用來從標籤頁面中的特定類別隨機顯示產品的僞代碼示例。 (你可以改變$seed
來完成你想要的)
public function _getProductCollection()
{
if(is_null($this->_productCollection)) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$seed = $this->getCategoryId() . date("W");
$this->_productCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($this->_productCollection);
$this->_productCollection->getSelect()->order("rand($seed)");
$this->_productCollection->addStoreFilter();
$this->_productCollection->addCategoryFilter($category);
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection);
}
return $this->_productCollection;
}
謝謝你,原諒我的瘋狂響應延遲 - 你的答案逃過了我莫名其妙! :S你能告訴我哪些文件(S)我應該修改和哪些部分爲了得到這個工作?該過濾器功能(即按價格從低到高排序等)不是我們反正用的東西,所以它目前並不對我們那麼重要。 –
請看'Mage_Catalog_Block_Product_List'中的'_getProductCollection'(/app/code/core/Mage/Catalog/Block/Product/List.php) –
您應該也可以使用觀察者查看'catalog_block_product_list_collection' –