Jump to content

Brand Image on the brand Page


Recommended Posts

Hello to everyone,

I'm using Prestashop 1.7.5 and a custom template (jakiro).

We are using supplier pages to show the designer we are selling the products... the listing page is quite fine but each supplier page is missing the logo/image of the supplier inquestion...

I tried to change the .tpl file below copied but with no succes... Could you please help me? the concerned page is as exemple 

https://ghost.nid.ee/fr/supplier/9-annike-laigo

 

{**
 * 2007-2016 PrestaShop
 *
 * NOTICE OF LICENSE
......
 *}
{extends file='catalog/listing/product-list.tpl'}

{block name='product_list_header'}
  <h1>{if isset($supplier.name) && !empty($supplier.name)}{l s='List of products by supplier %s' sprintf=[$supplier.name] d='Shop.Theme.Catalog'}{/if}</h1>
  <div id="supplier-description">{if isset($supplier.description) && !empty($supplier.description)}{$supplier.description nofilter}{/if}</div>
{/block}
 

Link to comment
Share on other sites

I think you want the supplier logo, not the brand logo!?
Unfortunalety the supplier logo image is not assigned in SupplierController when displaying a single supplier. If you are a developer you can create a override and assign the image in function assignSupplier by using the following function:  $this->context->link->getSupplierImageLink

Link to comment
Share on other sites

  • 5 months later...

Hi,

I'm sorry for the dealy of my answer but I gave up for a while because I thought it too complicated for me... But now, I want to try agian.

So.. I looked the the supplierController.php and it looks that the image fonction looks existing (in the bottom of the code copied below)

Could you please advice? in case of, where de I have to add the new portion of code?

In advance thank you very much 

<?php
/**
 * 2007-2018 PrestaShop.
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 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:
 * https://opensource.org/licenses/OSL-3.0
 * 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-2018 PrestaShop SA
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 */
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierProductSearchProvider;

class SupplierControllerCore extends ProductListingFrontController
{
    public $php_self = 'supplier';

    /** @var Supplier */
    protected $supplier;
    private $label;

    public function canonicalRedirection($canonicalURL = '')
    {
        if (Validate::isLoadedObject($this->supplier)) {
            parent::canonicalRedirection($this->context->link->getSupplierLink($this->supplier));
        } elseif ($canonicalURL) {
            parent::canonicalRedirection($canonicalURL);
        }
    }

    /**
     * Initialize supplier controller.
     *
     * @see FrontController::init()
     */
    public function init()
    {
        if ($id_supplier = (int) Tools::getValue('id_supplier')) {
            $this->supplier = new Supplier($id_supplier, $this->context->language->id);

            if (!Validate::isLoadedObject($this->supplier) || !$this->supplier->active) {
                $this->redirect_after = '404';
                $this->redirect();
            } else {
                $this->canonicalRedirection();
            }
        }

        parent::init();
    }

    /**
     * Assign template vars related to page content.
     *
     * @see FrontController::initContent()
     */
    public function initContent()
    {
        if (Configuration::get('PS_DISPLAY_SUPPLIERS')) {
            parent::initContent();

            if (Validate::isLoadedObject($this->supplier) && $this->supplier->active && $this->supplier->isAssociatedToShop()) {
                $this->assignSupplier();
                $this->label = $this->trans(
                    'List of products by supplier %supplier_name%',
                    array(
                        '%supplier_name%' => $this->supplier->name,
                    ),
                    'Shop.Theme.Catalog'
                );
                $this->doProductSearch(
                    'catalog/listing/supplier',
                    array('entity' => 'supplier', 'id' => $this->supplier->id)
                );
            } else {
                $this->assignAll();
                $this->label = $this->trans(
                    'List of all suppliers', array(), 'Shop.Theme.Catalog'
                );
                $this->setTemplate('catalog/suppliers', array('entity' => 'suppliers'));
            }
        } else {
            $this->redirect_after = '404';
            $this->redirect();
        }
    }

    protected function getProductSearchQuery()
    {
        $query = new ProductSearchQuery();
        $query
            ->setIdSupplier($this->supplier->id)
            ->setSortOrder(new SortOrder('product', 'position', 'asc'))
        ;

        return $query;
    }

    protected function getDefaultProductSearchProvider()
    {
        return new SupplierProductSearchProvider(
            $this->getTranslator(),
            $this->supplier
        );
    }

