Jump to content
Philo2005

Categories - Amount of articles not shown

Recommended Posts

Version 2.3.4 of OS Commerce shows amount of articles in each category. User saw if there are articles in categories easily.
With Phoenix Version 1 0 2 5 the amount is no longer shown, so user must check all categories if there are any articles in.

refers to. https://www.attias.ch/ishop/index.php/language/en

How can i activate the amount of article shown in each categories?

 

CategoriesAmountnew.jpg

CategoriesAmountold.jpg

Share this post


Link to post
Share on other sites

You can make the subcat titles show up by editing one line in the file includes/modules/boxes/bm_catagories.php:

Quote

      $OSCOM_CategoryTree->setMaximumLevel(3);

To show the quantities, you can edit the file includes/classes/category_tree.php

Find:

Quote

          $result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level);

Edit the line that comes after:

Quote

          $result .= $link_title . ' (' . tep_count_products_in_category($category_id, false) . ')</a>'; //added to include product counts

 

Edited by kgtee

Share this post


Link to post
Share on other sites
11 hours ago, kgtee said:

You can make the subcat titles show up by editing one line in the file includes/modules/boxes/bm_catagories.php:

To show the quantities, you can edit the file includes/classes/category_tree.php

Find:

Edit the line that comes after:

 

@kgtee

Thank you very much kgtee for your answer and your help

The first part works fine showing subcategories in the boxes (includes/modules/boxes/bm_catagories.php).
Good Tip!
What would be nice if the subcategories are indent 2 spaces or so.

