Jump to content

Add number of products in category (menu)


karolitg

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?

Link to comment
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.

Link to comment
Share on other sites

  • 2 years later...
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;
    }

Link to comment
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
×
×
  • Create New...