Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Questions
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 1st, 2011, 08:18 PM
meperez meperez is offline
 
Join Date: Mar 2011
Posts: 43
Default Dynamic Generation of Brand Filter

www.thekitchentool.com
Store Id: 30751

Hi Eric,

I have some hard-coded brand filters on each category and I'm trying to generate those dynamically so that I don't have to worry about them getting out of sync with the products. Based on other posts I saw, I gave it an initial try... and clearly my syntax is erroneous somewhere as the Brand Filter no longer shows up. I'm trying it on the Woks category under Cookware. Can you please help?

I added the following function to my functions.php:

//Function to Get Brands of Woks Category
function dfr_get_brands() {
global $wpdb;
$merchants = $wpdb->get_results("SELECT DISTINCT p.brand FROM ".$wpdb->prefix."dfr_shop_products p, ".$wpdb->prefix."wp_dfr_shop_p2c pc, ".$wpdb->prefix."wp_dfr_shop_cats c AND pc.cat_id = c.id AND c.name = \'Woks\' ORDER BY c.name, p.brand");
$list = array();
foreach ($brands as $brands) {
$list[$brands->brand] = $brands->brand;
}
return $list;
}

Then to the filter Widget, I added:

<div>
<form method="get">
<span>
<?php echo datafeedr_tools()->form_select("brand",
array(
"" => "All Brands",
?>
<?php
$brands = dfr_get_brands();
foreach ($brands as $brandname) {
echo '\"'$brandname'\" => \"'$brandname'\",';
}
?>
));
<input type="submit" value="Go" />
</span>
</form>
</div>

My goal is to generate the following code, for example:

<div>
<form method="get">
<span>
<?php echo datafeedr_tools()->form_select("brand",
array(
"" => "All Brands",
"All-Clad" => "All-Clad",
"Anolon" => "Anolon",
"Calphalon" => "Calphalon",
"Circulon" => "Circulon",
"Cuisinart" => "Cuisinart",
"Le Creuset" => "Le Creuset",
"West Bend" => "West Bend"
)); ?>
<input type="submit" value="Go" />
</span>
</form>
</div>
  #2  
Old May 1st, 2011, 08:21 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

You can't perform a foreach() loop inside the form_select() function call. You'll just have to create the <select> drop down box using your own HTML code and not the form_select() function.

Eric
  #3  
Old May 1st, 2011, 10:08 PM
meperez meperez is offline
 
Join Date: Mar 2011
Posts: 43
Default

Thanks, is there any other way you can think of to enable some sort of dynamic list?
  #4  
Old May 2nd, 2011, 08:39 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Something like this should work:

HTML Code:
<?php
//Function to Get Brands
function dfr_get_brands() {
	global $wpdb;
	$merchants = $wpdb->get_results("SELECT DISTINCT p.brand FROM ".$wpdb->prefix."dfr_shop_products p, ".$wpdb->prefix."wp_dfr_shop_p2c pc, ".$wpdb->prefix."wp_dfr_shop_cats c AND pc.cat_id = c.id AND c.name = \'Woks\' ORDER BY c.name, p.brand");
	$html = '';
	foreach ($brands as $brands) {
		$html .= '<option value="'.$brands->brand.'">'.$brands->brand.'</option>';
	}
	return $html;
}
?>





<!-- code for your vuew -->
<form method="get">
	<span>
		<?php echo dfr_get_brands(); ?>
		<input type="submit" value="Go" />
	</span>
</form>
  #5  
Old May 2nd, 2011, 10:18 PM
meperez meperez is offline
 
Join Date: Mar 2011
Posts: 43
Default

Thanks Eric, I tried putting all of that code in the view and received the following error:

Warning: Invalid argument supplied for foreach() in /home/content/69/7529569/html/wp-content/plugins/datafeedr/datafeedr.php(1981) : eval()'d code on line 8

I also tried putting the function in functions.php after removing the php beginning and ending markers and then the bottom view code alone in the view but I then received a parse error.

Thanks
  #6  
Old May 3rd, 2011, 08:08 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by meperez View Post
Thanks Eric, I tried putting all of that code in the view and received the following error:
The function is supposed to go in your theme's functions.php file and the html code is supposed to go into your view.
  #7  
Old May 4th, 2011, 11:50 PM
meperez meperez is offline
 
Join Date: Mar 2011
Posts: 43
Default

Yes, I also tried putting the function in functions.php after removing the php beginning and ending markers and then the bottom view code alone in the view but I then received a parse error.

Thanks,
Melissa
  #8  
Old May 5th, 2011, 08:58 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

I think your query is completely wrong. I did this and it worked:

