Jump to content
soundhar

How to create prestashop 1.7 custom module admin menus

Recommended Posts

Posted (edited)

Hi everyone,

I am trying to create a custom module admin menu. 
I need one parent and multiple child menus.

  • Inspiraiton
    • Wall Background
    • Frames
    • Frames Images
    • Menu4
    • etc.,

 

I have used tabs registration. that works for 1 parent and 1 child.

Module name : inspiration

The following code generate

  • Inspiraiton
    • Wall Background

But I am expecting the 

  • Inspiraiton
    • Wall Background
    • Frames

Please tell me how to fix this.

 

Thanks to all :)

$lang = Language::getLanguages();
$tab = new Tab();
$tab->class_name = 'AdminExample';
$tab->module = 'inspiration';
$tab->id_parent = 2;
$tab->position = 6;
$tab->icon = 'photo_size_select_actual';
$tab->parent_class_name = 'AdminExample';
foreach ($lang as $l) {
$tab->name[$l['id_lang']] = $this->l('Inspiration');
}
$tab->add();

$tab = new Tab();
$tab->active = 1;
$tab->class_name = 'AdminExample';
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = "Wall Background";
}
$tab->id_parent = (int)Tab::getIdFromClassName('AdminExample');
$tab->module = $this->name;
$tab->add();

$tab = new Tab();
$tab->active = 1;
$tab->class_name = 'AdminFrames';
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = "Frames";
}
$tab->id_parent = (int)Tab::getIdFromClassName('AdminFrames');
$tab->module = $this->name;
$tab->add();

 

Edited by soundhar (see edit history)

Share this post


Link to post
Share on other sites

Hi....
try this 

$languages = Language::getLanguages(false);

//Main Parent menu
if (!(int) Tab::getIdFromClassName('AdminInspiration')) {
      $parentTab = new Tab();
      $parentTab->active = 1;
      $parentTab->name = array();
      $parentTab->class_name = "AdminInspiration";
      foreach ($languages as $language) {
          $parentTab->name[$language['id_lang']] = 'Inspiration';
      }
      $parentTab->id_parent = 0;
      $parentTab->module = '';
      $parentTab->add();
}

//Sub menu code
if (!(int) Tab::getIdFromClassName('AdminWallBackground')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminWallBackground";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Wall Background');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}
if (!(int) Tab::getIdFromClassName('AdminFrames')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminFrames";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Frames');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}

Thanks
 

Share this post


Link to post
Share on other sites
Posted (edited)

Hi Nishith,

Sorry for the late reply. 

Your solution works great! Thank you so much for that. 
But is there any option to move the menu to top after SELL?
1180072009_ScreenShot2019-06-11at11_15_54AM.thumb.png.8a305ed7bd458dadead43be7ecab448a.png

I am working on the module menu pages. I have one issue. I searched about it but could not find any solution.
I am trying to create default bootstrap style admin panel.

When install the module. I set the bootstrap to true. but when i create the menu pages. I see nobootstrap class added to the id content. please check the screenshots.

$this->name = 'inspiration';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'soundhar';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->bootstrap = true;

parent::__construct();

$this->displayName = $this->l('Gallery Inspiration');
$this->description = $this->l('This module allows create customers own gallery.');

$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
frames.tpl

<div class="row">
  <div class="col-lg-12">
      <div class="panel">
          <h1>test</h1>
      </div>
  </div>
</div>

Frames Menu Page
711732425_ScreenShot2019-06-11at11_21_09AM.thumb.png.9853ee4b64f79036a634f925589b1932.png

Frames Menu Code
400357254_ScreenShot2019-06-11at11_21_50AM.png.89065a557530e458c0f381800beeffad.png


so if manually replace nobootstrap to bootstrap it works as i expected. 
1396087576_ScreenShot2019-06-11at11_23_17AM.thumb.png.dcd060a5e2565a74bac5c522801dd109.png

 

is there any solution to remove the nobootstrap class?

 

Thanks a lot :)

 

Edited by soundhar
added images (see edit history)

Share this post


Link to post
Share on other sites

Hi

I added the following code, after that bootstrap classes is loaded. is that correct way to do that?

public function init()
{
    $this->context->controller->addJquery();
    $this->context->controller->bootstrap=true;
    parent::init();
}

 

Share this post


Link to post
Share on other sites

hi..

Sorry i am not understand where you have added that code ?

Thanks

Share this post


Link to post
Share on other sites
On 6/6/2019 at 10:42 AM, Nishith said:

Hi....
try this 


$languages = Language::getLanguages(false);

//Main Parent menu
if (!(int) Tab::getIdFromClassName('AdminInspiration')) {
      $parentTab = new Tab();
      $parentTab->active = 1;
      $parentTab->name = array();
      $parentTab->class_name = "AdminInspiration";
      foreach ($languages as $language) {
          $parentTab->name[$language['id_lang']] = 'Inspiration';
      }
      $parentTab->id_parent = 0;
      $parentTab->module = '';
      $parentTab->add();
}

//Sub menu code
if (!(int) Tab::getIdFromClassName('AdminWallBackground')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminWallBackground";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Wall Background');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}
if (!(int) Tab::getIdFromClassName('AdminFrames')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminFrames";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Frames');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}

Thanks
 

Hi,

I added the reply to you but its in hidden status. I don't know where to enable to it. 
Admin will verify the post if we add any images? 

Your solution works great! Thank you so much for that. 
But is there any option to move the menu to top after SELL?

 

Share this post


Link to post
Share on other sites

Hi Nishith,

Sorry for the late reply. 

Your solution works great! Thank you so much for that. 
But is there any option to move the menu to top after SELL?

https://ibb.co/mNhQGqS

 

Share this post


Link to post
Share on other sites
On 6/11/2019 at 12:17 PM, soundhar said:

But is there any option to move the menu to top after SELL?

 

Hi, Replace

$parentTab->id_parent = 0;

with 

$parentTab->id_parent = (int)Tab::getIdFromClassName('SELL');

Thanks

Share this post


Link to post
Share on other sites
On 6/6/2019 at 2:12 AM, Nishith said:

Hi....
try this 


$languages = Language::getLanguages(false);

//Main Parent menu
if (!(int) Tab::getIdFromClassName('AdminInspiration')) {
      $parentTab = new Tab();
      $parentTab->active = 1;
      $parentTab->name = array();
      $parentTab->class_name = "AdminInspiration";
      foreach ($languages as $language) {
          $parentTab->name[$language['id_lang']] = 'Inspiration';
      }
      $parentTab->id_parent = 0;
      $parentTab->module = '';
      $parentTab->add();
}

//Sub menu code
if (!(int) Tab::getIdFromClassName('AdminWallBackground')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminWallBackground";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Wall Background');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}
if (!(int) Tab::getIdFromClassName('AdminFrames')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminFrames";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Frames');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}

Thanks
 

Hi, i'm new on prestashop development, what file do you put this code in? I'm trying to put   ps_imageslider and ps_banner on menu. Any help will be appreciated...  :)

Share this post


Link to post
Share on other sites
7 hours ago, franklin_mbf2 said:

Hi, i'm new on prestashop development, what file do you put this code in? I'm trying to put   ps_imageslider and ps_banner on menu. Any help will be appreciated...  :)

this code put inside module install method 

Thanks

Share this post


Link to post
Share on other sites

Hi @Nishith , please tell mi if I want to have this structure:

Module

         sub-menu1

         sub-menu2

 

How many admin controller I must create ?  

Share this post


Link to post
Share on other sites

Hi @pawelszulc

You need create each admin controller foe every sub menu

If you need 2 submenu then you need to create 2 admin controller.

Thanks

Share this post


Link to post
Share on other sites

Yes need to assign parent tab menu

Like This

private function _createTab()
{
    $response = true;
    // First check for parent tab

    $parentTabID = Tab::getIdFromClassName('AdminStMenu');
    if ($parentTabID) {
        $parentTab = new Tab($parentTabID);
    } else {
        $parentTab = new Tab();
        $parentTab->active = 1;
        $parentTab->name = array();
        $parentTab->class_name = "AdminStMenu";
        foreach (Language::getLanguages() as $lang){
            $parentTab->name[$lang['id_lang']] = "SpacingTech";
        }
        $parentTab->id_parent = 0;
        $parentTab->module = $this->name;
        $response &= $parentTab->add();
    }
// Check for parent tab2
    $parentTab_2ID = Tab::getIdFromClassName('AdminStMenu2');
    if ($parentTab_2ID) {
        $parentTab_2 = new Tab($parentTab_2ID);
    }
    else {
        $parentTab_2 = new Tab();
        $parentTab_2->active = 1;
        $parentTab_2->name = array();
        $parentTab_2->class_name = "AdminStMenu2";
        foreach (Language::getLanguages() as $lang) {
            $parentTab_2->name[$lang['id_lang']] = "SpacingTech Theme Configure";
        }
        $parentTab_2->id_parent = $parentTab_2->id;
        $parentTab_2->module = $this->name;
        $response &= $parentTab_2->add();
    }
    // Created tab
    $tab = new Tab();
    $tab->active = 1;
    $tab->class_name = "Adminstmegamenu";
    $tab->name = array();
    foreach (Language::getLanguages() as $lang){
        $tab->name[$lang['id_lang']] = "Configure Megamenu";
    }
    $tab->id_parent = $parentTab_2->id;
    $tab->module = $this->name;
    $response &= $tab->add();
    return $response;
}

For Live Demos You can check our demo URL

https://preshtaexpert.com/oro-landing/

 

 

 

Share this post


Link to post
Share on other sites
2 hours ago, Nishith said:

Hi @pawelszulc

You need create each admin controller foe every sub menu

If you need 2 submenu then you need to create 2 admin controller.

Thanks

Ok, but the parent tab is not clickable , and my questions is -> do I have to create admin controller for parent tab ?

Edited by pawelszulc (see edit history)

Share this post


Link to post
Share on other sites
4 hours ago, pawelszulc said:

Ok, but the parent tab is not clickable , and my questions is -> do I have to create admin controller for parent tab ?

The parent link will auto get first child link

Share this post


Link to post
Share on other sites
5 hours ago, pawelszulc said:

Hi @Nishith why create a controller for prarent tab if is not clickable ?

You need to create a ony submenu controller not need to create a parent menu controller

Share this post


Link to post
Share on other sites

@Nishith so, 

$tab = new Tab();

        $tab->active = 1;

        $tab->class_name = "AdminSubMenu";

        $tab->name = array();

        foreach (Language::getLanguages(true) as $lang) {

            $tab->name[$lang['id_lang']] = 'Sub menu';

        }

        $tab->id_parent = (int)Tab::getIdFromClassName('< What I should add here, since I don't have to create a parent controller');

        $tab->module = $this->name;

        $tab->add();

Edited by pawelszulc (see edit history)

Share this post


Link to post
Share on other sites

@pawelszulc

If you need create your own custom parent tab then you need create a paraen tab class. For example like this

$languages = Language::getLanguages(false);

//Main Parent menu
if (!(int) Tab::getIdFromClassName('AdminInspiration')) {
      $parentTab = new Tab();
      $parentTab->active = 1;
      $parentTab->name = array();
      $parentTab->class_name = "AdminInspiration";
      foreach ($languages as $language) {
          $parentTab->name[$language['id_lang']] = 'Inspiration';
      }
      $parentTab->id_parent = 0;
      $parentTab->module = '';
      $parentTab->add();
}

//Sub menu code
if (!(int) Tab::getIdFromClassName('AdminWallBackground')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminWallBackground";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Wall Background');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}
if (!(int) Tab::getIdFromClassName('AdminFrames')) {
      $parentTabID = Tab::getIdFromClassName('AdminInspiration');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminFrames";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Frames');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}


if you need create only submenu inside the prestashop native menu then you need to use pretsashop class.This example create submenu inside the Module tab.

$languages = Language::getLanguages(false);

//Main Parent menu
//Sub menu code
if (!(int) Tab::getIdFromClassName('AdminWallBackground')) {
      $parentTabID = Tab::getIdFromClassName('AdminParentModulesSf');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminWallBackground";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Wall Background');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}
if (!(int) Tab::getIdFromClassName('AdminFrames')) {
      $parentTabID = Tab::getIdFromClassName('AdminParentModulesSf');
      $parentTab = new Tab($parentTabID);

      $tab = new Tab();
      $tab->active = 1;
      $tab->class_name = "AdminFrames";
      $tab->name = array();
      foreach ($languages as $language) {
          $tab->name[$language['id_lang']] = $this->l('Frames');
      }
      $tab->id_parent = $parentTab->id;
      $tab->module = $this->name;
      $tab->add();
}

See here
https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/tabs/

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More