2010-10-28 64 views
0

我的两个模块是冲突的,这是一个严重的问题,我不是那么熟悉后端编程,所以我来这里希望有人能帮助我。附:我确实试图自己解决这个问题至少一两个小时,学到了很多东西,但没有足够的东西来解决这个问题。Magento Collection模型过滤器修改

我需要修改以下函数,以便当它以类似于下面的示例的方式使用时,它将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。

回答

0

这是未经测试的。

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

“nlike”的意思是“不喜欢”,“%”是通配符。大概你会打电话的功能,如->filterByIdPath('questions')