Magento Collection模型过滤器修改

发布于 2024-09-29 05:52:44 字数 768 浏览 4 评论 0原文

我的两个模块存在冲突,这导致了一个严重的问题,我对后端编程不太熟悉,所以我来这里希望有人可以帮助我。 PS我确实尝试自己解决这个问题至少一两个小时,学到了很多东西,但没有任何足够简单的东西来解决这个问题。

我需要修改以下函数,以便当以类似于下面示例的方式使用它时,它会从集合中排除 id_path 包含字符串“questions”的任何项目。

public function filterByIdPath($idPath)
{
    $this->getSelect()
        ->where('id_path = ?', $idPath);
    return $this;
}

$collection = Mage::getResourceModel('seosuite/core_url_rewrite_collection')
  ->filterAllByProductId($productId)
  ->sortByLength('ASC')
  ->addStoreFilter($storeId, false);
  ->filterByIdPath($idPath)

该函数所在的类是Mage_Core_Model_Mysql4_Url_Rewrite_Collection的扩展版本。如果 id_path 不合适,我们也可以访问 request_path。

以下是 id_paths 的一些示例:product/2/3/questions、product/5/3、category/3、product/3/3/questions。

Two of my modules are conflicting and it's causing a serious issue, I'm not all that familiar with back-end programming so I've come here hoping someone can help me out. P.S. I did try to solve this on my own for at least an hour or two, learned quite a bit but not anything that was straight forward enough to solve this.

I need to modify the following function so that when it is used in a manner similar to the example further below, it excludes from the collection any items where id_path contains the string 'questions'.

public function filterByIdPath($idPath)
{
    $this->getSelect()
        ->where('id_path = ?', $idPath);
    return $this;
}

$collection = Mage::getResourceModel('seosuite/core_url_rewrite_collection')
  ->filterAllByProductId($productId)
  ->sortByLength('ASC')
  ->addStoreFilter($storeId, false);
  ->filterByIdPath($idPath)

The class this function is located in is an extended version of Mage_Core_Model_Mysql4_Url_Rewrite_Collection. We also have access to request_path if id_path is not suitable.

Here are a few examples of id_paths: product/2/3/questions, product/5/3, category/3, product/3/3/questions.

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

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

发布评论

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

评论(1

魂ガ小子 2024-10-06 05:52:44

这是未经测试的。

public function filterByIdPath($idPath)
{
    $this->addFieldToFilter('id_path', array('nlike'=>'%'.$idPath.'%'));
    return $this;
}

“nlike”表示“NOT LIKE”,“%”是通配符。想必您会调用类似 ->filterByIdPath('questions') 的函数

This is untested.

public function filterByIdPath($idPath)
{
    $this->addFieldToFilter('id_path', array('nlike'=>'%'.$idPath.'%'));
    return $this;
}

"nlike" means "NOT LIKE" and "%" is a wildcard. Presumably you would call the function like ->filterByIdPath('questions')

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