Popular Posts

Sorry. No data so far.

Archives

Tutorial: Adding Search to Your Store

Greetings users, we are back again with another helpful tutorial to make your FoxyPress store better than it was before!  Today’s tutorial will go over adding a search form to your store and how to customize the results of that search.

With the assumption that you’ve installed FoxyPress and have a few products in your inventory, you will want to then decide where to put your search form. We put the FoxyPress Demo store search in the top left above the categories.  This will all depend on your store’s layout and how you’d like it to look.

Once you’ve decided on this, we can create our search form.  Below is code we’ve used, but feel free to customize to your needs:

<form name="foxypress_search_form" id="foxypress_search_form" method="POST">
	<input class="search_box" type="text" id="foxy_search_term" name="foxy_search_term" value="" />
	<input class="search_icon" type="submit" id="foxy_search_submit" name="foxy_search_submit" value="" />
</form>

The one attribute that you might want to set is the action=”" for where you want your form to post back to. We post back to the same page that we are on, which contains the same code for determining which products to display and I will provide in a moment, so this could be a dedicated search results page if you wanted. Feel free to customize as you see fit.

<?php 
	if(isset($_POST['foxy_search_submit'])){
		$products = foxypress_SearchProducts($_POST['foxy_search_term']);
	}else if(get('cat_id')==""){
		$products = foxypress_GetProducts();
	}else{
		$products = foxypress_GetProductsByCategory(get('cat_id'));
	}
?>    

As you can see, the foxypress_SearchProducts() function is being called and an array of $products is being created. You can view our API page to see what is all passed back or simply print_r($products) if you want to see the structure. This allows you to easily customize how your search results page should print out.

Please don’t hesitate to contact us through our live chat, forum, or email if you have any questions about this tutorial or FoxyPress in general.  Don’t forget to “Like” our Facebook fan page or follow us on Twitter as well so you can stay up to date with the latest FoxyPress information and updates.


Leave a Reply