Datafeedr Support Forums

Datafeedr Support Forums (http://www.datafeedr.com/forums/index.php)
-   Problems (http://www.datafeedr.com/forums/forumdisplay.php?f=68)
-   -   Search showing merchant id instead of merchant name (http://www.datafeedr.com/forums/showthread.php?t=6856)

fsuggest April 30th, 2012 12:33 AM

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.

Eric April 30th, 2012 08:22 AM

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

fsuggest May 1st, 2012 02:19 PM

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.

Eric May 1st, 2012 02:21 PM

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

fsuggest May 10th, 2012 10:36 AM

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.

Eric May 10th, 2012 10:43 AM

Hi
Quote:

Originally Posted by fsuggest (Post 31821)
Would that cause any problems?

No, but...

Quote:

Originally Posted by fsuggest (Post 31821)
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

fsuggest May 10th, 2012 09:17 PM

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.

Eric May 10th, 2012 11:43 PM

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

fsuggest May 11th, 2012 09:05 AM

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.

Eric May 11th, 2012 06:52 PM

Hi
Quote:

Originally Posted by fsuggest (Post 31850)
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

fsuggest May 12th, 2012 08:26 PM

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.

Eric May 12th, 2012 08:56 PM

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

fsuggest May 16th, 2012 10:06 PM

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


All times are GMT -5. The time now is 09:16 AM.

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