prestashop 1.6 how to show manufacturer logo in productcontroller.php

997 Views Asked by At

I want to show manufacturer logo image if product have no image.

I find on ProductController.php this:

if (!isset($cover)) {
            if (isset($images[0])) {
                $cover = $images[0];
                $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$images[0]['id_image']) : $images[0]['id_image']);
                $cover['id_image_only'] = (int)$images[0]['id_image'];
            } else {
                $cover = array(
                    'id_image' => $this->context->language->iso_code.'-default',
                    'legend' => 'No picture',
                    'title' => 'No picture'
                );
            }
        }

but i don't know how to put manufacturer logo instead of no picture.

2

There are 2 best solutions below

0
On

You can try the following code to get product manufacturer image in ProductController.php

$man_id = $this->product->id_manufacturer;
$image_url = _PS_MANU_IMG_DIR_.$man_id'-medium.jpg';
3
On

You must do a combination of changes in ProductController.php and product.tpl

        if (!isset($cover)) {
            if (isset($images[0])) {
                $cover = $images[0];
                $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$images[0]['id_image']) : $images[0]['id_image']);
                $cover['id_image_only'] = (int)$images[0]['id_image'];
            } else {
                $cover = array(
                'id_image' => $this->context->language->iso_code.'-default',
                'legend' => 'No picture',
                'title' => 'No picture'
                );  //here your modification code
                $manufacturer_image = _PS_MANU_IMG_DIR_.$item['id_manufacturer'].'-'.ImageType::getFormatedName('medium').'.jpg'; 
             }
        }

Then in TPL:

              {if $have_image}
                    <span id="view_full_size">
                        {if $jqZoomEnabled && $have_image && !$content_only}
                            <a class="jqzoom" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" rel="gal1" href="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'thickbox_default')|escape:'html':'UTF-8'}">
                                <img itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}"/>
                            </a>
                        {else} 
                            <img id="bigpic" itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" width="{$largeSize.width}" height="{$largeSize.height}"/>
                            {if !$content_only}
                                <span class="span_link no-print">{l s='View larger'}</span>
                            {/if}
                        {/if}
                    </span>
                {else} 
                    {* here you modification code *} <span id="view_full_size">
                        <img itemprop="image" src="{$manufacturer_image}" id="bigpic" alt="" title="{$product->name|escape:'html':'UTF-8'}" width="{$largeSize.width}" height="{$largeSize.height}"/>
                        {if !$content_only}
                            <span class="span_link">
                                {l s='View larger'}
                            </span>
                        {/if}
                    </span>
                {/if}

If you want the same behavior in all shop (cart, viewed productos, etc) you must override all specific controller that manage this views (CartController, etc). Other more simple option that I personally don't like but could work is set a default image for every product without images, and this image should be the manufacturer image. To do this automatically you should subscribe to all Image entity hooks (actionObjectImageAddAfter, actionObjectImageUpdateAfter, actionObjectImageDeleteAfter) and check if product does not have images any more to placed a default manufacturer image in his place. Then when a real image is added delete the "default one".

    public function hookActionObjectImageUpdateAfter($params)
    {
        if (!Image::getImagesTotal((int) $params['object']->id_product))
        {
              //create an image for this product with manufacturer image
        }
    }

Good luck.