Jump to content

How to create a new Front Controller?


Florian

Recommended Posts

Hi everyone,

 

I would like to know how to implement another Front controller in PS 1.7, do you have any guidelines?

 

Let's say we have a new "Employee" object that could login + retrieve his lost password + access his own backoffice. He cannot create an account, it would be done in PS main BO by employees. He's not an employee because he will have access to the main PS backoffice, and has its own database table+fields. Let call this new type of user the "Manager".

 

I created a new folder /manager with the bare minimum : /manager/.htaccess which redirect to /manager/index.php (same as in /admin-dev), with the following code:

 

<?php
// taken from /admin-dev/index.php
if (!defined('_PS_COACH_DIR_')) {
  define('_PS_COACH_DIR_', getcwd()); // utilise dans Dispatcher::construct pour determiner le type de front controller
}
// taken from /index.php
require(dirname(__FILE__).'/../config/config.inc.php');
Dispatcher::getInstance()->dispatch();

 

and then override Dispatcher: /override/classes/Dispatcher.php

<?php
class Dispatcher extends DispatcherCore {
  const FC_MANAGER = 999;

  public function __construct(){
    if(defined('_PS_COACH_DIR_')){
      $this->front_controller = self::FC_MANAGER;
      $this->controller_not_found = 'managernotfound';
      die('you hit the MANAGER front controller (from Dispatcher)');
    }
    // add custom routes
    $this->default_routes['managerroute1'] = [
      'controller' => 'managerroute1',
      'rule' => 'managerroute1',
      'keywords' => [],
    ];
    parent::__construct();
  }
}

Every request in https://my_domain.com/coach now displays "you hit the MANAGER front controller...", so it's great! I can also have https://manager.my_domain.com  to point on /coach

But now I have a few questions:

- how to create $context->manager? Where's created $context->employee to have an example??

- what would be the PHP Object class? A class that extends Employee?

- how to redirect User to login if he is not connected?

- how to benefit to already created classes/controllers such as login + lost password + 404 + 500 ?

- where would be located the theme files? Under /manager/themes/default/page.tpl? Where is the theme folder defined?

 

Thanks a lot!

Florian

 

Edit: I do not wish to create a new Employee group because the Manager would have totally different fields. But maybe is it the easiest option??

Edited by Florian (see edit history)
Link to comment
Share on other sites

After your question I have more questions than you :)

if you want create a Front Controller you don't need override dispatcher no create a separate directory ( but i am not clear about you requirement)

 

You can develop a module with your features where check the if the user is valid or something like that

 

Maybe is not what do you need but

 

Create a module

modmanager

using the structure on the regular module create your front controller

controllers/front

listorders (for put something) now on seo you can set a friendy url

 

* using these you can use all the features already running on Prestashop,

* take a look for example on the orderhistory use a authetication it doesnt work for you because you are using employs but you are going to got the idea how works

* you can keep the looking of your store

 

to create your look inside your module you can use the views/templates/front structure

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Hi guys,

 

thanks for your good answers, but I don’t want to create just 1 page, I want to create a whole new set of pages accessible only by « Managers ».

 

By default, Prestashop has 2 types of users: Customer (table ps_customer, using front controller FC_FRONT) and Employee (table ps_employee, using front controller FC_ADMIN).

 

Customers have their own database fields:

- birthdate, newsletter, etc

 

Employees have their own database fields also:

- roles, profile picture, etc

 

I want to create a new type of user: the Manager, which would have the following fields for example:

- company, city, zip code, some datetimes, some new linked tables, etc

 

He would connect through myprestashop.com/manager

and access pages that only Managers can see, such as myprestashop.com/manager/page1

 

Yoo know what I mean?

 

thanks for your help!

Link to comment
Share on other sites

You can create all the structure inside a module maybe you dont want in these way

 

Look these inside your module

* controller

-> admin / Handles on the backoffice you manager table

-> front / you can put here many controllers like you need for example manager-products you can create your custom filter for you manager

* classes

manager ->  handle your table

 

That if you want handle the store look and easy access to any class inside your project and you dont need mess with the  core code if you try to got all the functionality just call the library you maybe are going to got but is going to take you more time

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...