Customer area menu items

twisted1919

Administrator
Staff member
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:
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);
}
 
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
 
@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.
 
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
 
You will need to use the target="_new" attribute wherever you put your new link.
 
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.
 
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?
 
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.
 
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?
 
@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;
}
?
 
Am I supposed to be tweaking the backend settings so the customer side can have access to this link? Please advise.
Yes, from customer group settings or from backend -> settings -> customers, you have to give the customer permissions to add sending domains.
 
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.
 
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.
 
Is there a way to move the new links to another position or just push them to the top using this approach?
 
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.
 
Back
Top