noesac Posted June 14, 2010 Share Posted June 14, 2010 I notice that the Manufacturers block is showing all my manufacturers, even ones that I have marked as "Display = No", any ideas how I can fix this?Cheers Link to comment Share on other sites More sharing options...
rocky Posted June 15, 2010 Share Posted June 15, 2010 Try changing line 31 of modules/blockmanufacturer/blockmanufacturer.php from: 'manufacturers' => Manufacturer::getManufacturers(), to: 'manufacturers' => Manufacturer::getManufacturers(false, 0, true), This issue might be worth posting on the bug tracker. Link to comment Share on other sites More sharing options...
noesac Posted June 15, 2010 Author Share Posted June 15, 2010 Happy to contribute back to this project, where is this bug tracker? Link to comment Share on other sites More sharing options...
rocky Posted June 15, 2010 Share Posted June 15, 2010 Click on the Bug Tracker link near the top-right of the page, then click "Report a bug" in the right column. Link to comment Share on other sites More sharing options...
noesac Posted June 16, 2010 Author Share Posted June 16, 2010 Do you know how I can apply a filter based on whether the manufacturer has one or more products within it? I want to hide any where products = 0. Cheers Link to comment Share on other sites More sharing options...
rocky Posted June 16, 2010 Share Posted June 16, 2010 Try changing line 185 of classes/Manufacturer.php (in PrestaShop v1.3.1) from: $manufacturers[$key]['nb_products'] = sizeof($result); to: if (sizeof($result) > 0) $manufacturers[$key]['nb_products'] = sizeof($result); else unset($manufacturers[$key]); This should delete the manufacturer from the returned results when there are no products. Link to comment Share on other sites More sharing options...
noesac Posted June 16, 2010 Author Share Posted June 16, 2010 You're amazing, thanks. Should I log this in the bug tracker? Link to comment Share on other sites More sharing options...
rocky Posted June 16, 2010 Share Posted June 16, 2010 No, I think it is expected behaviour for manufacturers with no products to be displayed. Link to comment Share on other sites More sharing options...
noesac Posted June 17, 2010 Author Share Posted June 17, 2010 Hi Rocky, That worked perfectly on the block, however when I click on the block title ("Manufacturer") I think that may have caused some unusual behavior: http://tiny.cc/mjigrAs you can see, there should only be 3 manufacturers returned, while it states "There are 13 brands.", however there are only 6 results! Three different things! Any idea how I can tweak the mod above to fix this?Cheers Link to comment Share on other sites More sharing options...
rocky Posted June 17, 2010 Share Posted June 17, 2010 It looks like you also need to comment out line 170 of classes/Manufacturer.php: // if ($getNbProducts) Link to comment Share on other sites More sharing options...
noesac Posted June 17, 2010 Author Share Posted June 17, 2010 Hi Rocky, I just tried this but it doesn't appear to have made an impact. Link to comment Share on other sites More sharing options...
rocky Posted June 17, 2010 Share Posted June 17, 2010 It worked on my test site. I tested the code using PrestaShop v1.3.1. Are you using PrestaShop v1.2.5? Link to comment Share on other sites More sharing options...
rocky Posted June 17, 2010 Share Posted June 17, 2010 Here's the entire modified getManufacturers function: static public function getManufacturers($getNbProducts = false, $id_lang = 0, $active = false, $p = false, $n = false) { global $cookie; if (!$id_lang) $id_lang = Configuration::get('PS_LANG_DEFAULT'); $sql = 'SELECT m.*, ml.`description`'; $sql.= ' FROM `'._DB_PREFIX_.'manufacturer` as m LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.intval($id_lang).')'; $sql.= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : ''); $manufacturers = Db::getInstance()->ExecuteS($sql); if ($manufacturers === false) return false; // if ($getNbProducts) foreach ($manufacturers as $key => $manufacturer) { $sql = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`) WHERE m.`id_manufacturer` = '.intval($manufacturer['id_manufacturer']).' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` '.(!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').' )'; $result = Db::getInstance()->ExecuteS($sql); if (sizeof($result) > 0) $manufacturers[$key]['nb_products'] = sizeof($result); else unset($manufacturers[$key]); } for ($i = 0; $i < sizeof($manufacturers); $i++) if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) $manufacturers[$i]['link_rewrite'] = Tools::link_rewrite($manufacturers[$i]['name'], false); else $manufacturers[$i]['link_rewrite'] = 0; return $manufacturers; } Link to comment Share on other sites More sharing options...
noesac Posted June 17, 2010 Author Share Posted June 17, 2010 Hi Rocky,I'm on 1.3.0Cheers Link to comment Share on other sites More sharing options...
rocky Posted June 17, 2010 Share Posted June 17, 2010 It should be working then. Try copying the entire modified getManufacturers function above. Link to comment Share on other sites More sharing options...
noesac Posted June 17, 2010 Author Share Posted June 17, 2010 Thanks Rocky i'll give that a shot the moment I get home. Link to comment Share on other sites More sharing options...
noesac Posted June 17, 2010 Author Share Posted June 17, 2010 Hi Rocky I just tried it and it's still the same (http://tiny.cc/mjigr). Notice that the brands have no titles or anything...so I thought it might have been a data issue, but I checked the DB and it appears quite clean, nothing out of the ordinary Link to comment Share on other sites More sharing options...
rocky Posted June 18, 2010 Share Posted June 18, 2010 I don't understand why it isn't working for you. If you PM me your FTP details, I'll take a look at your site, otherwise there isn't any more I can do. Link to comment Share on other sites More sharing options...
rocky Posted June 26, 2010 Share Posted June 26, 2010 This issue was solved via PM. Here's the solution I came up with. Change line 157 of classes/Manufacturer.php (in PrestaShop v1.3.1) from: static public function getManufacturers($getNbProducts = false, $id_lang = 0, $active = false, $p = false, $n = false) to: static public function getManufacturers($getNbProducts = false, $id_lang = 0, $active = false, $p = false, $n = false, $nonZero = false) and add the following after line 165: $sql.= $nonZero ? ' WHERE (SELECT COUNT(*) FROM `'._DB_PREFIX_.'product` WHERE `id_manufacturer` = m.`id_manufacturer`) > 0' : ''; then change line 31 of modules/blockmanufacturer/blockmanufacturer.php from: 'manufacturers' => Manufacturer::getManufacturers(), to: 'manufacturers' => Manufacturer::getManufacturers(false, 0, false, false, false, true), and line 50 of supplier.php from: $data = call_user_func(array($className, 'get'.$className.'s'), false, intval($cookie->id_lang), true); to: $data = call_user_func(array($className, 'get'.$className.'s'), false, intval($cookie->id_lang), true, false, false, $className == 'Manufacturer'); and line 54 from: $data = call_user_func(array($className, 'get'.$className.'s'), true, intval($cookie->id_lang), true, $p, $n); to: $data = call_user_func(array($className, 'get'.$className.'s'), true, intval($cookie->id_lang), true, $p, $n, $className == 'Manufacturer'); It is possible to do a similar thing with the suppliers by making similar modifications to classes/Suppliers.php and modules/blocksupplier/blocksupplier.php and then change the code above for supplier.php from: $className == 'Manufacturer' to: true Link to comment Share on other sites More sharing options...
LukeH Posted August 5, 2010 Share Posted August 5, 2010 Hi,I have followed the solution above as recommended on my other topic and it works perfectly, although I do have one question.....It would appear that Manufacturers are only displayed when items are present in the catalog. Is it possible to modify the code so that I can choose to still display a brand despite not having any products in stock for that particular manufacturer?ThanksLuke. Link to comment Share on other sites More sharing options...
rocky Posted August 5, 2010 Share Posted August 5, 2010 No, that would be much more difficult, since it would involve modifying the database and adding a field in the Back Office. Link to comment Share on other sites More sharing options...
zeisei Posted April 2, 2011 Share Posted April 2, 2011 It works ok when a product is deleted completely from the database.But, it doesn't disable displaying the manufacturer if a product just disabled from the BO instead of deleting it. I use 1.3.1 with a modified version of manufacturers block.Anyhow i also need to thank Rocky for this solution. Link to comment Share on other sites More sharing options...
Recommended Posts