Customer area menu items

Discussion in 'Extensions' started by twisted1919, Dec 28, 2014.

  1. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,125
    Likes Received:
    2,352
    This simple extension shows how to add one/more menu links in the customer area.
    It is also a good example to learn a bit about mailwizz extension development.

    In order to get started, create a new folder on your desktop, named "customer-area-menu-items".
    In it, create a new file called "CustomerAreaMenuItemsExt.php" and paste following contents:

    PHP:
    <?php defined('MW_PATH') || exit('No direct script access allowed');

    class 
    CustomerAreaMenuItemsExt extends ExtensionInit
    {
        
    // name of the extension as shown in the backend panel
        
    public $name 'Customer area menu items';
      
        
    // description of the extension as shown in backend panel
        
    public $description 'Add a links in the menu from customer area';
      
        
    // current version of this extension
        
    public $version '1.0';

        
    // the author name
        
    public $author 'Your name';
      
        
    // author website
        
    public $website 'http://www.website.com/';
      
        
    // contact email address
        
    public $email 'your.email@domain.com';
      
        
    // in which apps this extension is allowed to run
        
    public $allowedApps = array('customer');

        
    // can this extension be deleted? this only applies to core extensions.
        
    protected $_canBeDeleted true;
      
        
    // can this extension be disabled? this only applies to core extensions.
        
    protected $_canBeDisabled true;

        
    // run the extension, ths is mandatory
        
    public function run()
        {
            
    Yii::app()->hooks->addFilter('customer_left_navigation_menu_items', array($this'_addMenuItem'));
        }
      
        public function 
    _addMenuItem(array $items = array())
        {
            
    $newItems = array();
            
    $newItem  = array(
                
    'name'      => Yii::t('app''Articles'),
                
    'icon'      => 'glyphicon-book',
                
    'active'    => 'api_keys',
                
    'route'     => Yii::app()->apps->getAppUrl('frontend''articles'),
            );
          
            foreach (
    $items as $name => $value) {
                if (
    $name == 'api-keys') {
                    
    $newItems['articles'] = $newItem;   
                }
                
    $newItems[$name] = $value;
            }
          
            if (!isset(
    $newItems['articles'])) {
                
    $newItems['articles'] = $newItem;
            }
          
            return 
    $newItems;
        }
    }
    Then simply zip the folder and go to your mailwizz app in Backend -> Extend -> Extensions and upload it then after upload, make sure you enable it.
    After the above steps, login as a customer and you should see a new menu link that will point the customers to the articles area of your application.
     
    Last edited: Dec 28, 2014
    Darryl likes this.
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,125
    Likes Received:
    2,352
    Just to add on the above, if instead you need to remove a menu item, the code should look like:
    PHP:
    <?php defined('MW_PATH') || exit('No direct script access allowed');

    class 
    CustomerAreaMenuItemsExt extends ExtensionInit
    {
        
    // name of the extension as shown in the backend panel
        
    public $name 'Customer area menu items';

        
    // description of the extension as shown in backend panel
        
    public $description 'Add a links in the menu from customer area';

        
    // current version of this extension
        
    public $version '1.0';

        
    // the author name
        
    public $author 'Your name';

        
    // author website
        
    public $website 'http://www.website.com/';

        
    // contact email address
        
    public $email 'your.email@domain.com';

        
    // in which apps this extension is allowed to run
        
    public $allowedApps = array('customer');

        
    // can this extension be deleted? this only applies to core extensions.
        
    protected $_canBeDeleted true;

        
    // can this extension be disabled? this only applies to core extensions.
        
    protected $_canBeDisabled true;

        
    // run the extension, ths is mandatory
        
    public function run()
        {
            
    Yii::app()->hooks->addFilter('customer_left_navigation_menu_items', array($this'_removeMenuItem'));
        }

        public function 
    _removeMenuItem(array $items = array())
        {
               
    $removeThese = array('api-keys''some-other-item');

               foreach (
    $removeThese as $item) {
                       if (isset(
    $items[$item])) {
                            unset(
    $items[$item]);
                       }
               }
           
               return 
    $items;
        }
    }
    If for some crazy reason you need to remove all menu items, you should simple do:
    PHP:
    public function _removeMenuItem(array $items = array())
    {
           return array();
    }
    Please note that if any extension will add new menu items AFTER your extension, then those items will still be shown.
    If you want to make sure your extension runs as the last one, just make sure when you attach the hook, you put it a very low priority, like:
    PHP:
    public function run()
    {
            
    Yii::app()->hooks->addFilter('customer_left_navigation_menu_items', array($this'_removeMenuItem'), 100);
    }
     
  3. Kenntkenner

    Kenntkenner New Member

    Joined:
    Mar 24, 2015
    Messages:
    9
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Hi there,

    I hope its not a big dumb question, I'm not firm in yii framework. Is it possible to display this inside the customer-section? On article page is no navigation or a link to return to the customer area.

    Best regards,
    Steve
     
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,125
    Likes Received:
    2,352
    @Kenntkenner - That's the place where it will be shown actually, you just have to install it in admin/backend area first and after that, customers will see the link.
    As for no navigation in articles page, that's true, there's no link to get the user back to customer area, except if he clicks on the top left side logo.
    Not sure if we need an actual link when in frontend area given that it's pretty easy to get back in customer area and if you open those pages from customer area, they open in a new tab anyway.
     
  5. Jamie Whittingham

    Jamie Whittingham Active Member

    Joined:
    Jun 27, 2015
    Messages:
    288
    Likes Received:
    45
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    9
    where in this code would I give an external url like say I wanted to link to our facebook page?

    thanks
     
  6. Jamie Whittingham

    Jamie Whittingham Active Member

    Joined:
    Jun 27, 2015
    Messages:
    288
    Likes Received:
    45
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    9
    scratch that, I found where to set my own link, next question .... how do I set it to topen in a new window and not the parent ...

    thanks
     
  7. Rob

    Rob Active Member

    Joined:
    Feb 17, 2015
    Messages:
    404
    Likes Received:
    99
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    You will need to use the target="_new" attribute wherever you put your new link.
     
  8. Justin Loeber

    Justin Loeber New Member

    Joined:
    May 26, 2015
    Messages:
    3
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    I have followed the instructions posted here. When I upload the zip archive, the application says "extension uploaded successfully" but nothing shows up in the custom extensions list, even after I click "refresh." I found the "extensions" directory on the server and can confirm that my files are on the server. Can you suggest a reason why the extensions aren't showing up in the list, even though they are on the server? Thank you.
     
  9. Rob

    Rob Active Member

    Joined:
    Feb 17, 2015
    Messages:
    404
    Likes Received:
    99
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Check the extension folder has 777 for permissions.
     
  10. Justin Loeber

    Justin Loeber New Member

    Joined:
    May 26, 2015
    Messages:
    3
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    It turns out the files are owned by a different server user? Those files are owned by apache:apache, which is not the user for the account running MWZ. Must be some issue with the upload feature in your app? can I FTP an extension directly into that directory or does it have to be placed there by the upload process built into the code?
     
  11. Justin Loeber

    Justin Loeber New Member

    Joined:
    May 26, 2015
    Messages:
    3
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    I've tried both: 1.) FTPing my extension folder directly to the /extensions directory; and 2.) using the "upload" tool in the extensions area in the backend. Neither method works. The files do end up on the server, but they do NOT appear in the extensions list. Permissions are set to 777.
     
  12. Jeff Guynn

    Jeff Guynn Member

    Joined:
    Jul 11, 2015
    Messages:
    73
    Likes Received:
    14
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    I followed the above example, substituting 'domains' for 'articles', and using an appropriate icon. After completing the task, my customer area now has a link, but it's a dead link. Leads to 404. Is the code supplied above complete?

    I see Jamie Whittingham had a similar question about how to insert a desired link when wanting to point to his Facebook page. Apparently he figured it out, but I have not.

    How do I finish the job of pointing my customer "Domains" menu link to the right destination?
     
  13. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,125
    Likes Received:
    2,352
    @Jeff Guynn - What's wrong with this approach:
    PHP:
    public function _addMenuItem(array $items = array())
    {
        
    $newItems = array();
        
    $_newItems  = array(
            array(
                
    'name'      => Yii::t('app''GOOGLE'),
                
    'icon'      => 'glyphicon-book',
                
    'active'    => null,
                
    'route'     => 'http://www.google.com',
                
    'linkOptions' => array('target' => '_blank'),
            ),
            array(
                
    'name'      => Yii::t('app''YAHOO'),
                
    'icon'      => 'glyphicon-book',
                
    'active'    => null,
                
    'route'     => 'http://www.yahoo.com',
                
    'linkOptions' => array('target' => '_blank'),
            )
        );
        foreach (
    $items as $name => $value) {
            if (
    $name == 'api-keys') {
                foreach (
    $_newItems as $index => $itm) {
                    
    $newItems['custom-'.$index] = $itm;
                } 
            }
            
    $newItems[$name] = $value;
        }
        if (!isset(
    $newItems['custom-0'])) {
            foreach (
    $_newItems as $index => $itm) {
                
    $newItems['custom-'.$index] = $itm;
            } 
        }
        return 
    $newItems;
    }
    ?
     
  14. Jeff Guynn

    Jeff Guynn Member

    Joined:
    Jul 11, 2015
    Messages:
    73
    Likes Received:
    14
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    @twisted1919 - Thanks for that. I'm still unclear how to point my 'domains' link correctly. When I'm logged into both customer and backend, the link mailwizz.tranzware.com/customer/index.php/sending-domains/index, it just redirects to the following: http://mailwizz.tranzware.com/customer/index.php/dashboard/index

    Am I supposed to be tweaking the backend settings so the customer side can have access to this link? Please advise.
     
  15. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,125
    Likes Received:
    2,352
    Yes, from customer group settings or from backend -> settings -> customers, you have to give the customer permissions to add sending domains.
     
  16. Jeff Guynn

    Jeff Guynn Member

    Joined:
    Jul 11, 2015
    Messages:
    73
    Likes Received:
    14
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    After following the instructions above, when I upload the zip folder my screen went solid white (unresponsive). After using FTP to delete the uploaded 'customer-area-menu-items' folder, a refresh restores my site. What's going on here? Note: I originally uploaded one version of the file, activated it, and it worked fine. Then I deleted that file to replace it with an edited version of the same (some minor tweaks). and this second upload is the one giving me grief.
     
  17. Rob

    Rob Active Member

    Joined:
    Feb 17, 2015
    Messages:
    404
    Likes Received:
    99
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    I had some similar behaviour, clearing the cache in most cases resolved the issue. You also have to be careful with some of the tweaking. Make one or two changes at a time and see what happens. You might want to try editing the extension files on the server as it is quicker to see which tweak is causing the problem.
     
    Jeff Guynn likes this.
  18. Mattias

    Mattias New Member

    Joined:
    Jan 13, 2015
    Messages:
    16
    Likes Received:
    3
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Is there a way to move the new links to another position or just push them to the top using this approach?
     
  19. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,125
    Likes Received:
    2,352
    @Mattias - That would be possible by simply ordering the array items with array sorting functions provided by php.
     
    Mattias likes this.
  20. prazze

    prazze New Member

    Joined:
    Feb 8, 2016
    Messages:
    5
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Dear @twisted1919
    i follow the first post with success.

    but when i click "Article" menu, the left sidebar is gone,
    and i click back button to back to member area.

    how to make >> when i clicked the article menu, sidebar still there...

    Regards,
    prazze

    ===
    I use the search, and it didn't bite.
     

Share This Page