Post by DannyMacD » Wed Oct 14, 2009 2:07 am

Hello,

like this site has,

http://www.shrimantech.com/opencart/dem ... ommon/home

i would like to know what code is needed to show the number of products in that category.

example

Desktops (20)
- Mac (12)
- PC (8)

many thanks :)

Danny

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by readyman » Wed Oct 21, 2009 8:28 pm

UPDATED FOR CLARITY BY QPHORIA

1. EDIT: catalog/controller/module/category.php

2. FIND:

Code: Select all

if ($this->category_id == $result['category_id']) {
	$output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '"><b>' . $result['name'] . '</b></a>';
} else {
	$output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '">' . $result['name'] . '</a>';
}
3. REPLACE WITH:

Code: Select all

$this->load->model('catalog/product');
		    $getTotal = '('. $this->model_catalog_product->getTotalProductsByCategoryId($result['category_id']) .')';
		    if ($this->category_id == $result['category_id']) {
		       $output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '"><b>' . $result['name'] . '</b></a>'. $getTotal;
		    } else {
		       $output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '">' . $result['name'] . '</a>' . $getTotal;
		    }

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by digitalchaos » Thu Oct 22, 2009 4:29 am

is there any way to color these numbers and brackets

The most terrifying words in the English language are: I'm from the government and I'm here to help.
Ronald Reagan

Digital Chaos | Graphic Design Studio http://www.digitalchaos.biz
Digital Chaos Prints | Custom Art Prints http://www.digitalchaosprints.biz


User avatar
New member

Posts

Joined
Mon Sep 28, 2009 9:22 pm
Location - Paterson NJ

Post by Qphoria » Wed Dec 02, 2009 6:09 am

I've cleaned up this thread to remove all the confusing posts and questions/spam. I've updated readyman's thread to be a bit clearer and to add the model load step as that is needed.

The code above is still credited to readyman but it should work for all versions of OpenCart the same way. I've tested it out and it works fine in 1.3.2 and 1.3.4

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by DoctorQ » Wed Dec 02, 2009 8:25 am

test for v 1.3.3 ---> OK!

New member

Posts

Joined
Tue Oct 27, 2009 3:08 pm

Post by leprimo » Wed Dec 02, 2009 6:36 pm

V.1.3.4, oh,what have I done?
Components (0) but subcategory Monitors(3) ???

Attachments

category_count.png

category_count.png (1.85 KiB) Viewed 4586 times


Active Member

Posts

Joined
Wed Nov 04, 2009 8:31 pm

Post by fido-x » Wed Dec 02, 2009 8:55 pm

leprimo wrote:V.1.3.4, oh,what have I done?
Components (0) but subcategory Monitors(3) ???
That's right. The "Components" category doesn't have any products, so it doesn't count any.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by leprimo » Wed Dec 02, 2009 9:34 pm

Mmhh, but only silly users click on categories without entry. :(
I think that's not really good.

Attachments

category_count_shrink.png

category_count_shrink.png (1.79 KiB) Viewed 4573 times


Active Member

Posts

Joined
Wed Nov 04, 2009 8:31 pm

Post by fido-x » Wed Dec 02, 2009 10:01 pm

You missed the point. Only categories that have PRODUCTS will display a PRODUCT count. Categories that have sub-categories but no products will display a zero value because the products are in the sub-categories.

You will note that, in the default set up (as per your attached image), there are 15 products in the "Desktops" category. There are also 2 sub-categories (PC and MAC) that are not counted!

Sounds like what you want is something that counts sub-categories as well as products.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by pepiw » Mon Mar 29, 2010 7:59 am

Hi,
this is the code modified for v1.4.4. Tested and work.

Code: Select all

$this->load->model('catalog/product');
                          $getTotal = '('. $this->model_catalog_product->getTotalProductsByCategoryId($result['category_id']) .')';
                 if ($this->category_id == $result['category_id']) {
                          $output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path)  . '"><b>' . $result['name'] . '</b></a>'. $getTotal;
                 } else {
                         $output .= '<a href="' . $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $new_path)  . '">' . $result['name'] . '</a>' . $getTotal;
                 }
