Datafeedr Support Forums

Datafeedr Support Forums (/index.php)
-   Tips, Tricks & Tutorials (/forumdisplay.php?f=66)
-   -   Add a category drop down menu to the Advanced Search (/showthread.php?t=7879)

Eric October 8th, 2012 03:35 PM

Add a category drop down menu to the Advanced Search
 
Here's how to add a drop down menu with your categories to the Advanced Search widget.

1. Go here: The Factory > Your Store > VIEWS > WIDGETS > Advanced Search

2. Delete the Text module that already is in the view.

3. Add a new Category list module to the view.

4. Add the following code to the Category list module:

HTML Code:

[search.form]
<div class="store_search_form">

        <p class="keyword"><label for="word">Keyword</label> [search.word]</p>
       
        <p class="merchant"><label for="merchant">Merchant</label> [search.merchant]</p>
       
        <p class="tag"><label for="tags">Tags</label> [search.tags]</p>
       
        <p class="price"><label for="price">Price</label> [search.selectprice options='any, cheap(-5), $5 - $10, $10 - $20, more than 20 (20+)']</p>
       
        <p class="category">
                <label for="category">Category</label>
                <select name="c">
                        [category.list before='' after='']
                                <option value="[category.id]"><?php echo str_repeat ('-', (($depth-1)*2) ); ?> &nbsp; [category.name]</option>
                                [category.repeat]
                        [/category.list]
                </select>
        </p>
       
        <p class="button">[search.submit title='Find it!']</p>
       
</div>
[/search.form]

5. Save.

After you click the [Update Settings Only] button on your site, your Advanced Search widget will now have a drop down menu containing your categories.

Eric

connepon October 28th, 2012 04:10 AM

Store ID: 16iizsa3ku6mhoje
Website URL: http://www.paardenlifestyle.com/store

Hi Eric,

thanks for posting that. It has been a bit quiet in my shop the last two weeks; I'd figured I had to contact the merchants and try to make sure they fill out brand and the appropriate tag, because it has been a lot of work for me. So I'm in the middle of doing that. I did make a bit of money in last month (almost €200!). I think that's quite good since I only started in september. I'm doing very well in Google, but that's probably because I have a blog attached to it.

Anyway, my question. I have a drop down for merchant and brand which works great. Now I was wondering how to include the dropdown menu for categories since my drop down code is a bit different and I'm not using the widget (since I attach specific ID's to the filters).

The code I have it as follows (for the page http://www.paardenlifestyle.com/stor.../bovenkleding/ )



HTML:

<form method="get">
<p style="font-family: Play; font-size: 18px; margin-bottom: 10px;">Selecteer merk</p><select name="brand">
<?php echo dfr_get_brands('991838,991938,992029,992447'); ?>
</select>

<p style="font-family: Play; font-size: 18px; margin-bottom: 10px; margin-top: 10px;">Selecteer webshop</p><select name="merchant_id">
<?php echo dfr_get_merchants('991838,991938,992029,992447'); ?>
</select>
<p style="margin-bottom: 20px;"></p>
<input type="submit" value="Zoeken" />

</form>



functions.php :

function dfr_get_brands($cat=false) {
global $wpdb;
if ($cat) { $cat_query = "WHERE p2c.cat_id IN (".$cat.") "; }
$brands = $wpdb->get_results("
SELECT brand, p2c.cat_id
FROM ".$wpdb->prefix."dfr_shop_products AS p
INNER JOIN ".$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id
$cat_query
GROUP BY brand
");
$html = '<option value="">Alle merken</option>';
foreach ($brands as $brands) {
if (trim($brands->brand) != "") {
$selected = (strip_tags(stripslashes($_GET['brand']))==$brands->brand) ? ' selected="selected"' : '';
$html .= '<option value="'.$brands->brand.'"'.$selected.'>'.$brands->brand.'</option>';
}
}
return $html;
}

function dfr_get_merchants($cat=false) {
global $wpdb;
if ($cat) { $cat_query = "WHERE p2c.cat_id IN (".$cat.") "; }
$merchants = $wpdb->get_results("
SELECT merchant, merchant_id, p2c.cat_id
FROM ".$wpdb->prefix."dfr_shop_products AS p
INNER JOIN ".$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id
$cat_query
GROUP BY merchant
");
$html = '<option value="">Alle webshops</option>';
foreach ($merchants as $k => $v) {
if (trim($v->merchant) != "") {
$selected = (strip_tags($_GET['merchant_id'])==$v->merchant_id) ? ' selected="selected"' : '';
$html .= '<option value="'.$v->merchant_id.'"'.$selected.'>'.$v->merchant.'</option>';
}
}
return $html;
}

How do I add the dropdown for categories? I'm assuming I have to fill out the ID's for the categories I want to show up in the filter for certain pages? In this example I would only want to show the categories from the IDs 991838, 991938, 992029 and 992447.

When I simply add the code you've shown to the HTML (the category filter), it doesn't show the categories, just an empty dropdown.

I hope you can help me out :) Thanks in advance!

Best regards,

Conny

Eric October 28th, 2012 09:32 AM

Hi Conny,

Congrats on your success. To add a category drop down with those 4 categories to your form, you should change your form to something like this:

HTML Code:

<form method="get">
<p style="font-family: Play; font-size: 18px; margin-bottom: 10px;">Selecteer merk</p><select name="brand">
<?php echo dfr_get_brands('991838,991938,992029,992447'); ?>
</select>

<p style="font-family: Play; font-size: 18px; margin-bottom: 10px; margin-top: 10px;">Selecteer webshop</p><select name="merchant_id">
<?php echo dfr_get_merchants('991838,991938,992029,992447'); ?>
</select>

<p style="font-family: Play; font-size: 18px; margin-bottom: 10px;">Category</p><select name="c">
        <option value="991838">Jassen</option>
        <option value="991938">Bodywarmers</option>
        <option value="992029">Vesten1</option>
        <option value="992447">Shirts1</option>
</select>

<p style="margin-bottom: 20px;"></p>
<input type="submit" value="Zoeken" />

</form>

Eric

connepon October 28th, 2012 10:11 AM

wow that worked great!!

I'm now redesigning the pages to make the filters next to each other, but wordpress keeps adding line breaks. Anyway, thanks for your quick reply!!!!


All times are GMT -5. The time now is 01:01 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.