I have Varien_Db_Select object with some joins and I need to change condition in one of them. How can I do this?

update: I found that condition in "from" part and then in "joinCondition" part. I can loop through, but I can't put them back

3 Answers 3


So this is what I came up with:

$fromAndJoins = $select->getPart(Zend_Db_Select::FROM);
foreach($fromAndJoins as $key=>$joins){
            $newcondition = //change $joins['joinCondition'] as you want


Here is the method I would use.

You can get the conditions ("where" part) like this:

$where = $collection->getSelect()->getPart('where');

Then you can loop through the conditions like this:

foreach ($where as $key => $condition)
// Do what you need

Finally once you've made the changes you needed, don't forget to apply the updated condition to your colllection:

$collection->getSelect()->setPart('where', $where);

If you get the error

You cannot define a correlation name 'xxx' more than once

you have to unset($fromAndJoins[$key]); item, where the key was in my case

$key = $attribute->getAttributeCode().'_idx.attribute_id';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.