Jump to content

Manufacture count Problem


Recommended Posts

Hello, 


I have posted in several forums, but I have not gotten any replies. I really need to figure this out for my new shop so please can anyone help me with this issue. 


 


This is the problem I have: 


The product count shows in the manufacture list in the back Office, but it will not show on the front Office. No matter what I do it always displays "0"  in the front office.


 


I have switched to the default theme and still the result is the same


 


Please help me with this problem 


 


Link to manufacturers list: 


http://www.serenusfe...m/manufacturers


 


Screen shots of problem: 


 


Back Office


post-996802-0-14618400-1431285981_thumb.png


 


Front Office


post-996802-0-09079900-1431285992_thumb.png


 


 


Here is the: 


manufacturer-list.tpl


 




{*


* 2007-2014 PrestaShop


*


* NOTICE OF LICENSE


*


* This source file is subject to the Academic Free License (AFL 3.0)


* that is bundled with this package in the file LICENSE.txt.


* It is also available through the world-wide-web at this URL:


http://opensource.or...ses/afl-3.0.php


* If you did not receive a copy of the license and are unable to


* obtain it through the world-wide-web, please send an email


* to [email protected] so we can send you a copy immediately.


*


* DISCLAIMER


*


* Do not edit or add to this file if you wish to upgrade PrestaShop to newer


* versions in the future. If you wish to customize PrestaShop for your


* needs please refer to http://www.prestashop.com for more information.


*


*  @author PrestaShop SA <[email protected]>


*  @copyright  2007-2014 PrestaShop SA


*  @license    http://opensource.or...ses/afl-3.0.php  Academic Free License (AFL 3.0)


*  International Registered Trademark & Property of PrestaShop SA


*}






{capture name=path}{l s='Manufacturers'}{/capture}


<div id="pagetab">


<h1 class="page-heading product-listing">{l s='Brands'}</h1>


{strip}


<p>


{if $nbManufacturers == 0}{l s='There are no manufacturers.'}


{else}


{if $nbManufacturers == 1}


{l s='There is 1 brand'}


{else}


{l s='There are %d brands' sprintf=$nbManufacturers}


{/if}


{/if}


</p>


{/strip}


</div>






{if isset($errors) AND $errors}


{include file="$tpl_dir./errors.tpl"}


{else}


{if $nbManufacturers > 0}


    <div class="content_sortPagiBar">


        <div class="sortPagiBar clearfix">


{if isset($manufacturer) && $manufacturer.nb_products > 0}


<ul class="display hidden-xs">


<li class="display-title">


{l s='View:'}


</li>


<li id="grid">


<a rel="nofollow" href="#" title="{l s='Grid'}">


<i class="icon-th-large"></i>{l s='Grid'}


</a>


</li>


<li id="list">


<a rel="nofollow" href="#" title="{l s='List'}">


<i class="icon-th-list"></i>{l s='List'}


</a>


</li>


</ul>


{/if}


                {include file="./nbr-product-page.tpl"}


            </div>


        <div class="top-pagination-content clearfix bottom-line">


{include file="$tpl_dir./pagination.tpl"}


            </div>


        </div> <!-- .content_sortPagiBar --> 






        {assign var='nbItemsPerLine' value=3}


        {assign var='nbItemsPerLineTablet' value=2}


        {assign var='nbLi' value=$manufacturers|@count}


        {math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}


        {math equation="nbLi/nbItemsPerLineTablet" nbLi=$nbLi nbItemsPerLineTablet=$nbItemsPerLineTablet assign=nbLinesTablet}






<ul id="manufacturers_list" class="list row">


{foreach from=$manufacturers item=manufacturer name=manufacturers}


        {math equation="(total%perLine)" total=$smarty.foreach.manufacturers.total perLine=$nbItemsPerLine assign=totModulo}


           {math equation="(total%perLineT)" total=$smarty.foreach.manufacturers.total perLineT=$nbItemsPerLineTablet assign=totModuloTablet}


           {if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}


           {if $totModuloTablet == 0}{assign var='totModuloTablet' value=$nbItemsPerLineTablet}{/if}


