Forums / Setting Up Categories, Products, Attributes / A flag to check whether category/subcat contains products

A flag to check whether category/subcat contains products

Locked

Views: 2,190

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
18 Sep 2008, 6:07 PM
#1
callingrohit avatar

callingrohit

New Zenner

Join Date:
Aug 2008
Posts:
48
Plugin Contributions:
0

A flag to check whether category/subcat contains products

Hi,

Can anyone tell me if there is a flag/record count which after inspection can let me know whether a category or sub-category has any products within it or not ?

Thanks
callingrohit

18 Sep 2008, 8:16 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: A flag to check whether category/subcat contains products

On the Catalog or the Admin?

The Admin shows a count of how many products are in a Category and how many are active ...

You could go to the Site Map in the Catalog to see the layout of all Categories and Subcategories ...

What kind of details are you needing?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

19 Sep 2008, 3:55 AM
#3
callingrohit avatar

callingrohit

New Zenner

Join Date:
Aug 2008
Posts:
48
Plugin Contributions:
0

Re: A flag to check whether category/subcat contains products

Hi Linda,

Thansk for responding. Well basically my page has 2 boxes. Box 1 shows the name of the category/subcategory. Box 2 shows the items. Now the key point here is that the Box 2 will show random products from that category's subcategories. These subcategories are listed in Box 1.

Now say I have 3 subcategories(A, B, C) in a category. If I don't have any products in subcategory C, if someone clicks on it, I want the Box 2 to say something like "no products available" instead of coming up as just blank.

If you remember you gave me a solution for customizing specials by looking at record count(). The reason was the same. If no specials, "display some text in the box" or execute any other function.

So hence I need some kind of flag to actually check the following -

  1. Category has a subcategory or not.

  2. If no subcategory, does it have any products or not.

  3. If subcategories present, check each if it has products or not.

I hope I have been able to clearly explain my objective. Oh and this flag needs to work for the catalog side of the website not for the admin.

Thanks
callingrohit

19 Sep 2008, 2:20 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: A flag to check whether category/subcat contains products

Do you have these boxes setup now with selects that work so that when there are Products, something displays in the second box and when there are not products you get a blank?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

20 Sep 2008, 12:56 PM
#5
callingrohit avatar

callingrohit

New Zenner

Join Date:
Aug 2008
Posts:
48
Plugin Contributions:
0

Re: A flag to check whether category/subcat contains products

Hi Linda,

Thanks for pointing out. In tpl_index_product_list.php, at line 125 there is a code where I added my statement to be displayed if there are no products available in a category/subcategory....

$check_category = $db->Execute("select categories_id from " . TABLE_CATEGORIES . " where categories_id='" . $cPath . "'");
            if ($check_category->RecordCount() == 0) {
              $new_products_category_id = '0';
              $cPath= '';
            } else {	// This displays the following when there are no products in a category or subcategory
			  echo 'Sorry, there are no products listed in this category.';
			}  

Its working now and i have tested it. Fulfills its purpose. Is this a correct way to do it ??

Thanks
callingrohit

20 Sep 2008, 2:15 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: A flag to check whether category/subcat contains products

You appear to be resetting the:
$new_products_category_id = '0';
$cPath= '';

And you really do not want to change that logic in the middle of things ...

I am not sure what it is you think you are searching for on the select ...

It shows you are trying to search for the $cPath in the categories table but you already know the $cPath and $new_products_categories_id ... finding its record in the categories table will not give you any info on the products count ...

What do you want to see/know here after the select has been made?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

20 Sep 2008, 3:28 PM
#7
callingrohit avatar

callingrohit

New Zenner

Join Date:
Aug 2008
Posts:
48
Plugin Contributions:
0

Re: A flag to check whether category/subcat contains products

Well basically the code was already in place, I just added the else statement to get the resultant. So I'm not really sure what exactly it does but after putting in the else statement, the zenshop now will show the statement "sorry no products" in the box where products are usually listed in the case when there are no products in that particular category or sub-category.

So is this a wrong way ? Because I have tested my pages with the else statement for both categories and sub-categories...isn't causing any error. If no products are present, the statement just shows up, so I thought may be its right.

20 Sep 2008, 3:52 PM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: A flag to check whether category/subcat contains products

Maybe it is the version you are running as I did not have that code in mine ... but it is morning ...

As long as you are just working with an IF around existing code to set when to display the text and all seems to be working, you should be okay ...

Just check the navigation and that when things display you can get where you think you will get ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

22 Sep 2008, 1:34 PM
#9
callingrohit avatar

callingrohit

New Zenner

Join Date:
Aug 2008
Posts:
48
Plugin Contributions:
0

Re: A flag to check whether category/subcat contains products

Hi Linda,

Yes I have checked the navigation and its working all fine. But I'm still very curious to know if there's a flag/RecordCount that would directly tell me if a category or subcategory has a product or not. I suppose a close look at the header.php in module>>pages>>index or product info might reveal some information.

Regards
callingrohit

22 Sep 2008, 4:35 PM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: A flag to check whether category/subcat contains products

There are functions to test for this ...

For starters, look in the functions file:
/includes/functions/functions_categories.php

see if any of those help you ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

25 Sep 2008, 8:03 PM
#11
callingrohit avatar

callingrohit

New Zenner

Join Date:
Aug 2008
Posts:
48
Plugin Contributions:
0

Re: A flag to check whether category/subcat contains products

Thanks Linda for all your help.

27 Sep 2008, 4:00 AM
#12
cheng avatar

cheng

New Zenner

Join Date:
Nov 2005
Posts:
18
Plugin Contributions:
0

Re: A flag to check whether category/subcat contains products

Dear All:
I read all the instructions here, but I situation a little different to the previous. original I set up 4 categories and there is no problem. However after I add the five one and add one product when I click on the new categories I got blank link
If I take out the product in the category, then it back to normal, how can I solve this problem???

Thanks
Cheng

28 Sep 2008, 2:35 PM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: A flag to check whether category/subcat contains products

Thanks for the update and for posting the link to the solution that worked for you ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!