    /**
     * Assign template vars if displaying one supplier.
     */
    protected function assignSupplier()
    {
        $supplierVar = $this->objectPresenter->present($this->supplier);

        $filteredSupplier = Hook::exec(
            'filterSupplierContent',
            array('object' => $supplierVar),
            $id_module = null,
            $array_return = false,
            $check_exceptions = true,
            $use_push = false,
            $id_shop = null,
            $chain = true
        );
        if (!empty($filteredSupplier['object'])) {
            $supplierVar = $filteredSupplier['object'];
        }

        $this->context->smarty->assign(array(
            'supplier' => $supplierVar,
        ));
    }

    /**
     * Assign template vars if displaying the supplier list.
     */
    protected function assignAll()
    {
        $suppliersVar = $this->getTemplateVarSuppliers();

        if (!empty($suppliersVar)) {
            foreach ($suppliersVar as $k => $supplier) {
                $filteredSupplier = Hook::exec(
                    'filterSupplierContent',
                    array('object' => $supplier),
                    $id_module = null,
                    $array_return = false,
                    $check_exceptions = true,
                    $use_push = false,
                    $id_shop = null,
                    $chain = true
                );
                if (!empty($filteredSupplier['object'])) {
                    $suppliersVar[$k] = $filteredSupplier['object'];
                }
            }
        }

        $this->context->smarty->assign(array(
            'brands' => $suppliersVar,
        ));
    }

    public function getTemplateVarSuppliers()
    {
        $suppliers = Supplier::getSuppliers(true, $this->context->language->id, true);
        $suppliers_for_display = array();

        foreach ($suppliers as $supplier) {
            $suppliers_for_display[$supplier['id_supplier']] = $supplier;
            $suppliers_for_display[$supplier['id_supplier']]['text'] = $supplier['description'];
            $suppliers_for_display[$supplier['id_supplier']]['image'] = $this->context->link->getSupplierImageLink($supplier['id_supplier'], 'small_default');
            $suppliers_for_display[$supplier['id_supplier']]['url'] = $this->context->link->getsupplierLink($supplier['id_supplier']);
            $suppliers_for_display[$supplier['id_supplier']]['nb_products'] = $supplier['nb_products'] > 1
                ? $this->trans('%number% products', array('%number%' => $supplier['nb_products']), 'Shop.Theme.Catalog')
                : $this->trans('%number% product', array('%number%' => $supplier['nb_products']), 'Shop.Theme.Catalog');
        }

        return $suppliers_for_display;
    }

    public function getListingLabel()
    {
        return $this->label;
    }
}

 

Link to comment
Share on other sites

12 hours ago, slimbl said:

protected function assignSupplier()
    {
        $supplierVar = $this->objectPresenter->present($this->supplier);

        $filteredSupplier = Hook::exec(
            'filterSupplierContent',
            array('object' => $supplierVar),
            $id_module = null,
            $array_return = false,
            $check_exceptions = true,
            $use_push = false,
            $id_shop = null,
            $chain = true
        );
        if (!empty($filteredSupplier['object'])) {
            $supplierVar = $filteredSupplier['object'];
        }

        $this->context->smarty->assign(array(
            'supplier' => $supplierVar,
        ));
    }

For your requirement you need to override assignSupplier function by default $supplierVar variable does not have supplier image link. So either you can add it in the same variable or you can create a new smarty variable for the image link.

I can give you code for it if you need it.

And for overriding you need to do that in the override folder in your prestashop installation directory. You can take help of documentation link given by JBW.

On 2/26/2019 at 3:38 PM, JBW said:

