2

How to show different logo when the user is logged in?

7
  • follow this answer and in helper check customer is login or not then pass logo path as per your need
    – Piyush
    Commented Jan 5, 2018 at 16:25
  • can you give me more details please Commented Jan 5, 2018 at 16:29
  • what more details you need? if you follow that answer you will achieve what you need with little modifications
    – Piyush
    Commented Jan 5, 2018 at 16:30
  • so i replace <arguments> <argument name="logo_file" xsi:type="string">images/logo.png</argument> <argument name="logo_img_width" xsi:type="number">192</argument> <!--<argument name="logo_img_height" xsi:type="number">50</argument>--> </arguments> with <argument name="logo_file" xsi:type="helper" helper="Namespace\ModuleName\Helper\Data::getLogoImage"></argument> where i can find helper file? Commented Jan 5, 2018 at 16:35
  • 1
    Sorry friend I am little bit busy, will surely help you when I get some time.
    – Piyush
    Commented Jan 5, 2018 at 16:51

1 Answer 1

3

You can set different logo while customer is logged in using a helper method, You have to Create a custom module for this.

In your layout you have to pass helper method for logo path,By adding below code in file

Magento_Theme/layout/default.xml

<argument name="logo_file" xsi:type="helper" helper="Namespace\ModuleName\Helper\Data::getLogoImage"></argument>

After that in your modules helper file you have to add below code

<?php

    namespace Namespace\ModuleName\Helper;

    class Data extends \Magento\Framework\App\Helper\AbstractHelper
    {
        protected $_request;
        protected $_session;

        public function __construct
        (
            \Magento\Framework\App\Request\Http $request,
            \Magento\Customer\Model\Session $session
        ) {
            $this->_request = $request;
            $this->_session = $session;
        }

        public function getLogoImage()
        {
            if ($this->_session->isLoggedIn()) {
                $logo =  'path/to/logo/for/logged_in/customer.png';
            } else {
                $logo = 'path/to/logo/for/guest/customer.png';
            }

            return $logo;
        }
    } 

Note: Change Namespace and ModuleName based on your custom Module

5
  • What if the logo is set in the admin?
    – Ben Crook
    Commented Jan 8, 2018 at 13:56
  • @BenCrook in that case we have to replace logo path with storeConfig value
    – Piyush
    Commented Jan 8, 2018 at 15:14
  • is there a step by step procedure easy to use to achieve this objective? Commented Jan 10, 2018 at 16:08
  • @Piyush Can you please explain how we can call it from logo.phtml or through block, and where to define this argument inside the block or some refrenceBlock? Thankyou
    – JN_newbie
    Commented May 15, 2018 at 12:17
  • @Piyush I have done it through using the helper object in logo.phtml file.
    – JN_newbie
    Commented May 15, 2018 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.