The second part unfortunally does not work even i corrected a Syntax error (missing ')! it seems Phoenix started looping.
$result .= $link_title . ' (' . tep_count_products_in_category($category_id, false) . ') '</a>'; //added to include product counts

Any ideas?

 

Share this post


Link to post
Share on other sites

Would it not be better only to show categories that have products available to buy?


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: on the official osc download page

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites
3 minutes ago, Philo2005 said:

@kgtee

Thank you very much kgtee for your answer and your help

The first part works fine showing subcategories in the boxes (includes/modules/boxes/bm_catagories.php).
Good Tip!
What would be nice if the subcategories are indent 2 spaces or so.

The second part unfortunally does not work even i corrected a Syntax error (missing ')! it seems Phoenix started looping.
$result .= $link_title . ' (' . tep_count_products_in_category($category_id, false) . ') '</a>'; //added to include product counts

Any ideas?

 

@kgtee

I solved it, i had Problems editing the file 

$result .= $link_title . ' (' . tep_count_products_in_category($category_id, false) . ') </a>';

works fine.

Share this post


Link to post
Share on other sites
1 hour ago, BrockleyJohn said:

Would it not be better only to show categories that have products available to buy?

@BrockleyJohn

Yes of course, do you have any idea?

Share this post


Link to post
Share on other sites
4 hours ago, Philo2005 said:

@kgtee

I solved it, i had Problems editing the file 

$result .= $link_title . ' (' . tep_count_products_in_category($category_id, false) . ') </a>';

works fine.

To get the indent, you can add blank spaces or any character you like to the variable $spacer_string. This variable is declared in the beginning of the file category_tree.php.

Example :

Quote

        $spacer_string = '<i class="fas fa-caret-right"></i> ',

This will add a caret sign in front of every subcat title.

 

Share this post


Link to post
Share on other sites

To hide categories which have no product to sell, you can add a if logic prior to display the categories.

Quote

    if (tep_count_products_in_category($category_id, false) > 0) { // added to show only categories with products to sell

          if ( ($this->follow_cpath === true) && in_array($category_id, $this->cpath_array) ) {
            $link_title = $this->cpath_start_string . $category['name'] . $this->cpath_end_string;
          } else {
            $link_title = $category['name'];
          }

          $result .= '<a class="list-group-item " href="' . tep_href_link('index.php', 'cPath=' . $category_link) . '">';
          $result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level);
          $result .= $link_title . ' (' . tep_count_products_in_category($category_id, false) . ')</a>'; //added to include product counts
    } // end show

 

Share this post


Link to post
Share on other sites
6 hours ago, kgtee said:

To hide categories which have no product to sell, you can add a if logic prior to display the categories.

 

@kgtee

Thank you very much for your code, works fine.

Share this post


Link to post
Share on other sites
1 hour ago, Philo2005 said:

@kgtee

Thank you very much for your code, works fine.

@kgtee, the Problem i have is that when supressing the categories with 0 articles, the content module (index) shows all categories,
i might have to supress them as well, to be full of Integrity.

How?

 

Share this post


Link to post
Share on other sites

Try this.

In category_tree.php:

 

Quote

    function buildBranchArray($parent_id, $level = 0, $result = '') {
      if (empty($result)) {
        $result = array();
      }

      if (isset($this->_data[$parent_id])) {
        foreach ($this->_data[$parent_id] as $category_id => $category) {
          if ($this->breadcrumb_usage == true) {
            $category_link = $this->buildBreadcrumb($category_id);
          } else {
            $category_link = $category_id;
          }
      if (tep_count_products_in_category($category_id, false) > 0) { // added to show only categories with products
          $result[] = array('id' => $category_link,
                            'image' => $category['image'],          
                            'title' => str_repeat($this->spacer_string, $this->spacer_multiplier * $level) . $category['name']);
      } // end show
          if (isset($this->_data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
            if ($this->follow_cpath === true) {
              if (in_array($category_id, $this->cpath_array)) {
                $result = $this->buildBranchArray($category_id, $level+1, $result);
              }
            } else {
              $result = $this->buildBranchArray($category_id, $level+1, $result);
            }
          }
        }
      }

 

Share this post


Link to post
Share on other sites
10 hours ago, kgtee said:

Try this.

In category_tree.php:

 

 

@kgtee

Thank you very much, works fine!
I assume you had this done before I asked for it?

Share this post


Link to post
Share on other sites

A small addition: to make it look pretty, you can change the icon, its color and size.
 

        $spacer_string = '<span style="font-size: 1.15em; color: Green;"><i class="fas fa-arrow-alt-circle-right">&nbsp;</i></span>',

1551.jpg.bc0b02b350bed70030a838e33dad9a3b.jpg


Support forum for osCommerce in russian language - from Ashkelon. Support since 2002.

Best regards,

Fredi

Share this post


Link to post
Share on other sites

Bear in mind that this particular count does hammer the database - which will impact on load time. 

I don't know by how much and would say it would vary slightly server to server, so it may be worth doing a benchmark, before and after...

 


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

I agree with Burt. Recounting the quantity of goods is impractical. But showing subcategories in the menu is very desirable. They do not need to be hidden.

2043.jpg.b11eacd401356bcee2579683f83ccc23.jpg

Edited by Fredi

Support forum for osCommerce in russian language - from Ashkelon. Support since 2002.

Best regards,

Fredi

Share this post


Link to post
Share on other sites

I'm sure this has been stock install on official osC for a long time.

Testing my site with and without I have not been able to register any diferance.

image.png.cbd6f1a0b347dff938df6ad523b4c73f.png


 

Share this post


Link to post
Share on other sites
8 hours ago, Fredi said:

I agree with Burt. Recounting the quantity of goods is impractical. But showing subcategories in the menu is very desirable. They do not need to be hidden.

2043.jpg.b11eacd401356bcee2579683f83ccc23.jpg

I really like your changes to the menu above.

I think it is up to the shopowners if they wish to display numbers or not as for some it would make sense and for others it would serve no practical purpose.

I agree it would be much easier for shopowners if that option was available in admin and it would not be too difficult to achieve this. Potentially a candidate for a module for the apps marketplace - or for someone to raise an issue / propose a pull request in GitHub for core?

As long as we capture in documentation (whether in this forum, or in the documentation initiatives being worked on) how to apply these changes.

Peter


PROUDLY PASSIONATE PHOENIX SUPPORTER

Full-time I am a C-suite executive of a large retail company in Australia. In my spare time, I enjoying learning about web-design.

Download the latest version of CE Phoenix from gitHub here

Join the Phoenix Club. Become a Phoenix Supporter.  Gain access to special codes and modules and help the project thrive. Read here

 

Share this post


Link to post
Share on other sites

I think this small change can be made to the kernel module: includes/modules/boxes/bm_categories.php
Add 2 lines to the module configuration after line 63.

setMaximumLevel  =

And a line that sets the format for how the indentation for subcategories will be displayed.
This will affect the file:  category_tree.php
But I think Burt can do it in 5 minutes!

This will give great flexibility to boxing categories.

Phoenix should be as convenient as possible for the owner of the store and for the user.
Unfortunately, this can increase the load time by 0.0001 second, but this is not a problem.

 


Support forum for osCommerce in russian language - from Ashkelon. Support since 2002.

Best regards,

Fredi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×