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 October 6th, 2012, 01:07 PM
digitalcow digitalcow is offline
 
Join Date: Jun 2010
Posts: 494
Default List of merchants in a category

Eric

Other than going through all the categories in the factory, is there an easy way to get a list of all the merchants in a category? What I am trying to do is add a merchant menu so when you go to a category in the store you can filter products for colour, price and by retailer? If not, not to worry. I have 214 categories so will keep me out of trouble. I could use the main list of merchants from the store but don't want to have massive list and also have 'no results returned' if a retailer only does shoes and not dresses (for example)
  #2  
Old October 6th, 2012, 01:22 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Are you already using the merchant filter as discussed here: /showthread.php?t=6778

If so, you can modify that like I've suggested here: /show...5993#post35993

But that's for brands. You need to do it for merchants.

Here's the functions.php code:
PHP Code:
function dfr_get_merchants_list($category) {
    global 
$wpdb;
    
$cat_query "";
    if (
$category->is_null != 1) { 
        
$in = array();
        
$in[] = $category->id;
        if (!empty(
$category->children)) {
            foreach (
$category->children as $child => $id) {
                
$in[] = $id;
            }
        }
        
$category_ids implode(","$in);
        
$cat_query " INNER JOIN ".$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id WHERE p2c.cat_id IN (".$category_ids.") "
    }
    
$merchants_results $wpdb->get_results("
        SELECT merchant, merchant_id
        FROM "
.$wpdb->prefix."dfr_shop_products AS p 
         
        
$cat_query
        GROUP BY merchant
    "
);
    
$list = array();
    foreach (
$merchants_results as $merchants) {
        
$merchant trim($merchants->merchant);
        if (
$merchant != "") {
            
$list[$merchants->merchant_id] = $merchant;
        }
    }
    return 
$list;

And your views code:
PHP Code:
<ul>
<?php 
$merchants 
dfr_get_merchants_list($category);
foreach (
$merchants as $merchant_id => $merchant) : ?>
  <li><a href="[server.url type='fullpage' query='merchant_id=$merchant_id']"><?php echo $merchant?></a></li>
<?php endforeach; ?>
</ul>
Eric
  #3  
Old October 7th, 2012, 03:55 AM
digitalcow digitalcow is offline
 
Join Date: Jun 2010
Posts: 494
Default

Eric,

Thanks that's perfect and super easy. Got it showing up on my site in no time, http://digitalcatwalk.co.uk/category/968011/shoes
  #4  
Old October 7th, 2012, 03:58 AM
digitalcow digitalcow is offline
 
Join Date: Jun 2010
Posts: 494
Default

Eric

Sorry I think I spoke too soon.... When I click on any of the merchants listed I get 'There are no products in this category.' message. Have I missed something simple out? I have included the functions code and the widget but having issue.


many thanks, Carl
  #5  
Old October 7th, 2012, 08:32 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

Oops, sorry. Try this:
PHP Code:
function dfr_get_merchants_list($category) {
    global 
$wpdb;
    
$cat_query "";
    if (
$category->is_null != 1) { 
        
$in = array();
        
$in[] = $category->id;
        if (!empty(
$category->children)) {
            foreach (
$category->children as $child => $id) {
                
$in[] = $id;
            }
        }
        
$category_ids implode(","$in);
        
$cat_query " INNER JOIN ".$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id WHERE p2c.cat_id IN (".$category_ids.") "
    }
    
$merchants_results $wpdb->get_results("
        SELECT merchant, merchant_id
        FROM "
.$wpdb->prefix."dfr_shop_products AS p 
         
        
$cat_query
        GROUP BY merchant
    "
);
    
$list = array();
    foreach (
$merchants_results as $merchants) {
        
$merchant trim($merchants->merchant);
        if (
$merchant != "") {
            
$list[$merchants->merchant_id] = $merchant;
        }
    }
    return 
$list;

(I updated my original post with this new code, too.)

Eric
  #6  
Old October 7th, 2012, 09:04 AM
digitalcow digitalcow is offline
 
Join Date: Jun 2010
Posts: 494
Default

That's fixed it. Thanks for your help Eric
 


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
List merchants in a store's feed bingo Questions 4 July 8th, 2012 02:41 PM
Merchants List Won't Update....? gorman101 Problems 2 February 15th, 2012 12:13 PM
Merchants list not compatible astran Problems 2 July 26th, 2011 09:04 PM


All times are GMT -5. The time now is 12:54 PM.


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