<li class="{if $smarty.foreach.manufacturers.iteration%$nbItemsPerLine == 0} last-in-line{elseif $smarty.foreach.manufacturers.iteration%$nbItemsPerLine == 1} first-in-line{/if} {if $smarty.foreach.manufacturers.iteration > ($smarty.foreach.manufacturers.total - $totModulo)}last-line{/if} {if $smarty.foreach.manufacturers.iteration%$nbItemsPerLineTablet == 0}last-item-of-tablet-line{elseif $smarty.foreach.manufacturers.iteration%$nbItemsPerLineTablet == 1}first-item-of-tablet-line{/if} {if $smarty.foreach.manufacturers.iteration > ($smarty.foreach.manufacturers.total - $totModuloTablet)}last-tablet-line{/if}{if $smarty.foreach.manufacturers.last} item-last{/if} col-xs-12">


<div class="mansup-container animated bounceIn" style="visibility: visible;">


<div class="row"> 


            <div class="left-side col-xs-12 col-sm-3">


<div class="logo">


{if $manufacturer.nb_products > 0}


<a


class="lnk_img" 


href="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)|escape:'html':'UTF-8'}" 


title="{$manufacturer.name|escape:'html':'UTF-8'}" >


{/if}


<img src="{$img_manu_dir}{$manufacturer.image|escape:'html':'UTF-8'}-medium_default.jpg" alt="" />


{if $manufacturer.nb_products > 0}


</a>


{/if}


</div> <!-- .logo -->


</div> <!-- .left-side -->






<div class="middle-side col-xs-12 col-sm-5">


<h3>


{if $manufacturer.nb_products > 0}


<a 


class="product-name" 


href="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)|escape:'html':'UTF-8'}">


{/if}


{$manufacturer.name|truncate:60:'...'|escape:'html':'UTF-8'}


{if $manufacturer.nb_products > 0}


</a>


{/if}


</h3>


<div class="description rte">


{$manufacturer.description|truncate:180:'...'}


</div>


               </div> <!-- .middle-side -->






<div class="right-side col-xs-12 col-sm-4">


                <div class="right-side-content">


                       <p class="product-counter">


                           {if $manufacturer.nb_products > 0}


                            <a href="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)|escape:'html':'UTF-8'}">


                           {/if}


                           {if $manufacturer.nb_products == 1}


                            {l s='%d product' sprintf=$manufacturer.nb_products|intval}


                           {else}


                            {l s='%d products' sprintf=$manufacturer.nb_products|intval}


                           {/if}


                           {if $manufacturer.nb_products > 0}


                        </a>


                        {/if}


                       </p>


                   {if $manufacturer.nb_products > 0}


                       <a 


                       class="btn btn-default button exclusive-medium" 


                       href="{$link->getmanufacturerLink($manufacturer.id_manufacturer, $manufacturer.link_rewrite)|escape:'html':'UTF-8'}">


                        <span>


                        <i class="icon-reorder left"></i>  {l s='view products'} 


                        </span>


                       </a>


                   {/if}


                   </div>


               </div> <!-- .right-side -->


           </div>


       </div>


</li>


{/foreach}


</ul>


        <div class="content_sortPagiBar">


        <div class="bottom-pagination-content clearfix">


{include file="$tpl_dir./pagination.tpl" paginationId='bottom'}


            </div>


        </div> 


{/if}


{/if}

post-996802-0-07206600-1431285699_thumb.png

post-996802-0-97578400-1431285724_thumb.png

Edited by razaro (see edit history)
Link to comment
Share on other sites

Looks  like that bug is fixed.

 

Check https://github.com/PrestaShop/PrestaShop/blob/1.6/classes/Manufacturer.php#L211 and use code from line 211 to 216 

			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					if (array_key_exists((int)$manufacturer['id_manufacturer'], $counts))
						$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
					else
						$manufacturers[$key]['nb_products'] = 0; 

instead of what you probably have now in classes/Manufacturer.php

			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
Link to comment
Share on other sites

 

Looks  like that bug is fixed.

 

