Jump to content

Product Count in Categories


creters

Recommended Posts

Was wondering if there was a way to include product counts for each category which would show in the header. Thought maybe it would be in Admin Panel somewhere but could not locate unless I am looking in the wrong place. Also checked the forum. Found some solutions but seem to be for older versions of CubeCart since files and lines referenced do not match current version (6.1.1).

Link to comment
Share on other sites

Let's try this. Two small edits. There isn't a hook nearby we can use, so an edit to the core code is what we will do.

In /classes/catalogue.class.php, near line 749, find:

$result = array(
  'name'  => (isset($this->_category_translations[$category['cat_id']]) && !empty($this->_category_translations[$category['cat_id']])) ? $this->_category_translations[$category['cat_id']] : $category['cat_name'],
  'cat_id' => $category['cat_id'],
  'cat_level' => $level
);

Change to:

$result = array(
  'name'  => (isset($this->_category_translations[$category['cat_id']]) && !empty($this->_category_translations[$category['cat_id']])) ? $this->_category_translations[$category['cat_id']] : $category['cat_name'],
  'cat_id' => $category['cat_id'],
  'cat_level' => $level, 'count' => $products,
);

In the skin template, element.navigation_tree.php, find:

<a href="{$BRANCH.url}" title="{$BRANCH.name}">{$BRANCH.name}</a>

Change to:

<a href="{$BRANCH.url}" title="{$BRANCH.name}">{$BRANCH.name} ({$BRANCH.count})</a>

The problem remains that the entire finished/rendered Navigation Tree template is cached. So, if the number of products change, this will not be reflected in the navigation.

We must prevent this from being cached.

In /clases/gui.class.php, near line 1034, find:

$GLOBALS['cache']->write($content, $cache_id, '', $serialize);

Change to:

// $GLOBALS['cache']->write($content, $cache_id, '', $serialize);

Be aware there is a reason for caching this - it could take a (relatively) long time to build it for every page load.

Link to comment
Share on other sites

The edits seem to have done the job. Now see count for categories. As far as the caching/speed concern, the store (eventually) shouldn't change constantly and would rather have speed if I had a preference. I would assume entering/exiting site would clear the cache anyway. As always, thanks for the direction and help!

 

Link to comment
Share on other sites

"I would assume entering/exiting site would clear the cache anyway."

Actually, no. The only automatic clearing is any cached SQL query, then only if exiting the admin - where, presumably, you have made changes that would show in query responses. And also when quantities change when products are sold.

But the Navigation Tree is not a database query response, so it is not cleared between storefront pageloads, but is when the admin makes changes to the category hierarchy in admin.

Link to comment
Share on other sites

Not sure if this is an issue related to changing the cache setting in gui.class.php as suggested above or something unrelated:

Did the change and didn't navigate around the site too much. Came back, went into the Admin Panel and noticed the font size for the dashboard was larger (about twice the size); so much so the page went off the screen slightly. While in the Panel also noticed same thing happending with product page, customer list, statistics. Not sure if it is happening elsewhere. 

On the store side of things, seems the "home" icon in the category box is now in upper left hand corner of box and the Featured, Latest, Sale columns at the bottom "bleed" into the footer.

Only thing I have done in the last few days other than this fix and one to show Featured, Latest, Sale on the bottom is to increase the size the "more" button on the product pages when there is more than 15 items in a category. I reversed my "more" change thinking that had something to do with it, but things mentioned above persist. 

Also thought maybe it was browser problem. Switched browsers with same results.

 

Link to comment
Share on other sites

We can best help with this kind of situation if we can visit your site.

Please remind us of your web address.

One thing I recently did was to change the <!DOCTYPE> declaration on the main.php skin template to a version prior to the HTML5 syntax. This tells the browser to show things and to behave in ways according to HTML4 protocols and earlier.

Have you made any changes to the main.php template?

Link to comment
Share on other sites

Site is http://open4biz.biz/gtg 

Haven't touched main. Did change "tiny" type in config.xml thinking it would help the "more button but when it didn't changed it back to 30.  Changed content.category.php to "enlarge" from "tiny" when it came to displaying the "more" button but changed that back as well (although it seemed to do what I wanted it to).

Other than that, only changes made were as instructed in previous fixes (category count and allowing Featured, Latest and Sale (FLS) to show at bottom of page when browser would not allow for it on the side).

Page does not seem to "bleed" into footer when FLS displays on the side.

Not sure why Admin Panel fonts increased as well; haven't touched files specific to admin at all.

Edited by creters
typo
Link to comment
Share on other sites

Everything looks good to me.

Please check if your various browsers have had their Zoom settings changed, or that something might have changed the default font/size used by the browser if not specified by the HTML/CSS (which Foundation does not set an initial font size).

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...