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/

Eric September 15th, 2012 11:59 AM

Hi

Can you change the HTML to this (below), load the page and copy any of the <pre>formatted text and paste it here?

HTML Code:

<pre><?php print_r($category); ?></pre>

<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>


connepon September 15th, 2012 04:11 PM

Hi there,

This is the text I get:

stdClass Object
(
[id] => 999838
[parent] => 992506
[typ] => 0
[name] => stoffen1
[path] => dames/rijbroeken/stoffen1
[slug] => stoffen1

=>
[thumbnail] =>
[description] =>
[keywords] =>
[pc] => 138
[pct] => 138
[legacy_id] => dames_rijbroeken_stoffen1
[site_link] => store/category/dames/rijbroeken/stoffen1/
[visible] => 1
[children] => Array
(
)

)

Eric September 15th, 2012 04:21 PM

Hi

This means the products appearing in this category are already in another category and the query will need to use a JOIN on the p2c table.

Eric

connepon September 15th, 2012 04:44 PM

uhmm... say what?

Eric September 15th, 2012 05:11 PM

Try this function:
PHP Code:

function dfr_get_brands($cat=false) {
    global 
$wpdb;
    if (
$cat) { $cat_query "WHERE p2c.cat_id = ".$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="">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;



connepon September 16th, 2012 12:42 PM

wow!!!!!!! it works!!! Thank you sooo much!

I guess it is also possible to add functions for merchant, tag and price filter in the way the code above has been set up? I will give that a try :)

Once again, thank you!

connepon September 20th, 2012 05:29 AM

One additional question...

In some categories, it doesn't show the brands and merchants, because I added the products to the subcategory and not the parent category. To overcome this problem, I want to add the category ids to the code in the view page. However, I can't seem to get multiple id's in a proper way. I use the following code for 1 ID, but I also want to add the ID's "994434", "994435" and "994436." How should I implement that?

<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($cat_ids='994433'); ?>
</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($category_id='994433'); ?>
</select>
<p style="margin-bottom: 20px;"></p>
<input type="submit" value="Zoeken" />

</form>

Thanks in advance!!

EDIT: this is for the page "Veiligheid" which can be seen at: http://www.paardenlifestyle.com/stor...es/veiligheid/

Eric September 20th, 2012 09:04 AM

Hi

You need to use MySQL's IN().

WHERE p2c.cat_id IN(994434,994435,994436)

Eric

connepon September 20th, 2012 04:05 PM

Hi Erik,

thanks for you reply. Where do I add the line of code? I've tried adding it in the view page on several ways, but now it keeps breaking up. I'm sorry I'm not experienced with this, so I'm just trying to sort it out.

Eric September 20th, 2012 04:54 PM

Are you passing 1 or more than 1 category IDs into the dfr_get_brands() function?

connepon September 21st, 2012 02:14 AM

The "parent category" is called "Veiligheid" and has ID 992504. That category is empty, because the products are in the subcategories: 994433, 994434, 994435 and 994436. I want to show the products from the subcategories on the page Veiligheid (in the dropdown filter).

So I started with the following code, which shows the products from 994433 on the page Veiligheid. However, I want to show 34, 35 and 36 as well. I've added the line you've suggested and placed it on several ways, but that didn't work. I'm sure I'm doing something wrong, so I was hoping you could tell me how to change the code below.


<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($cat_id='994433'); ?>
</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($cat_id='994433'); ?>
</select>
<p style="margin-bottom: 20px;"></p>
<input type="submit" value="Zoeken" />

</form>

Eric September 21st, 2012 09:44 AM

Hi

You can do this in your view:

HTML Code:

<?php echo dfr_get_brands('994433,994434,994435,994436'); ?>
And this in your function:

PHP Code:

if ($cat) { $cat_query "WHERE p2c.cat_id IN (".$cat.") "; } 

That should query brands from multiple categories.

Eric

connepon September 25th, 2012 09:21 AM

Yeah it works! Thanks!!!!!! :)!!


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

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