Show email on customer layout

Discussion in 'General discussions' started by Torsten Högel, Jun 21, 2019.

  1. Torsten Högel

    Torsten Högel New Member

    Joined:
    Jun 21, 2019
    Messages:
    15
    Likes Received:
    1
    S.E:
    2019-12-20 08:03:47
    L.T:
    Extended
    L.C:
    1
    Hey there,

    I wanted to embed Intercom into the customer layout.

    I used the code:

    <?php echo ($fullName = Yii::app()->customer->getModel()->getFullName()) ? CHtml::encode($fullName) : Yii::t('app', 'Welcome');?>

    for inputting the name into the variable, but I can't seem to get the email shown in a similar way... do I have to create a ruction, or is there an easier way?

    P.S.: I've searched in the profile layout because the email of the customer is shown there, but with no luck...
     
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,176
    Likes Received:
    2,362
    @Torsten Högel - The email should be available at:

    PHP:
    Yii::app()->customer->getModel()->email;
    Did you try it like this?
    Maybe share the code?
     
    Torsten Högel likes this.
  3. Torsten Högel

    Torsten Högel New Member

    Joined:
    Jun 21, 2019
    Messages:
    15
    Likes Received:
    1
    S.E:
    2019-12-20 08:03:47
    L.T:
    Extended
    L.C:
    1
    That worked perfect! Thank you. The code I use is: (If anybody want to use it change YOURAPPID to the app id of your intercom project.)

    <script>
    window.intercomSettings = {
    app_id: "YOURAPPID",
    name: "<?php echo Yii::app()->customer->getModel()->getFullName();?>", // Full name
    email: "<?php echo Yii::app()->customer->getModel()->email;?>" // Email address
    };
    </script>
    <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/YOURAPPID';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();</script>
     
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,176
    Likes Received:
    2,362
    @Torsten Högel - i hope you used a hook to add that and you haven't added it into the core files, right ? :D
     
  5. Torsten Högel

    Torsten Högel New Member

    Joined:
    Jun 21, 2019
    Messages:
    15
    Likes Received:
    1
    S.E:
    2019-12-20 08:03:47
    L.T:
    Extended
    L.C:
    1
    I think I did
     
  6. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,176
    Likes Received:
    2,362
    Ok, so don't do that.
    Create a file called init-custom.php in the /apps/ folder and put this into it:
    PHP:
    <?php

    Yii
    ::app()->hooks->addAction('layout_footer_html', function(){
        if (!
    Yii::app()->apps->isAppName('customer') || !Yii::app()->customer->getModel()) {
            return;
        }
        
    ?>
        <script>
        window.intercomSettings = {
        app_id: "YOURAPPID",
        name: "<?php echo Yii::app()->customer->getModel()->getFullName();?>", // Full name
        email: "<?php echo Yii::app()->customer->getModel()->email;?>" // Email address
        };
        </script>
        <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/YOURAPPID';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();</script>
        <?php
    });
    This uses this action hook: https://hooks-docs.mailwizz.com/actions.php?keyword=layout_footer_html which means when you upgrade mailwizz, you'll keep your changes ;)

    Check out the hooks site for more info. But generally speaking, you never edit core files, but do changes using hooks.
     
  7. Torsten Högel

    Torsten Högel New Member

    Joined:
    Jun 21, 2019
    Messages:
    15
    Likes Received:
    1
    S.E:
    2019-12-20 08:03:47
    L.T:
    Extended
    L.C:
    1
    Thank You really much for that ;)
     
  8. Torsten Högel

    Torsten Högel New Member

    Joined:
    Jun 21, 2019
    Messages:
    15
    Likes Received:
    1
    S.E:
    2019-12-20 08:03:47
    L.T:
    Extended
    L.C:
    1
    Short question,
    is there a way to embed the customer_id, because I got the information that you need that for intercom ...
     
  9. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,176
    Likes Received:
    2,362
    @Torsten Högel - of course.
    PHP:
    Yii::app()->customer->getModel()->customer_id;
     
    Torsten Högel likes this.

Share This Page