In catalogsearch/block/advanced/form.php , I guess this function retrieve search string, then user can modify the search he made previously (user can see the previously selected option).

public function getAttributeValue($attribute, $part = null)
    $value = $this->getRequest()->getQuery($attribute->getAttributeCode());
    if ($part && $value) {
        if (isset($value[$part])) {
            $value = $value[$part];
        } else {
            $value = '';

    return $value;

I found many tutorial on how to add Search By Category in Advanced Search Form like this tutorial

But can not find one that give explicit example on how to retrieve the previously selected category when user modify the search.

Can someone help to do this ?


It's not the expected solution, but it's possible to get url parameters

$category = $this->getRequest()->getQuery('category');

And then in the option tag, check if url parameter is equal to option value

<option <?php if($category == $_category->getId()){echo 'selected';}?> value="<?php echo $_category->getId(); ?>">
     <?php echo $_category->getName();?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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