Check https://github.com/PrestaShop/PrestaShop/blob/1.6/classes/Manufacturer.php#L211 and use code from line 211 to 216 

			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					if (array_key_exists((int)$manufacturer['id_manufacturer'], $counts))
						$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
					else
						$manufacturers[$key]['nb_products'] = 0; 

instead of what you probably have now in classes/Manufacturer.php

			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];

Firstly, thank you for offering to help. 

If I am using PS cloud how do I access the php files? 

Because under override/classes  I cannot find the manufacturer.php

Thank you again to offer help

Link to comment
Share on other sites

Try with this, in that override/classes create new file Manufacturer.php with this code

<?php

class Manufacturer extends ManufacturerCore
{
	public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $group_by = false)
	{
		if (!$id_lang)
			$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
		if (!Group::isFeatureActive())
			$all_group = true;
		$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT m.*, ml.`description`, ml.`short_description`
		FROM `'._DB_PREFIX_.'manufacturer` m
		'.Shop::addSqlAssociation('manufacturer', 'm').'
		INNER JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.')
		'.($active ? 'WHERE m.`active` = 1' : '')
		.($group_by ? ' GROUP BY m.`id_manufacturer`' : '' ).'
		ORDER BY m.`name` ASC
		'.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''));
		if ($manufacturers === false)
			return false;
		if ($get_nb_products)
		{
			$sql_groups = '';
			if (!$all_group)
			{
				$groups = FrontController::getCurrentCustomerGroups();
				$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
			}
			$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
					SELECT  p.`id_manufacturer`, COUNT(DISTINCT p.`id_product`) as nb_products
					FROM `'._DB_PREFIX_.'product` p USE INDEX (product_manufacturer)
					'.Shop::addSqlAssociation('product', 'p').'
					LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
					WHERE p.`id_manufacturer` != 0 AND product_shop.`visibility` NOT IN ("none")
					'.($active ? ' AND product_shop.`active` = 1 ' : '').'
					'.(Group::isFeatureActive() && $all_group ? '' : ' AND EXISTS (
						SELECT 1
						FROM `'._DB_PREFIX_.'category_group` cg
						LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
						WHERE p.`id_product` = cp.`id_product` AND cg.`id_group` '.$sql_groups.'
					)').'
					GROUP BY p.`id_manufacturer`'
				);
			$counts = array();
			foreach ($results as $result)
				$counts[(int)$result['id_manufacturer']] = (int)$result['nb_products'];
			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					if (array_key_exists((int)$manufacturer['id_manufacturer'], $counts))
						$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
					else
						$manufacturers[$key]['nb_products'] = 0;
		}
		$total_manufacturers = count($manufacturers);
		$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
		for ($i = 0; $i < $total_manufacturers; $i++)
			$manufacturers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($manufacturers[$i]['name']) : 0);
		return $manufacturers;
	}

}

Clear cache in Advance Preferences > Preformance.

 

If that does not work you probably have to next update where bug will be fixed.

 

 

P.S. Please try not to make multiple topics for one issue. 

  • Like 1
Link to comment
Share on other sites

Try with this, in that override/classes create new file Manufacturer.php with this code

<?php

