【问题标题】:Magento - Collection empty if category anchor set to noMagento - 如果类别锚设置为 no,则集合为空
【发布时间】: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


【解决方案1】:

anchor 类型表示主类别显示子类别中的所有子类别 在您的情况下,您应该获得所有子类别,然后才能获得随机产品

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    相关资源
    最近更新 更多