开发者

Magento Collection Model Filter Modification

开发者 https://www.devze.com 2023-01-23 01:52 出处:网络
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 thi

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 belo开发者_开发技巧w, 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.


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')

0

精彩评论

暂无评论...
验证码 换一张
取 消