Datafeedr Support Forums

Datafeedr Support Forums (http://www.datafeedr.com/forums/index.php)
-   Tips, Tricks & Tutorials (http://www.datafeedr.com/forums/forumdisplay.php?f=66)
-   -   Category specific Dropdown filters (http://www.datafeedr.com/forums/showthread.php?t=7241)

camseo July 3rd, 2012 07:23 AM

Category specific Dropdown filters
 
Hi Everyone / Eric

My first post. I have 100 or so sites built in WP (feed uploads and manipulation nowhere near as good /easy as dfR) and Affilistore (no longer supported). DatafeedR seems like it could be a real timesaver:)

Awesome tool applying it to a couple of sites fairtrade-fashion.co.uk and cheapbarbecue.co.uk.

I have implemented the category specific brand filter found in another thread (thanks Eric) - works great...however, i'd like it to be as a dropdown as some categories have 30 or 40 brands which is too long. So how can I make this list code into dropdown code?!?

//add to view//

Code:

<ul>
<?php
$brands = dfr_get_brands($category->id);
foreach ($brands as $brand) {
    if ($brand != "") {
    $brand = urlencode($brand);
    ?>
    <li><a href="[server.url type='fullpage' query='brand=$brand']"><?php echo urldecode($brand); ?></a></li>
  <?php } ?>
<?php } ?>
</ul>


//add to function.php//

Code:

function dfr_get_brands($cat=false) {
    global $wpdb;
    if ($cat) { $cat_query = "WHERE cat_id = ".$cat." "; }
    $brands = $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products ".$cat_query."GROUP BY brand");
    $list = array();
    foreach ($brands as $brands) {
        $list[] = $brands->brand;
    }
    return $list;
}

Thanks very much

James

Eric July 3rd, 2012 09:43 AM

Hi James,

Welcome to the forums!

I've posted how to do dropdown menus for merchants and brands here: http://www.datafeedr.com/forums/showthread.php?t=6778

Eric

camseo July 3rd, 2012 10:58 AM

Hopefully not a stupid question!
 
Have reviewed other post re dropdowns - will this give me a dropdown menu with brands specific to category A, category B etc or is this a dropdwon where ALL brands are displayed?

james

Eric July 3rd, 2012 11:04 AM

Hi

It will get you all brands so you'll need to modify the query like you've done above.

Eric

camseo July 3rd, 2012 02:59 PM

Cheers
 
Ok sorted. TX

marksperl August 28th, 2012 03:50 PM

Im getting duplication or variance of brand names on the drop down. Is there any way to correct that, or is that due to the merchant's feed

ex.
Spy
Spy Optics
Spy Sunglasses

Eric August 28th, 2012 03:51 PM

Hi

It's due to the merchant's feed. You can change the product's brand in the Factory but if you have lots of products, that could take some time.

Eric

connepon September 15th, 2012 05:28 AM

Hi,

I tried getting the category specific drop down filter, but it didn't work out. I'm not experienced with this. I tried the following code:

in functions:

function dfr_get_brands($cat=false) {
global $wpdb;
if ($cat) { $cat_query = "WHERE cat_id = ".$cat." "; }
$brands = $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products ".$cat_query."GROUP BY brand");
$html = '<option value="">Select a brand</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;
}

in view:

<form method="get">

<!-- Brand drop down select menu -->
<select name="brand">
<?php echo dfr_get_brands($category->id); ?>
</select>


</select>

<input type="submit" value="Go" />

</form>

I'm still getting all the brands in the shop. Eventually, I want to add merchant and price filter. But first I need to figure out how I get it working for brands. Could you tell me what I'm doing wrong?

Thanks in advance!

Eric September 15th, 2012 07:36 AM

Hi

Your code works for me. I do see you have an extra closing </select> tag.

Make sure you don't cache your view.

Eric

connepon September 15th, 2012 07:58 AM

Thanks for your quick response. The filter shows and it works, however, it also shows brands that are nog in that specific category.

EDIT: for example on this page: http://www.paardenlifestyle.com/stor...eken/stoffen1/

Eric September 15th, 2012 08:02 AM

Did you turn off caching for that view?

connepon September 15th, 2012 08:17 AM

I pressed on "clear cache" so I guess that should do

Eric September 15th, 2012 08:19 AM

Hi

You should disable caching the View where your <select> form is. Go to the View menu > View Properties and check the "don't cache this view" checkbox.

Also, make sure you don't have any other function named dfr_get_brands in your functions.php file.

Eric

connepon September 15th, 2012 08:42 AM

Thanks again for the quick reply; that's just amazing :) I checked the "don't cache this view" and had a look at the functions.php file. However, it still doesn't work...

This is the only code I have in my functions.php:

<?php
require_once (TEMPLATEPATH . '/framework/main.php');

// loclization
$lang = TEMPLATE_PATH . '/lang';
load_theme_textdomain('theme', $lang);
load_theme_textdomain('framework', $lang);


function dfr_get_brands($cat=false) {
global $wpdb;
if ($cat) { $cat_query = "WHERE cat_id = ".$cat." "; }
$brands = $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products ".$cat_query."GROUP BY brand");
$html = '<option value="">Select a brand</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;
}

?>

Eric September 15th, 2012 08:52 AM

Hi

I still see the "Don't cache this view" unchecked here: http://factory3.datafeedr.com/feeder/view?view=224338

Eric

connepon September 15th, 2012 10:56 AM

ah I thought you meant the category page view. Well, I've checked the "don't cache this view" but it seems not be working. I've updated products and settings, but no changes?

Anything else I should do/try?

Eric September 15th, 2012 11:08 AM

Hi

It seems you are referencing the wrong widget from your Category Page view. You are referencing: [DFR:widget/drop-down-filter]. That view is empty.

You should be referencing "Category specific brand drop down".

Eric

connepon September 15th, 2012 11:19 AM

Not on the category page view "stoffen1" ?

Eric September 15th, 2012 11:25 AM

Hi

Try replacing this:
Code:

[DFR:widget/category-specific-brand-drop-down]
With this:
HTML Code:

<form method="get">
 
  <!-- Brand drop down select menu -->
  <select name="brand">
    <?php echo dfr_get_brands($category->id); ?>
  </select>
 
  <input type="submit" value="Go" />
 
</form>

Eric

connepon September 15th, 2012 11:55 AM

I replaced it, but now it doesn't show any brand:

http://www.paardenlifestyle.com/stor...eken/stoffen1/


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

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