class Manufacturer extends ManufacturerCore
{
	public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $group_by = false)
	{
		if (!$id_lang)
			$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
		if (!Group::isFeatureActive())
			$all_group = true;
		$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT m.*, ml.`description`, ml.`short_description`
		FROM `'._DB_PREFIX_.'manufacturer` m
		'.Shop::addSqlAssociation('manufacturer', 'm').'
		INNER JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.')
		'.($active ? 'WHERE m.`active` = 1' : '')
		.($group_by ? ' GROUP BY m.`id_manufacturer`' : '' ).'
		ORDER BY m.`name` ASC
		'.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''));
		if ($manufacturers === false)
			return false;
		if ($get_nb_products)
		{
			$sql_groups = '';
			if (!$all_group)
			{
				$groups = FrontController::getCurrentCustomerGroups();
				$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
			}
			$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
					SELECT  p.`id_manufacturer`, COUNT(DISTINCT p.`id_product`) as nb_products
					FROM `'._DB_PREFIX_.'product` p USE INDEX (product_manufacturer)
					'.Shop::addSqlAssociation('product', 'p').'
					LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
					WHERE p.`id_manufacturer` != 0 AND product_shop.`visibility` NOT IN ("none")
					'.($active ? ' AND product_shop.`active` = 1 ' : '').'
					'.(Group::isFeatureActive() && $all_group ? '' : ' AND EXISTS (
						SELECT 1
						FROM `'._DB_PREFIX_.'category_group` cg
						LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
						WHERE p.`id_product` = cp.`id_product` AND cg.`id_group` '.$sql_groups.'
					)').'
					GROUP BY p.`id_manufacturer`'
				);
			$counts = array();
			foreach ($results as $result)
				$counts[(int)$result['id_manufacturer']] = (int)$result['nb_products'];
			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					if (array_key_exists((int)$manufacturer['id_manufacturer'], $counts))
						$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
					else
						$manufacturers[$key]['nb_products'] = 0;
		}
		$total_manufacturers = count($manufacturers);
		$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
		for ($i = 0; $i < $total_manufacturers; $i++)
			$manufacturers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($manufacturers[$i]['name']) : 0);
		return $manufacturers;
	}

}

Clear cache in Advance Preferences > Preformance.

 

If that does not work you probably have to next update where bug will be fixed.

 

 

P.S. Please try not to make multiple topics for one issue. 

Thank you so much it is solved. omg I was so frustrated... THANK YOU :)

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...
  • 4 years later...
On 5/11/2015 at 7:40 AM, razaro said:

Try with this, in that override/classes create new file Manufacturer.php with this code


<?php

class Manufacturer extends ManufacturerCore
{
	public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $group_by = false)
	{
		if (!$id_lang)
			$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
		if (!Group::isFeatureActive())
			$all_group = true;
		$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT m.*, ml.`description`, ml.`short_description`
		FROM `'._DB_PREFIX_.'manufacturer` m
		'.Shop::addSqlAssociation('manufacturer', 'm').'
		INNER JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.')
		'.($active ? 'WHERE m.`active` = 1' : '')
		.($group_by ? ' GROUP BY m.`id_manufacturer`' : '' ).'
		ORDER BY m.`name` ASC
		'.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''));
		if ($manufacturers === false)
			return false;
		if ($get_nb_products)
		{
			$sql_groups = '';
			if (!$all_group)
			{
				$groups = FrontController::getCurrentCustomerGroups();
				$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
			}
			$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
					SELECT  p.`id_manufacturer`, COUNT(DISTINCT p.`id_product`) as nb_products
					FROM `'._DB_PREFIX_.'product` p USE INDEX (product_manufacturer)
					'.Shop::addSqlAssociation('product', 'p').'
					LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
					WHERE p.`id_manufacturer` != 0 AND product_shop.`visibility` NOT IN ("none")
					'.($active ? ' AND product_shop.`active` = 1 ' : '').'
					'.(Group::isFeatureActive() && $all_group ? '' : ' AND EXISTS (
						SELECT 1
						FROM `'._DB_PREFIX_.'category_group` cg
						LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
						WHERE p.`id_product` = cp.`id_product` AND cg.`id_group` '.$sql_groups.'
					)').'
					GROUP BY p.`id_manufacturer`'
				);
			$counts = array();
			foreach ($results as $result)
				$counts[(int)$result['id_manufacturer']] = (int)$result['nb_products'];
			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					if (array_key_exists((int)$manufacturer['id_manufacturer'], $counts))
						$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
					else
						$manufacturers[$key]['nb_products'] = 0;
		}
		$total_manufacturers = count($manufacturers);
		$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
		for ($i = 0; $i < $total_manufacturers; $i++)
			$manufacturers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($manufacturers[$i]['name']) : 0);
		return $manufacturers;
	}

}

Clear cache in Advance Preferences > Preformance.

 

If that does not work you probably have to next update where bug will be fixed.

 

 

P.S. Please try not to make multiple topics for one issue. 

This works great for my problem. 

 

But :) is there a way to only make it work in fronend and not in the backend :D

When this is active you can't add a new manufacturer' because it doesn't show manufacturers with no products when adding new a new product .

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