简体   繁体   English

Magento Collection模型过滤器修改

[英]Magento Collection Model Filter Modification

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. 我的两个模块相互冲突,这引起了一个严重的问题,我对后端编程并不那么熟悉,所以我来这里是希望有人能帮助我。 PS 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. PS,我确实尝试过至少一两个小时来自己解决此问题,虽然学到了不少知识,但没有任何直接解决问题的方法。

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'. 我需要修改以下函数,以便在以与下面的示例类似的方式使用它时,它从集合中排除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)

The class this function is located in is an extended version of Mage_Core_Model_Mysql4_Url_Rewrite_Collection. 该函数所在的类是Mage_Core_Model_Mysql4_Url_Rewrite_Collection的扩展版本。 We also have access to request_path if id_path is not suitable. 如果id_path不适合,我们也可以访问request_path。

Here are a few examples of id_paths: product/2/3/questions, product/5/3, category/3, product/3/3/questions. 以下是id_paths的一些示例:product / 2/3 / questions,product / 5/3,category / 3,product / 3/3 / 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. “ nlike”表示“不喜欢”,“%”是通配符。 Presumably you would call the function like ->filterByIdPath('questions') 大概您会调用->filterByIdPath('questions')类的函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM