roboy Posted November 5, 2010 Share Posted November 5, 2010 I have been trying to include both the supplier's name and manufacturer's name for each product in the product listing (product-list.tpl). By adding {$product.manufacturer_name} I managed to include the manufacturer, but strange enough {$product.supplier_name} does not work for including the supplier. I would be very grateful for some help on how to show the corresponding supplier for each product in product-list.tpl. Here is the code that I unsuccessfully have been trying to use: {if isset($product.supplier_name)} {$product.supplier_name} {/if} Link to comment Share on other sites More sharing options...
rocky Posted November 6, 2010 Share Posted November 6, 2010 That's the way PrestaShop was designed for some reason. You will need to modify the query on line 394 of classes/Category.php (in PrestaShop v1.3.2): $sql = ' SELECT p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, (p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1) - IF((DATEDIFF(`reduction_from`, CURDATE()) <= 0 AND DATEDIFF(`reduction_to`, CURDATE()) >=0) OR `reduction_from` = `reduction_to`, IF(`reduction_price` > 0, `reduction_price`, (p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1) * `reduction_percent` / 100)),0)) AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax` LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').' '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : ''); to: $sql = ' SELECT p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, s.`name` AS supplier_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, (p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1) - IF((DATEDIFF(`reduction_from`, CURDATE()) <= 0 AND DATEDIFF(`reduction_to`, CURDATE()) >=0) OR `reduction_from` = `reduction_to`, IF(`reduction_price` > 0, `reduction_price`, (p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1) * `reduction_percent` / 100)),0)) AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax` LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'supplier` s ON s.`id_supplier` = p.`id_supplier` WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').' '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : ''); Link to comment Share on other sites More sharing options...
noesac Posted November 6, 2010 Share Posted November 6, 2010 That's a good idea Link to comment Share on other sites More sharing options...
roboy Posted November 6, 2010 Author Share Posted November 6, 2010 Thank you very much Rocky! I would never have figured that one out. Perhaps it should be included in the next version of Prestashop as a permanent fix? Link to comment Share on other sites More sharing options...
rocky Posted November 6, 2010 Share Posted November 6, 2010 You can post it to the bug tracker, but I'm not sure whether the PrestaShop team would be interested in making this change. Link to comment Share on other sites More sharing options...
roboy Posted November 6, 2010 Author Share Posted November 6, 2010 Sorry guys! It seems I was too fast calling it "SOLVED". I took for granted that it would work, but when I actually tried, it didn't. As proposed I replaced the query in classes/Category.php with the one you provided Rocky. Then I added the supplier name just below the product name in product-list.tpl in the simpleast possible form: {$product.supplier_name} But still it doesn't work. Perhaps I have missed something here. Should I use a different form for addressing the supplier name? Link to comment Share on other sites More sharing options...
roboy Posted November 7, 2010 Author Share Posted November 7, 2010 Just realized that I'm actually running Prestashop version 1.2.5, while the answer was given for 1.3.2. Could this be the reason why the fix doesn't work for me? At least the code that should be replaced in classes/Category.php appears to be identical in version 1.2.5.I would really appreciate some help here. Link to comment Share on other sites More sharing options...
rocky Posted November 8, 2010 Share Posted November 8, 2010 I just tested the code on my test site and it works fine. I noticed that it didn't work if I copied the code though, since the forums are removing the line breaks, causing an error in the SQL query. Did you copy and paste the query or manually modify your query to match the query I posted? Link to comment Share on other sites More sharing options...
Tecniloco Posted November 8, 2010 Share Posted November 8, 2010 Hi rocky, I've been all afternoon trying to see supplier_name but the code you put is not working. any ideas? Link to comment Share on other sites More sharing options...
roboy Posted November 8, 2010 Author Share Posted November 8, 2010 You ought to be a detective!Once I made the changes without copying the entire code it worked like a charm.Thank you so much for the help and sorry for the extra newbie hassle Link to comment Share on other sites More sharing options...
roboy Posted November 8, 2010 Author Share Posted November 8, 2010 Tecniloco:First of all you need to make the changes to classes/Category.php as proposed by Rocky. But you cannot simply replace the original code with the new one. You must compare the old with the new and then make each change manually in the original file.Rocky has simply added two pieces of code: s.`name` AS supplier_name, and LEFT JOIN `'._DB_PREFIX_.'supplier` s ON s.`id_supplier` = p.`id_supplier` Copy/Paste Rocky's entire code into a new text document and search for the above strings. Then you will find how and where they fit in.Once you have made those changes you insert {$product.supplier_name} into product-list.tpl whereever you want the Supplier name to appear. Hope this helps! 2 Link to comment Share on other sites More sharing options...
Tecniloco Posted November 9, 2010 Share Posted November 9, 2010 Thanks Robban but the changes you mention are already implemented. Link to comment Share on other sites More sharing options...
Greenbox Posted March 20, 2012 Share Posted March 20, 2012 I have PrestaShop v1.4.7 installed. I have edited the classes/Category.php file and product-list.tpl as described by above, but I still don't see the product.supplier_name on the product-list. I have manually typed in the code / cut-n-paste, but still no result. Does anyone have any ideas why it would not be working? Link to comment Share on other sites More sharing options...
bagos Posted May 10, 2016 Share Posted May 10, 2016 Hello, I use prestahop 1.6.1.5 and I would like to include supplier name in product list too. I don't know how and where we have to modify Category.php. If someone have the answer it will be welcome. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now