Magento随机产品订单和记忆订单


magento random products order and remembering the order

我想不通。我试图得到一个随机产品的列表,像这样:

$category = Mage::getModel('catalog/category')->load($catId);
$products = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('status',1)
                ->addCategoryFilter($category)
                ->addAttributeToFilter('visibility',array('in' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH))
                ->setPageSize(20)
                ->setCurPage($page);
$products->getSelect()->order(new Zend_Db_Expr('RAND()'));

这段代码工作得很好,但我需要的是记住顺序,所以可以通过ajax调用的页面。

是否有一种方法可以使这种随机性由某种数字控制,如果给定将始终返回相同的行顺序?

我可以想到两个适合你需要的解决方案。

第一个是通过一个唯一产品字段(例如产品ID)的CRC32进行订购。也许值得在表中添加一个新列以加快速度,而不是每次选择时为每行计算字段的CRC32。

第二个建议是添加一个新列,其中为表中的每一行放入一个随机生成的数字。