There is further information in Presta docu (it's in module chapter, but no module required if you do it in your override folder directly)

https://devdocs.prestashop.com/1.7/modules/concepts/overrides/#class-controller-override

Feel free to contact if you need help with it.

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

Thank you @Apar

Indeed, I think that I see the problem, but unfortunatly, I dont see how to resolve it.

Could you tell me please how to add the supplier image link to $supplierVar variable. 

For sure, if you could give me the code as you proposed, it will be great.

In advance thank you.

Sbl

 

 

Link to comment
Share on other sites

Step 1 ->  Create a file Named SupplierController.php in the location "PRESTASHOP_ROOT/override/controllers/front/listing/"

Step 2 ->  Copy the code and paste it

<?php
/**
 * 2007-2017 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 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:
 * https://opensource.org/licenses/OSL-3.0
 * 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-2017 PrestaShop SA
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 */
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierProductSearchProvider;

class SupplierController extends SupplierControllerCore
{

    /**
     * Assign template vars if displaying one supplier.
     */
    protected function assignSupplier()
    {
        $supplierVar = $this->objectPresenter->present($this->supplier);
        $supplierImageLink = $this->context->link->getSupplierImageLink($supplier['id_supplier'], 'small_default');
        $filteredSupplier = Hook::exec(
            'filterSupplierContent',
            array('object' => $supplierVar),
            $id_module = null,
            $array_return = false,
            $check_exceptions = true,
            $use_push = false,
            $id_shop = null,
            $chain = true
        );
        if (!empty($filteredSupplier['object'])) {
            $supplierVar = $filteredSupplier['object'];
        }

        $this->context->smarty->assign(array(
            'supplier' => $supplierVar,
            'supplier_image' => $supplierImageLink,
        ));
    }

}

Step 3 ->  Use supplier_image variable in the file /themes/YOUR_THEME/templates/catalog/listing/supplier.tpl to get image of supplier. For Example

{block name='product_list_header'}
  <h1>{l s='List of products by supplier %s' sprintf=[$supplier.name] d='Shop.Theme.Catalog'}</h1>
  <div id="supplier-description">{$supplier.description nofilter}</div>
  <img src="{supplier_image}" alt="{$supplier.name}">
{/block}

Step 4 -> Delete class_index.php file in var/cache/dev/ and var/cache/prod/ folders

  • Like 1
Link to comment
Share on other sites

@Apar

Thank you really much for you answer and the time you gave to write the code. Really much appreciated.

I did all you adviced but it looks that something goes wrong because I receive a 500 error when I try the supplier page. 

The problem comes maybe from the fact that there was no "listing"  folder in "/override/controllers/front/"... I created and pasted  in it the SupplierController.php i just created.

Do you think it comes from there or it's somewhere elese?

Again thank you very much for your help.

Sbl

Link to comment
Share on other sites

@Apar

Here below the error code of the page .. Looks that the override is not taken under consideration

Syntax error in template "file:/homepages/33/d724684479/htdocs/Ghost/themes/jakiro/templates/catalog/listing/supplier.tpl" on line 30 "<img src="{supplier_image}" alt="{$supplier.name}">" unknown tag 'supplier_image'

Thank you in advance

Sbl

Link to comment
Share on other sites

13 minutes ago, slimbl said:

The problem comes maybe from the fact that there was no "listing"  folder in "/override/controllers/front/"... I created and pasted  in it the SupplierController.php i just created.

You need to create "listing" folder then paste your SupplierController.php inside it

Did you delete class_index.php after doing all this?

Link to comment
Share on other sites

That's what I did.. And I deleted also the class_index.php

 

But reading your message, I tried again to delete class_index.php.. And looks that i did something wrong because my BO isn't anymore accessible (when the FO is still working)

I try to restore yesterday cache folders and give you more info.

thank you for your help.

Sbl

Link to comment
Share on other sites

OK. 

I started by creating the folder "listing" and pasted into it the SupplierController.php

image.png.2faaf00d7888e54ce057b25820e96503.png

The code inside is the one you adviced

image.png.059a70da30e99a9f4aac35bc5bd8af61.png

Then I changed the code in the tpl file

image.png.6f10f85f25ffa715f4551dbf63b52da1.png

And finally i ereased the cache files

image.png.c09ae106f4133f8d30ff992e2613ba66.png

Please tell me if i made someting wrong. Thank you

Link to comment
Share on other sites

Looks taht the photos are not clear.. I remade them

I started by creating the folder "listing" and pasted into it the SupplierController.php

1.jpg.d562311aa777ed29ba6231e1858ab97c.jpg

The code inside is the one you adviced

2.thumb.jpg.4d3156b37146b8e344d4799830683155.jpg

 

Then I changed the code in the tpl file

3.thumb.jpg.c2a84df7ebf5dc86cad931795037782e.jpg

 

And finally i ereased the cache files4.jpg.c41e9f86eae8d3bb10e97076a3770f07.jpg

Link to comment
Share on other sites

On 7/27/2019 at 9:20 PM, slimbl said:

Syntax error in template "file:/homepages/33/d724684479/htdocs/Ghost/themes/jakiro/templates/catalog/listing/supplier.tpl" on line 30 "<img src="{supplier_image}" alt="{$supplier.name}">" unknown tag 'supplier_image'

You are missing the $ in {supplier_image}

  • Thanks 1
Link to comment
Share on other sites

So I have a complete solution for this now.

Corrected SupplierController.php

<?php
/**
 * 2007-2017 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 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:
 * https://opensource.org/licenses/OSL-3.0
 * 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-2017 PrestaShop SA
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 */
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Supplier\SupplierProductSearchProvider;

class SupplierController extends SupplierControllerCore
{

    /**
     * Assign template vars if displaying one supplier.
     */
    protected function assignSupplier()
    {
        $supplierVar = $this->objectPresenter->present($this->supplier);
        $supplierImageLink = $this->context->link->getSupplierImageLink($this->supplier->id, 'small_default');
        $filteredSupplier = Hook::exec(
            'filterSupplierContent',
            array('object' => $supplierVar),
            $id_module = null,
            $array_return = false,
            $check_exceptions = true,
            $use_push = false,
            $id_shop = null,
            $chain = true
        );
        if (!empty($filteredSupplier['object'])) {
            $supplierVar = $filteredSupplier['object'];
        }

        $this->context->smarty->assign(array(
            'supplier' => $supplierVar,
            'supplier_image' => $supplierImageLink,
        ));
    }

}

Corrected Template supplier.tpl

{block name='product_list_header'}
  <h1>{l s='List of products by supplier %s' sprintf=[$supplier.name] d='Shop.Theme.Catalog'}</h1>
  <div id="supplier-description">{$supplier.description nofilter}</div>
  <img src="{$supplier_image}" alt="{$supplier.name}">
{/block}

And it works 

Screenshot_3.png.8a9d46e2c31db33e894f0b0958cdc05d.png

Link to comment
Share on other sites

1 hour ago, slimbl said:

it shows the image but it's rooting to the default image, as by your screen

It's showing default image because i did not upload any image for my supplier. If you upload a image for supplier it will show that image.

Link to comment
Share on other sites

6 minutes ago, Apar said:

It's showing default image because i did not upload any image for my supplier. If you upload a image for supplier it will show that image.

@apar

Unfortunately, even in my website, where i have images/logos for suppliers, it shows the same default image. I also regenerated the images but no success..

thanks and sorry for disturbing you and asking that much

Link to comment
Share on other sites

Try Removing "small_default" from $supplierImageLink = $this->context->link->getSupplierImageLink($this->supplier->id); this will give the url of original image. And do remove your cache. 

Link to comment
Share on other sites

8 minutes ago, Apar said:

Try Removing "small_default" from $supplierImageLink = $this->context->link->getSupplierImageLink($this->supplier->id); this will give the url of original image. And do remove your cache. 

I tried... but unfortunatly, still the same. in your website, it workes?
 

Link to comment
Share on other sites

11 minutes ago, Apar said:

It works for me. Check the screen recording. I'll also include a copy of my modified files. SupplierController.php and supplier.tpl maybe this could help you a litttle.

 

Screen Recording (30-07-2019 01-26-22).wmv

Again thank you very much. I will continue trying to find from where comes the error and make you know if i find. For now it still not working..

Link to comment
Share on other sites

6 minutes ago, slimbl said:

Again thank you very much. I will continue trying to find from where comes the error and make you know if i find. For now it still not working..

MIRACLE... It worked... I changed nothing but I emptied again the cache form the BO... and it worked
@Apar You re really kind and many thanks

Link to comment
Share on other sites

Great that it worked at last for you. So this is only a suggestion I noticed you have started using supplier original image not the version generated by prestashop. So you are displaying a 380X380 image but sending a 561x561 Image instead. its not good for optimization. So you can create a image setting for 380x380 then use that for displaying images. 

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Apar said:

Great that it worked at last for you. So this is only a suggestion I noticed you have started using supplier original image not the version generated by prestashop. So you are displaying a 380X380 image but sending a 561x561 Image instead. its not good for optimization. So you can create a image setting for 380x380 then use that for displaying images. 

Oww. It's really nice of you that you made attention of this. I will corrected indeed. A huge thanks.

Link to comment
Share on other sites

@Apar  I checked the images and, as i understood, the 561x561 size looks to be usefull for the smaller screens where the image is full width.. so I think that's why is larger then the 380x380 that we see on 'normal' screens.. If I m wrong?

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