Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Problems
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 April 30th, 2012, 12:33 AM
fsuggest fsuggest is offline
 
Join Date: Apr 2012
Posts: 45
Default Search showing merchant id instead of merchant name

Hey,

I was following the post at http://www.datafeedr.com/forums/showthread.php?t=6778 to display brands and merchants in a drop down.

I realize that the merchant ID is being used to gather the information but was wondering what would be the code to insert in my search page to display the merchant's name instead of the id number. Right now I have:

Code:
<?php if (@$_GET['merchant_id']){ ?><li><b>Merchant: </b>[store.get param="merchant_id"]</li><?php } ?>
Have also tried:

Code:
<?php if (@$_GET['merchant_id']){ ?><li><b>Merchant: </b>[store.get param="merchant"]</li><?php } ?>
but get a blank after "Merchant:"

Any suggestions?

Store ID: 37285
Website URL: www.FriendsSuggest.com

Thank you.
  #2  
Old April 30th, 2012, 08:22 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

We don't recommend the merchant name because with merchant names you have to take into consideration punctuation like apostrophes and quotes and all of that needs to be escaped. Merchant IDs are much less prone to errors.

Eric
  #3  
Old May 1st, 2012, 02:19 PM
fsuggest fsuggest is offline
 
Join Date: Apr 2012
Posts: 45
Default

Hey Eric,

I agree the id is less prone to error. What I was hoping for is to give the merchants name when someone does a search on my site. For example, where it displays what was searched for:

Description: jeans
Brand: Guess
Merchant: Amazon (instead of a id number as the name is more descriptive for the user)

Thank you.
  #4  
Old May 1st, 2012, 02:21 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

Then you'll want to change your code to this:

<?php if (@$_GET['merchant']){ ?><li><b>Merchant: </b>[store.get param="merchant"]</li><?php } ?>

Eric
  #5  
Old May 10th, 2012, 10:36 AM
fsuggest fsuggest is offline
 
Join Date: Apr 2012
Posts: 45
Default

Hey Eric,

Was hoping for your clarification.

I currently have this code generating a drop down of my merchants in my theme's function.php file:

Code:
function dfr_get_merchants_dropdown() {
    global $wpdb;
    $merchants = $wpdb->get_results("SELECT merchant, merchant_id FROM ".$wpdb->prefix."dfr_shop_products GROUP BY merchant");
    $html = '<option value="">All stores</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;
}
The code in my widget is:

Code:
  <p class="merchant">
    <label for="merchant">Store</label>
    <select name="merchant_id" style="width: 195px;" value=''>
      <?php echo dfr_get_merchants_dropdown(); ?>
    </select>
  </p>
And the code in my search results page is:

Code:
<?php if (@$_GET['merchant_id']){ ?><li><b>Merchant: </b>[store.get param="merchant_id"]</li><?php } ?>
If I was to switch the following line in the functions.php file:

Code:
$html .= '<option value="'.$v->merchant_id.'"'.$selected.'>'.$v->merchant.'</option>';
to

Code:
$html .= '<option value="'.$v->merchant.'"'.$selected.'>'.$v->merchant.'</option>';
Then change the widget code to:

Code:
  <p class="merchant">
    <label for="merchant">Store</label>
    <select name="merchant" style="width: 195px;" value=''>
      <?php echo dfr_get_merchants_dropdown(); ?>
    </select>
  </p>
And search results page code to:

Code:
<?php if (@$_GET['merchant']){ ?><li><b>Merchant: </b>[store.get param="merchant"]</li><?php } ?>
Would that cause any problems? As you mentioned before, I wouldn't want punctuations in the merchants name to mess with my search results.

Thank you.
  #6  
Old May 10th, 2012, 10:43 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi
Quote:
Originally Posted by fsuggest View Post
Would that cause any problems?
No, but...

Quote:
Originally Posted by fsuggest View Post
As you mentioned before, I wouldn't want punctuations in the merchants name to mess with my search results.
if you want to pass the merchant ID to the URL, then it won't display the merchant's name because that information is not available.

You are going to have to query the database to get the merchant's name from the merchant's ID here: The Factory > Your Store > VIEWS > SEARCH PAGE > Default > Product list module:

HTML Code:
<?php if (@$_GET['merchant']) { ?>
	<li>
		<b>Merchant: </b> 
		<?php PHP CODE TO QUERY DB ?>
	</li>
<?php } ?>
Eric
  #7  
Old May 10th, 2012, 09:17 PM
fsuggest fsuggest is offline
 
