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 9th, 2013, 07:31 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default Count of Products in a particular brand

Hello,
Store ID:
Website URL: http://pricechecker247.co.uk/
URL to page in question: http://pricechecker247.co.uk/photogr...gital-cameras/


I was trying to display brands per category.
I had written following code in my functions.php
PHP Code:
function dfr_get_brands($cat=false) {
    global 
$wpdb;
    if (
$cat) { $cat_query "WHERE cat_id = ".$cat." "; }
    
$brands $wpdb->get_results("SELECT brand FROM ".$wpdb->prefix."dfr_shop_products ".$cat_query."GROUP BY brand");
    
$list = array(); 
    foreach (
$brands as $brands) {
        
$list[] = $brands->brand;        
    }
    return 
$list

And following code in view
PHP Code:
<ul> 
<?php 
$brands 
dfr_get_brands(1270308); 
foreach (
$brands as $brand) {
    if (
$brand != "") {
    
$brand urlencode($brand); 
    
?> 
      <li><a href="[server.url type='fullpage' query='search-class=PPT_S-ppt_s&cs-all-0=$brand']"><?php echo urldecode($brand); ?></a></li>
  <?php ?>
<?php 
?> 
</ul>

Now I want to display number of products in that particular brand next to brand name e.g. canon (10).
Can you please help me on this

Thanks
  #2  
Old October 9th, 2013, 08:10 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

I think you need something like this:

PHP Code:
function dfr_get_brands($cat=false) { 
    global 
$wpdb
    if (
$cat) { $cat_query "WHERE cat_id = ".$cat." "; } 
    
$brands $wpdb->get_results("SELECT COUNT(*) as num, brand FROM ".$wpdb->prefix."dfr_shop_products ".$cat_query."GROUP BY brand"); 
    
$list = array();  
    foreach (
$brands as $brands) { 
        
$list[] = array($brands->brand$brands->num);         
    } 
    return 
$list;  

PHP Code:
<ul>  
<?php  
$brands 
dfr_get_brands();  
foreach (
$brands as $brand) { 
    if (
$brand != "") { ?>  
      <li><a href="[server.url type='fullpage' query='search-class=PPT_S-ppt_s&cs-all-0=$brand[0]']"><?php echo urldecode($brand[0]); ?> (<?php echo $brand[1]; ?>)</a></li> 
  <?php ?> 
<?php ?>  
</ul>
Eric
  #3  
Old October 10th, 2013, 04:02 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

thanks Eric it works :-)
  #4  
Old October 10th, 2013, 07:30 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

Hello Eric,
Sorry to trouble you agian.

In a view (Text),
I have written following code.
<ul>
<?php


$brands = dfr_get_brands(1270308);
foreach ($brands as $brand) {
if ($brand != "") { ?>
<li><a href="[server.url type='fullpage' query='search-class=PPT_S-ppt_s&cs-all-0=$brand[0]']">
<?php echo urldecode($brand[0]); ?> (<?php echo $brand[1]; ?>)</a></li>
<?php } ?>
<?php } ?>
</ul>

Here I am passing a hard coded value of category Id (rather a sub category Id).
How Can i get the category Id.
The url is in following format
www.mysite.com/categoryName/subCategoryName/
(Actual example http://pricechecker247.co.uk/photography/camcorders/)

Can you please help ?
Thanks
  #5  
Old October 10th, 2013, 07:43 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

If you are in a Datafeedr Store Category, this variable will give you the category ID:

PHP Code:
$category->id 
Eric
  #6  
Old October 10th, 2013, 08:15 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

Its blank ...
  #7  
Old October 10th, 2013, 09:23 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

The $category object will only be available after a call to the_content() has been made. It it's called before that, the $category object will be empty.

Eric
  #8  
Old October 14th, 2013, 07:44 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

Hello,

I am still getting it as blank.
If I want to write a function in my functions.php file to get Category Id (dfr) from categoryName, how it should be...

I was trying something like this.
But the array is blank.

function dfr_get_cat_id($catName=false) {
global $wpdb;
if ($catName) { $cat_query = "WHERE cat_name = '".$catName."' "; }
$cats = $wpdb->get_results("SELECT cat_id FROM ".$wpdb->prefix."dfr_shop_categories " .$cat_query);
var_dump($cats);

}


Can you please suggest ?

Thanks,
  #9  
Old October 14th, 2013, 08:39 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

I would recommend getting and querying based on the category ID, not the name. If the name is accessible, the ID will also be accessible.

Your current query is trying to perform a match based on an integer however you're passing a string to the query. That's not going to work.

Eric
  #10  
Old October 14th, 2013, 08:57 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

Yes, exactly, I am trying to get category id.
Actually I am getting category name in URL. So I can easily access it from $_GET.

Sorry, but I did not understand what do you mean by 'Your current query is trying to perform a match based on an integer'

I had also tried defining function as following. But it did not work for me.
function dfr_get_cat_id($catName="") { ......}

Can you please help me getting category Id?

Last edited by pricechecker : October 14th, 2013 at 09:01 AM.
  #11  
Old October 14th, 2013, 09:12 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

Where exactly are you making the call to the dfr_get_brands() function from?

Eric
  #12  
Old October 14th, 2013, 09:31 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

I have created a widget
Added a text to it
And written following code in it


<ul>
<?php
//cat_name_to_id('cookers');
//$current_cat_id = dfr_get_cat_id(1270866);
//echo($current_cat_id[0] . "**");
$brands = dfr_get_brands(1270302);
foreach ($brands as $brand) {
if ($brand != "" && trim($brand[0] != "")) { ?>
<li><a href="[server.url type='fullpage' query='search-class=PPT_S-ppt_s&cs-all-0=$brand[0]']">
<?php echo urldecode($brand[0]); ?> (<?php echo $brand[1]; ?>)</a></li>
<?php } ?>
<?php } ?>
</ul>
  #13  
Old October 14th, 2013, 09:50 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

Try this:

HTML Code:
<ul> 
	<?php
	$brands = dfr_get_brands($category->id); 
	foreach ($brands as $brand) { 
		if ($brand != "" && trim($brand[0] != "")) { ?> 
			<li><a href="[server.url type='fullpage' query='search-class=PPT_S-ppt_s&cs-all-0=$brand[0]']">
			<?php echo urldecode($brand[0]); ?> (<?php echo $brand[1]; ?>)</a></li> 
		<?php } ?> 
	<?php } ?> 
</ul>
Eric
  #14  
Old October 14th, 2013, 09:51 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

And don't forget to update the dfr_get_brands() function to query the category ID, not name.
  #15  
Old October 17th, 2013, 07:31 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

Hello Eric,

I am using following code in my function.php
PHP Code:
function dfr_get_brands($cat=false) { 
    global 
$wpdb
    if (
$cat) { $cat_query "WHERE cat_id = ".$cat." "; } 
    
$brands $wpdb->get_results("SELECT COUNT(*) as num, brand FROM ".$wpdb->prefix."dfr_shop_products ".$cat_query."GROUP BY brand"); 
    
$list = array();  
    foreach (
$brands as $brands) { 
        
$list[] = array($brands->brand$brands->num);         
    } 
    return 
$list;  

But the result set has some problems
1. It is not showing me incorrect number of products in a particular brand.
2. It is showing some irrelevant brands e.g ION.
You can check the same here : http://pricechecker247.co.uk/photogr...gital-cameras/


Can you please help?
  #16  
Old October 17th, 2013, 08:56 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi,

The issue is, that's not a Datafeedr store page. You're using the PremiumPress theme which completely overrides what Datafeedr outputs. This also means that the code above is not relevant to your PP pages. I would ask the PP guys how to set up brand filters for your theme.

Eric
  #17  
Old October 18th, 2013, 07:51 AM
pricechecker pricechecker is offline
 
Join Date: Sep 2013
Posts: 19
Default

Hello Eric,

Thank you so much.
We will be waiting for your reply.
  #18  
Old October 18th, 2013, 08:33 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi
Quote:
Originally Posted by pricechecker View Post
Hello Eric,

Thank you so much.
We will be waiting for your reply.
Just to clarify, you will need to contact them. I'm not a PP customer therefore I can't contact regarding this issue.

Thanks,
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
show count of Products Task001 Questions 2 May 19th, 2012 09:47 PM
Please help - Related/featured products word count majestic12 Problems 10 November 8th, 2011 09:55 AM
Product Count not working ayorofrance Problems 11 January 31st, 2011 09:31 AM


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


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