Code for theme's functions.php file:
PHP Code:
function dfr_get_brands() {
    global 
$wpdb;
    
$brands $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products GROUP BY brand");
    
$html '';
    foreach (
$brands as $brands) {
        
$html .= '<option value="'.$brands->brand.'">'.$brands->brand.'</option>';
    }
    return 
$html;

Code for your view:
HTML Code:
<form method="get">
	<select name="brand">
		<?php echo dfr_get_brands(); ?>
		<input type="submit" value="Go" />
	</select>
</form>
  #9  
Old May 14th, 2011, 08:05 AM
fashion fashion is offline
 
Join Date: May 2011
Posts: 24
Default

Im a bit confused, where did you put this code?
  #10  
Old May 14th, 2011, 08:47 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by fashion View Post
Im a bit confused, where did you put this code?
The function dfr_get_brands() { ... } goes in your theme's functions.php file.
The other HTML code goes in one of your Views.
  #11  
Old August 17th, 2011, 10:29 PM
digitalatom digitalatom is offline
 
Join Date: Jul 2011
Posts: 11
Default

Help please - I have just pasted The function dfr_get_brands() { ... } goes in your theme's functions.php file. (I assume you meant the wordpress theme)

and... HTTP Error 500 (Internal Server Error) - really not sure what to do - HELPP
  #12  
Old August 18th, 2011, 08:58 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Sounds like you either didn't paste the whole thing or you pasted outside of the opening/closing php tags (ie. <?php ... ?>)
  #13  
Old August 18th, 2011, 10:16 AM
digitalatom digitalatom is offline
 
Join Date: Jul 2011
Posts: 11
Default

Hi Eric,

The code I pasted in was:
function dfr_get_brands() {
global $wpdb;
$brands = $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products GROUP BY brand");
$html = '';
foreach ($brands as $brands) {
$html .= '<option value="'.$brands->brand.'">'.$brands->brand.'</option>';
}
return $html;
}

How do I now get the site back live - as I cant login to my wordpress theme

www.designerlabeldeals.co.uk

Any help to get it back up and running would be really appreciated

Thanks
  #14  
Old August 18th, 2011, 10:18 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

The first step to getting your site back online is to remove all of the code your pasted into your functions.php file and save it again. Then you will be able to log back into your site.
  #15  
Old August 18th, 2011, 10:26 AM
digitalatom digitalatom is offline
 
Join Date: Jul 2011
Posts: 11
Default

Hi Eric - fortunately my son has just arrived back and got the site live again - doing exactly what you just suggested.

Many thanks
  #16  
Old January 17th, 2012, 03:01 PM
meinehandtasche meinehandtasche is offline
 
Join Date: Jul 2011
Posts: 43
Default

Store ID: 32722
Website URL: http://www.meinehandtasche.de/
URL to page in question: http://www.meinehandtasche.de/store/


Hi Eric,

I copied this code into the functions.php of my wordpress theme (lifestyle from studiopress):

Quote:
<?php
//Function to Get Brands
function dfr_get_brands() {
global $wpdb;
$merchants = $wpdb->get_results("SELECT DISTINCT p.brand FROM ".$wpdb->prefix."dfr_shop_products p, ".$wpdb->prefix."wp_dfr_shop_p2c pc, ".$wpdb->prefix."wp_dfr_shop_cats c AND pc.cat_id = c.id AND c.name = \'Woks\' ORDER BY c.name, p.brand");
$html = '';
foreach ($brands as $brands) {
$html .= '<option value="'.$brands->brand.'">'.$brands->brand.'</option>';
}
return $html;
}
?>
and I copied this code into a new view category widget within the datafeedr factory:

Quote:

<!-- code for your vuew -->
<form method="get">
<span>
<?php echo dfr_get_brands(); ?>
<input type="submit" value="Go" />
</span>
</form>
but it doesn't look like it should. Please scroll down on this page
http://www.meinehandtasche.de/store
and you can see the black list of words under the header "MARKEN".

I don't have a clue actually what this list is showing. The result should look like under the header "MARKEN FILTER".

Do you have any idea what went wrong?

Thanks,
Oliver
  #17  
Old January 17th, 2012, 03:13 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by meinehandtasche View Post
Do you have any idea what went wrong?
I don't think you copied the code correctly. The code you need in your functions.php file is in post #8.

Also, it looks like the correct code for your view is this:
HTML Code:
<form method="get">
	<select name="brand">
		<?php echo dfr_get_brands(); ?>
		<input type="submit" value="Go" />
	</select>
</form>
Eric
  #18  
Old January 17th, 2012, 03:42 PM
meinehandtasche meinehandtasche is offline
 
Join Date: Jul 2011
Posts: 43
Default

Store ID: 32722
Website URL: http://www.meinehandtasche.de/
URL to page in question: http://www.meinehandtasche.de/store/


Thank you Eric! :-) Now the drop down shows all brands.

Is there a way to manage which brands should show up in the drop down?

Additionally the brands show up in different style (some capital letter some small etc.).

Thanks,
Oliver
  #19  
Old January 17th, 2012, 03:55 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi
Quote:
Originally Posted by meinehandtasche View Post
Is there a way to manage which brands should show up in the drop down?
Not without modifying the query and adding WHERE NOT IN() exceptions.

Quote:
Originally Posted by meinehandtasche View Post
Additionally the brands show up in different style (some capital letter some small etc.).
That's how the merchant's have entered the brand names. You could control that with CSS or PHP.
  #20  
Old January 17th, 2012, 04:29 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Here's an example of how to remove brands from the list. I've removed 'Adidas' and 'Atlas'. This example also shows how to capitalize the first letter in each word of the brand.
PHP Code:
function dfr_get_brands() {
    global 
$wpdb;
    
$brands $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products 
    WHERE brand NOT IN('Adidas','Atlas') 
    GROUP BY brand"
);
    
$html '';
    foreach (
$brands as $brands) {
        
$html .= '<option value="'.$brands->brand.'">'.ucwords($brands->brand).'</option>';
    }
    return 
$html;

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merchant and Brand filter Widgets Nugerama Tips, Tricks & Tutorials 13 March 7th, 2012 05:01 PM
Brand Filter Drop-Down with All Brands option meperez Questions 8 March 26th, 2011 12:04 AM
Brand Filter = Brands Only show when in Category macfink Questions 3 March 25th, 2011 12:55 PM
Drop down Menu from filter by Brand macfink Questions 4 March 25th, 2011 09:32 AM
Brand filter? sylviathewitch Problems 3 March 8th, 2011 08:43 AM


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


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