Join Date: Apr 2012
Posts: 45
Default

Hey Eric,

Appreciate the quick reply.

Tried your suggestion but I'm not sure where my code is wrong.

Here's what I've done:

In function.php, I use:

Code:
function dfr_get_merchants_dropdown() {
    global $wpdb;
    $merchants = $wpdb->get_results("SELECT merchant, merchant_id FROM ".$wpdb->prefix."dfr_shop_products GROUP BY merchant");
    $html = '<option value="">All stores</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;
}
In my widget, I use:

Code:
  <p class="merchant">
    <label for="merchant">Store</label>
    <select name="merchant_id" style="width: 195px;" value=''>
      <?php echo dfr_get_merchants_dropdown(); ?>
    </select>
  </p>
And in the search results page, I use:

Code:
<!-- Search Fields -->
<ul>
  <?php if (@$_GET['word']){ ?><li><b>Description: </b>[store.get param="word"]</li><?php } ?>
  <?php if (@$_GET['brand']){ ?><li><b>Brand: </b>[store.get param="brand"]</li><?php } ?>
  <?php if (@$_GET['category']){ ?><li><b>Category: </b>[store.get param="category"]</li><?php } ?>
  <?php if (@$_GET['merchant_id']) { ?>
  <li>
    <b>Store: </b>
  <?php
    $merchant = $wpdb->get_row("SELECT merchant FROM ".$wpdb->prefix."dfr_shop_products WHERE merchant_id = $_GET['merchant_id']");
    echo $merchant;
  ?>
  </li>
  <?php } ?>
  <?php if (@$_GET['tags']){ ?><li><b>Tags: </b>[store.get param="tags"]</li><?php } ?>
  <?php if (@$_GET['saleprice']){ ?><li><b>Price: </b>$[store.get param="saleprice"]</li><?php } ?>
</ul>
<!-- /Search Fields -->
I've tried get_results as well but still get a blank page.

Can you see where I'm going wrong in my code?

Thank you.

Last edited by fsuggest : May 10th, 2012 at 09:20 PM.
  #8  
Old May 10th, 2012, 11:43 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

Adding something like this to your View:

HTML Code:
  <?php if (@$_GET['merchant_id']) : ?>
  <li>
    <b>Merchant: </b> 
    <?php echo dfr_get_merchant($_GET['merchant_id']); ?>
  </li>
<?php endif; ?>
And something like this to your theme's functions.php file:

PHP Code:
function dfr_get_merchant($mid=false) {
    global 
$wpdb;
    
$merchant_name $wpdb->get_var$wpdb->prepare("
        SELECT merchant 
        FROM "
.$wpdb->prefix."dfr_shop_products
        WHERE merchant_id = %d
        Limit 1"

        
$mid
    
) );
    return 
$merchant_name;

... worked for me.

Eric
  #9  
Old May 11th, 2012, 09:05 AM
fsuggest fsuggest is offline
 
Join Date: Apr 2012
Posts: 45
Default

Awesome! Thanks Eric.

One thing I've noticed is that the search results is returning paginated pages with the last several pages showing blank results. For example, if you just hit the submit button on the top left hand sidebar search it returns 60 pages but pages 57-60 are blank.

Thank you.
  #10  
Old May 11th, 2012, 06:52 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi
Quote:
Originally Posted by fsuggest View Post
One thing I've noticed is that the search results is returning paginated pages with the last several pages showing blank results. For example, if you just hit the submit button on the top left hand sidebar search it returns 60 pages but pages 57-60 are blank.
That's because you have the following if statement around your product list code:

PHP Code:
<?php if ($product->saleprice && $product->saleprice $product->price && $savings_percentage >= 30) { ?>
Eric
  #11  
Old May 12th, 2012, 08:26 PM
fsuggest fsuggest is offline
 
Join Date: Apr 2012
Posts: 45
Default

Hey Eric,

But doesn't that if statement act as a filter to only display the items based on the conditions I've set?

Thank you.
  #12  
Old May 12th, 2012, 08:56 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

Yes, but it doesn't modify the query on the database which returns more products (and creates the pagination links to pages that don't have products because of the if filter).

Eric
  #13  
Old May 16th, 2012, 10:06 PM
fsuggest fsuggest is offline
 
Join Date: Apr 2012
Posts: 45
Default

Thanks Eric. I will have to take a look into the products in inventory.
 


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 Not Showing in Merchant Filter dk3 Problems 2 March 9th, 2012 01:42 PM


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


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