But still the main category show (0) although in the subcategory are eg 14 products.
Like this:
Category_A (0)
Subcategory_A (3)
Subcategory_B (5)
Subcategory_C (6)

I want shows something like that:
Category_A (14)
Subcategory_A (3)
Subcategory_B (5)
Subcategory_C (6)

How I do this? Help!

Newbie

Posts

Joined
Thu Mar 25, 2010 7:17 pm

Post by Perthaussie » Mon May 31, 2010 1:12 pm

leprimo wrote:Mmhh, but only silly users click on categories without entry. :(
I think that's not really good.
I have added a message at the top of the category list to let customers know there may be items in sub-categories of empty top level categories.

Edit the file: catalog/view/theme/XXXXX/template/module/category.tpl

Code: Select all

<div id="category" class="middle"><?php echo 'Empty categories may have items in subcategories';?></br></br><?php echo $category; ?></div>
The category count idea seemed such a good idea that I thought the message would overcome the empty category drawback.

You can see the benefit better in the demo store in my signature.

http://www.hostedmalls.com
http://www.hostedmalls.com/demo/store/


Newbie

Posts

Joined
Sun May 23, 2010 1:48 pm


Post by dramony » Tue Jul 13, 2010 8:32 pm

Can someone please help us make this work on the latest version?
Thanks!

Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm

Post by Trucifix » Tue Jul 20, 2010 7:42 pm

I just added the later of the two codes to version 1.4.8b and it appears to be working fine.

http://www.getimacroscripts.com
http://www.myyearbookscripts.com


Newbie

Posts

Joined
Tue Jun 08, 2010 10:22 am

Post by Maansy » Tue Jul 20, 2010 8:42 pm

I want to show something like that:
Category_A (14)
Subcategory_A (3)
Subcategory_B (5)
Subcategory_C (6)

How do I do that?
thanks

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by Perthaussie » Tue Jul 20, 2010 9:00 pm

Maansy wrote:I want to show something like that:
Category_A (14)
Subcategory_A (3)
Subcategory_B (5)
Subcategory_C (6)

How do I do that?
thanks
As explained earlier in this thread, it is not possible.

http://www.hostedmalls.com
http://www.hostedmalls.com/demo/store/


Newbie

Posts

Joined
Sun May 23, 2010 1:48 pm


Post by Maansy » Sat Aug 07, 2010 9:27 am

Perthaussie wrote:
Maansy wrote:I want to show something like that:
Category_A (14)
Subcategory_A (3)
Subcategory_B (5)
Subcategory_C (6)

How do I do that?
thanks
As explained earlier in this thread, it is not possible.
NOTHING is not possible :)
one day someone will figure it out

ALL Templates :: 1.5.1+ Templates :: 50%-75% PRICE DROP ONLY at OpencartStuff.com


User avatar
Active Member

Posts

Joined
Thu Jun 24, 2010 6:04 am


Post by dramony » Fri Aug 20, 2010 1:44 pm

I agree with Maansy.
If it worked on earlier versions, how come it wont on the latest?

Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm

Post by cevarief » Fri Aug 20, 2010 2:18 pm

Yeah it's possible, only slow down opencart 1 or 2 sec (depend on how many sub folder) since the code should traverse its sub folder to count how many product in it :P

Active Member

Posts

Joined
Wed Jun 02, 2010 10:52 pm

Post by celestial » Thu Sep 09, 2010 3:11 am

that is working for v1.4.9???

Celestial - Martín Abel Rosales
WhatsApp: 50671482211
Email: martinrosales2012@hotmail.com
Skype: martin.abel.rosales
San José , Costa Rica


User avatar
Expert Member

Posts

Joined
Sat Mar 20, 2010 4:19 am
Location - Costa Rica

Post by virgil » Tue Oct 12, 2010 4:07 am

Does someone please know how you can make it like this for v1.4.9.1:

Category_A (14)
Subcategory_A (3)
Subcategory_B (5)
Subcategory_C (6)

New member

Posts

Joined
Tue Aug 03, 2010 9:48 pm

Who is online

Users browsing this forum: Majestic-12 [Bot] and 77 guests