Magento 1.4 按类别加载不起作用

发布于 2024-08-29 13:27:06 字数 565 浏览 8 评论 0原文

我编写了一个 Magento 辅助类,它在 1.3 中运行得非常好。然而,我们正在开发 1.4 的新安装,并且由于某种原因按类别过滤将不起作用。

 function __construct()
 {
  Mage::app();
  $this->model = Mage::getModel('catalog/product');
  $this->collection = $this->model->getCollection();
  $this->collection->addAttributeToFilter('status', 1);//enabled
  $this->collection->addAttributeToSelect('*');
 }

 function filterByCategoryID($catID)
 {
  $this->collection->addCategoryFilter(Mage::getModel('catalog/category')->load($catID));
 }

我不明白为什么这在 1.4 中不起作用。还有其他人参与过这个问题吗?

I have a Magento helper class I wrote that works wonderfully in 1.3. However, we're working on a new install of 1.4 and filtering by category won't work for some reason.

 function __construct()
 {
  Mage::app();
  $this->model = Mage::getModel('catalog/product');
  $this->collection = $this->model->getCollection();
  $this->collection->addAttributeToFilter('status', 1);//enabled
  $this->collection->addAttributeToSelect('*');
 }

 function filterByCategoryID($catID)
 {
  $this->collection->addCategoryFilter(Mage::getModel('catalog/category')->load($catID));
 }

I can't figure out why this isn't working in 1.4. Has anyone else come into this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我乃一代侩神 2024-09-05 13:27:06

根据您发布的内容,我的猜测是您的代码中还有其他内容正在向您的集合添加/删除过滤器。我在 1.4 安装上运行了以下代码

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('status', 1)
->addCategoryFilter(Mage::getModel('catalog/category')->load(8))
->addAttributeToSelect('*');

,并且产品集合已按预期进行过滤。

扩展你的问题以显示你如何使用你的助手以及你期望它做什么和它做什么会有所帮助。

Based on what you posted, my guess would be there's something else in your code that's adding/removing filters to/from your collection. I ran the following code on a 1.4 install

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('status', 1)
->addCategoryFilter(Mage::getModel('catalog/category')->load(8))
->addAttributeToSelect('*');

and the product collection was filtered as expected.

Expanding your question to show how you're using your helper and what you expect it to do vs what it does would help.

初吻给了烟 2024-09-05 13:27:06

我能够使用下面的代码让它工作......


函数 __construct()
{
法师::app();
}

function filterByCategoryID($catID)
{
    //$this->collection->addCategoryFilter(Mage::getModel('catalog/category')->load($catID));
    $this->collection = Mage::getModel('catalog/category')->load($catID);

}

<代码>

I was able to get it working with the code below...


function __construct()
{
Mage::app();
}

function filterByCategoryID($catID)
{
    //$this->collection->addCategoryFilter(Mage::getModel('catalog/category')->load($catID));
    $this->collection = Mage::getModel('catalog/category')->load($catID);

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文