【发布时间】:2014-07-04 11:38:54
【问题描述】:
我的主要类别页面上有一个自定义登录页面,我想在其中显示使用集合的 9 种产品的随机选择。当我的类别设置如下所示时,主类别锚是是,子类别是否,它可以正常工作并显示随机的 9 个产品
Main category A - anchor Yes
- sub category 1 - anchor No
- sub category 2 - anchor No
- sub category 3 - anchor No
但我现在需要切换它,将主类别设置为 NO,将子类别设置为锚点是的,什么都没有显示,并且集合是空的
Main category A - anchor No
- sub category 1 - anchor Yes
- sub category 2 - anchor Yes
- sub category 3 - anchor Yes
我的代码是:
$_category = $this->getCurrentCategory();
$collection = $_category->getProductCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 9;
$collection->setPage(1, $numProducts)->load();
foreach($collection as $product) {
// display...
集合代码不能以这种方式工作是否有原因?
【问题讨论】:
-
做 var_dump($_category->getId()) 并分享结果
标签: magento collections anchor categories