How to change default sort order / dir in Magento search results?

March 4, 2012  |  6 Comments  |  by Raj (MagePsycho)  |  Latest, Magento

Introduction

Today we will be discussing about how to change the defualt sort order / dir in magento search results (simple & advanced).

Regarding solution, some says you need to change the /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php file in order to change the default sort order field and dir. But you don’t need to do so as there is an extremely easy way to do so.

Suppose say we are changing the default sort order field to ‘name’ and default sort direction to ‘asc’. Here goes the solution:

Changing default sort order / dir in simple search results:

1> Copy the following file to your custom theme folder
app/design/frontend/*/*/template/catalogsearch/form.mini.phtml
2> and insert the following two lines of code in between the

<form></form>

element of form.mini.phtml:

<input type="hidden" name="order" value="name" />
<input type="hidden" name="dir" value="asc" />

3> You’re done

Changing default sort order / dir in advanced search results:

1> Copy the following file to your custom theme folder
app/design/frontend/*/*/template/catalogsearch/advanced/form.phtml
2> and insert the following two lines of code in between the

<form></form>

element of form.phtml:

<input type="hidden" name="order" value="name" />
<input type="hidden" name="dir" value="asc" />

3> You’re done

Sort By Field: 'name', Dir: 'asc'

Hopefully this artice was useful.
Thanks for reading guys.

Converting multi-select field to checkbox in advanced search form of Magento

January 19, 2012  |  3 Comments  |  by Raj (MagePsycho)  |  Latest, Magento, PHP

Introduction:

Have you ever thought of modifying the default multi-select field to checkbox field in advanced search of Magento?
If not then here we will be discussing about how to do which is damn easy and much user friendlier.

Steps:

1> Copy the following file to your working theme:
app/design/frontend/[interface]/[theme]/template/catalogsearch/advanced/form.phtml

2> Open the form.phtml (from above) and find the following line just after the case ‘select’: ?>

<div class="input-box">
	<?php echo $this->getAttributeSelectElement($_attribute) ?>
</div>

and replace it by the following code

<?php if(in_array($_attribute->getAttributeCode(), array('manufacturer'))): ?>
<div class="input-box">
	<?php
		 $options = $_attribute->getSource()->getAllOptions(false);
		 foreach($options as $_option):
			 $isChecked = in_array($_option['value'], $this->getRequest()->getParam($_attribute->getAttributeCode())) ? ' checked="checked"' : null;
			 ?>
	<input type="checkbox" name="<?php echo $_attribute->getAttributeCode(); ?>[]" value="<?php echo $_option['value']; ?>"<?php echo $isChecked; ?> /> <?php echo $_option['label']; ?><br />
	<?php
		 endforeach;
	?>
</div>
<?php else: ?>
<div class="input-box">
	<?php echo $this->getAttributeSelectElement($_attribute); ?>
</div>
<?php endif; ?>

Note: Here we have customized the display for manufacturer attribute, similarly you can customize for other attributes. Just you need to add the attribute code(for example: color) in the array as:

<?php if(in_array($_attribute->getAttributeCode(), array('manufacturer', 'color'))): ?>

3> Try to refresh the advanced search page: http://your-magento-url/catalogsearch/advanced
You will see some good results 🙂

Manufacturer in default format (Before)

Customized Manufacturer Display(After)


Note: You can use some css in order to break the checkboxes in multi-columns for better display.
Hope you liked this article 🙂