Jump to content
karolitg

Add number of products in category (menu)

Recommended Posts

Hello,
I have a problem with PrestaShop. I do shop for my friend, and he wants to number of product in category menu (left_column). In shop will be many products, and many (multi-level) categories.
I think that it's not good idea, because every refresh of website I will calculate number of product in every category.

-> I don't know how I can do this. Because, if I refresh website, I must calculate number of products. It's not efficient.

-> Second problem is- i don't know how i can do this in PrestaShop controller.

 

What you think about this problem?

Share this post


Link to post
Share on other sites

Hi, you want to show the number of products in each category beside the category title?

Share this post


Link to post
Share on other sites

So, you will need to do some customizations in the corresponding module, blockcategories.

Share this post


Link to post
Share on other sites

Thanks for your answer.
Yes, I know, but I see in sql code of module, and if I do join with products, my query will be very slow (if in shop will be many products, and many categories - now I have a 100 categories, and a few products. But in future, in this shop will be maybe 3000-4000 products.).
I don't want to slow this shop, but I don't know, how I can do it this modification in other way that add sql join to products table.

Share this post


Link to post
Share on other sites
2 hours ago, andreea91 said:

Hello, how do I make it work in 1.6.11, because the code is different?

 

Thank you :)

The method is the same, just adapt the code based on error reportings.

Share this post


Link to post
Share on other sites
16 hours ago, ndiaga said:

The method is the same, just adapt the code based on error reportings.

Hello again, I tried many times but no results :))  My code is below:

public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0)
    {
        if (is_null($id_category))
            $id_category = $this->context->shop->getCategory();
        $children = array();
        if (isset($resultParents[$id_category]) && count($resultParents[$id_category]) && ($maxDepth == 0 || $currentDepth < $maxDepth))
            foreach ($resultParents[$id_category] as $subcat)
                $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
        if (isset($resultIds[$id_category]))
        {
            $link = $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']);
            $name = $resultIds[$id_category]['name'];
            $desc = $resultIds[$id_category]['description'];
        }
        else
            $link = $name = $desc = '';

        $return = array(
            'id' => $id_category,
            'link' => $link,
            'name' => $name,
            'desc'=> $desc,
            'children' => $children
        );
        return $return;
    }

Share this post


Link to post
Share on other sites
5 hours ago, andreea91 said:

Hello again, I tried many times but no results :))  My code is below:


        

What do you mean by

count($resultParents[$id_category])

???

Share this post


Link to post
Share on other sites

This is not counting the number of products .

You should use something like this to count the number of products:

$category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');

 

Share this post


Link to post
Share on other sites
On 11/20/2018 at 2:18 PM, andreea91 said:

and where can I put this code?

 

If you are asking these type of questions it means that you should hire a developer to handle this issue for you.

Share this post


Link to post
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More