Jump to content

Display manufacturer's name and link on bestseller module on homepage


Recommended Posts

Hi everyone,

 

I read some post somewhere on how to do this. I added the code below to product-list.tpl and I was able to display the name of manufacturer on the Featured and New Products block/module but it will not work for Best Selling block/module.

						{if isset($product->manufacturer_name)}
							<p class="product_manufacturer_name">
								<a href="{$link->getManufacturerLink($product.id_manufacturer)}" title="{$product->manufacturer_name|escape:'htmlall':'UTF-8'}">{$product->manufacturer_name|escape:'htmlall':'UTF-8'}</a>
							</p>
						{/if}

Does anyone know how to get this to display on bestseller list.

 

 

Thank you

Link to comment
Share on other sites

Hi

 

Issue with bestsellers module is that it use function getBestSalesLight which is not returning manufacturer_name in products.

https://github.com/PrestaShop/PrestaShop/blob/develop/classes/ProductSale.php#L159

 

So you could maybe override that class and that function and add

m.`name` AS manufacturer_name

and

LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)

so sql of function looks like 

        $sql = '
		SELECT
			p.id_product, IFNULL(product_attribute_shop.id_product_attribute,0) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, product_shop.`id_category_default`,
			image_shop.`id_image` id_image, il.`legend`,
			ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable,
			IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock,
			product_shop.`date_add` > "'.date('Y-m-d', strtotime('-'.(Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int)Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY')).'" as new,
			product_shop.`on_sale`, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity,m.`name` AS manufacturer_name
		FROM `'._DB_PREFIX_.'product_sale` ps
		LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
		'.Shop::addSqlAssociation('product', 'p').'
		LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` product_attribute_shop
			ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop='.(int)$context->shop->id.')
		LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (product_attribute_shop.id_product_attribute=pa.id_product_attribute)
		LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
			ON p.`id_product` = pl.`id_product`
			AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
		LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop
			ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.')
		LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
		LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
			ON cl.`id_category` = product_shop.`id_category_default`
			AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').Product::sqlStock('p', 0);

Note:  I did not test this but it should work.

Link to comment
Share on other sites

Thanks SPAM Mod.

 

The problem I have now is I do not know what files to edit. I am not a very technical person and my understanding of PHP Smarty or SQL is quite basic.

Anyway of doing this without editing core files please.

 

Thanks for your time nevertheless.

Link to comment
Share on other sites

Hi Members :-)

 

Ok sorry for not being too precise. 

Here are steps you need to do. Copy attached ProductSale.php to your root override/classes folder.

And for me manufacturer code that works is 

						{if isset($product.manufacturer_name)}
							<p class="product_manufacturer_name">
								<a href="{$link->getManufacturerLink($product.id_manufacturer)}" title="{$product.manufacturer_name|escape:'htmlall':'UTF-8'}">{$product.manufacturer_name|escape:'htmlall':'UTF-8'}</a>
							</p>
						{/if}

Place that where you want manufacturer name to show.

 

And do not forget to clear cache in Advanced Parametars > Performance.

 

If you have any issue let me know.

ProductSale.php

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