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)
-   -   Merchant and Brand filter Widgets (http://www.datafeedr.com/forums/showthread.php?t=4244)

Nugerama March 29th, 2011 01:59 PM

Merchant and Brand filter Widgets
 
Hi, I just installed and began using Datafeedr today an flippin' love it, I wonder though if you can help me with this little issue.

I've playing about with the widgets and it's all been made very easy to set up but I wonder if there's a way of having the Merchant and Brand filters automatically populated according to the products that are in my store in the same was as the Category one is?

I see how the widget is edited manually but I'd like to be able to hand this over to my client when it's all done knowing that those widgets will stay up to date, let's say if she adds a merchant to the store, without me having to log in and edit the widget.

Thanks very much for you time
Kev

Eric March 29th, 2011 02:21 PM

Hi Kev,

You could always add a couple of queries and add those to theme's functions.php file. But, there might be way more merchants and or brands than you might anticipate:

Here's one that could work for your merchants. You can do the same thing for brands.

PHP Code:

function dfr_get_merchants() {
    global 
$wpdb;
    
$merchants $wpdb->get_results("SELECT merchant FROM ".$wpdb->prefix."dfr_shop_products GROUP BY merchant");
    
$list = array();
    foreach (
$merchants as $merchants)
        
$list[] = $merchants->merchant;
    return 
$list;


Then you could add something like this in your views:

PHP Code:

<?php
$merchants 
dfr_get_merchants();
foreach (
$merchants as $merchant) {
    echo 
'<li><a href="[server.url type=\'fullpage\' query=\''.$merchant).'\']">'.$merchant).'</a></li>';
}
?>

You might need to tweak that to meet your needs but it should get you in the ballpark.

Eric

Nugerama March 31st, 2011 01:27 PM

Hi Eric, this has almost got it, the function works great and the I'm getting an automatically generate list of merchants. The links however don't work and I can't figure out why. Could you take a look please at the 'Stores' widget on my home page and give advise me on fixing it so that these links are interpreted correctly.

My dev site can be found at www.hersuits.co.uk/dev

Many thanks
Kev

Eric March 31st, 2011 01:38 PM

Try this:
PHP Code:

<?php
$merchants 
dfr_get_merchants();
foreach (
$merchants as $merchant) {
    echo 
"<li><a href=\"[server.url type='fullpage' query='$merchant']\">$merchant</a></li>";
}
?>


Nugerama March 31st, 2011 01:57 PM

Hi Eric. Sadly, that's not done it. In fact it stops outputting the buttons at all.

If I add some dots either side of the variables I get the buttons back but still not tracing out the link correctly. I've left it as echo "<li><a href=\"[server.url type='fullpage' query='.$merchant.']\">.$merchant.</a></li>"; for you to have a look at. www.hersuits.co.uk/dev

Thanks
Kev

Eric March 31st, 2011 02:17 PM

OK, I figured out the issue. Try this:
PHP Code:

<ul>
<?php
$merchants 
dfr_get_merchants();
foreach (
$merchants as $merchant) { 
    
$merchant urlencode($merchant);
    
?>
    <li><a href="[server.url type='fullpage' query='merchant=$merchant']"><?php echo urldecode($merchant); ?></a></li>
<?php ?>
</ul>


Nugerama March 31st, 2011 02:52 PM

Aces!!! That's done it, thanks again Eric.

wildstyles February 20th, 2012 07:50 AM

Store ID: 36187
Website URL: http://www.thewildstyles.com
URL to page in question: http://www.thewildstyles.com/store/category/clothing/

Hi there,
This piece of code works really good. I've managed to pull all my brands from the database with this code.
I've used the code from ""Creating Filters" post to put the list in a dropdown..
See the code:

<?php if (@$_GET['brand']) { ?>

<h6><a href="[server.url type='fullpage' query='-brand']">[X] Remove your choice "[store.get param="brand"]"</a></h6>

<?php } else { ?>

<form method="get">
<select name="brand" onchange='this.form.submit()'>
<?php
$brands = dfr_get_brands();
foreach ($brands as $brand) {
$brand = urlencode($brand);
?>

<option value="<?php echo urldecode($brand); ?>"<?php if (@$_GET['brand']) {echo ' selected="selected"';}?>><?php echo urldecode($brand); ?></option>

<?php } ?>
</select>
</form>

<?php } ?>


Now my issue is that when I have other filters on (merchant, etc) and I choose a different brand, it erases all the other filters and goes to the brand page.. While all other filters don't have that issue, you can add and remove as many as you want without overriding anything.
So Im sure I've made some errors in the code, I'm not an expert unfortunately. Could either of you help me out with this?

Thanks in advance.
Ivar Zuidhoek.

Eric February 20th, 2012 10:30 AM

Hi

You'll need to pass those parameters along in your <form>. So, between <form> and </form> you can add something like this:

HTML Code:

<?php if (@$_GET['merchant']){ echo "<input type='hidden' name='merchant' value='".strip_tags($_GET['merchant'])."' />"; } ?>
Eric

wildstyles February 20th, 2012 11:02 AM

hey Eric,

thanks for your fast response. really appreciate it.

however when I included that line inbetween <form> and </form> what happened is that when I selected a brand, then an merchant, then remove the brand, I couldn't pick another brand..

maybe it easier to see for yourself, you can see the filters @ work here:

http://www.thewildstyles.com/store/category/clothing/

Eric February 20th, 2012 11:31 AM

Hi

You need to put the above code within the <form> tags but not between the <select> tags. It should appear immediately after the <form> tag and just before the <select> tag.

Eric

wildstyles February 20th, 2012 12:18 PM

works like a charm. brilliant. thank you so much.

wildstyles March 7th, 2012 03:54 PM

Store ID: 36187
Website URL: http://www.thewildstyles.com
URL to page in question: http://www.thewildstyles.com/store/category/clothing/

I have another question about this piece of code.
It works great.

However I'm gonna have a few main categories later on, like Clothing, Music, Accesoires..
I only wanna draw the brands from articles I add to the clothing category..
Is that possible?

Eric March 7th, 2012 05:01 PM

Hi

You could modify the query like this:

PHP Code:

function dfr_get_merchants() { 
    global 
$wpdb
    
$merchants $wpdb->get_results("SELECT merchant FROM ".$wpdb->prefix."dfr_shop_products WHERE cat_id = 670426 GROUP BY merchant"); 
    
$list = array(); 
    foreach (
$merchants as $merchants
        
$list[] = $merchants->merchant
    return 
$list


Replace 670426 with the Category ID you want to pull products from.

Eric


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

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