Jump to content

B2B - Filtering the Employee View


DrGren

Recommended Posts

Dear fellow Prestashoppers!

 

I have this situation:

 

I am constructing a B2B site where on the one hand I have a provider of office material.

On the other hand there is a large corporation with many offices spread around the country.

Within the corporation there are several companies.

Each of the offices belong to one of these companies.

Every company has a purchasing manager that should see his offices, but not the others.

 

So, with respect to the standard installation, I thought that every office should be a customer and a purchasing manager should be a new role in the employee class.

 

I created a new class "Company" and I added it as an attribute to the Customer and to the Employee classes. This way there is a link between an Employee (purchasing manager) and a Customer (office).

 

Now, when a purchasing manager logs in to the ps admin interface he should only see the profiles and the orders of the offices that belong to his company.

 

I understand that I should intervene on the AdminCustomers and the AdminOrders modules. But how? I have no clue.

 

Anybody?

 

Thanks a lot!

Link to comment
Share on other sites

OK... I implemented the following quite nasty solution. I works, but I would be grateful for improvements in terms of elegancy.

 

1. The companies within the corporation are stored in a table ps_company with the following structure

 

id_company

company

 

2. The offices to which the customer belongs are stored in a table ps_agency with the folloing structure

 

id_agency

agency

company (referencing ps_company)

 

3. I modified the ps_employee, adding a field company referencing ps_company

 

4. I modified the ps_customer, adding a field agency referencing ps_agency

 

5. I override the Employee Class, providing a method for retrieving the current employee's company with:

 


public static function getMyCompany($id_employee)
{
 $companies = array();
 $result = Db::getInstance()->ExecuteS('
 SELECT e.`company`
 FROM '._DB_PREFIX_.'employee e
 WHERE e.`id_employee` = '.$id_employee);
 foreach ($result AS $company)
   $companies[] = $company['company'];
 return $companies[0];
}

 

6. Then I modified the AdminCustomer.php with the following declarations in the constructor:



$myCompany = Employee:: getMyCompany($cookie->id_employee);
$this->_filter = 'AND a.`agency` IN (SELECT ag.id_agency from '._DB_PREFIX_.'agency ag where ag.company = '.$myCompany.')';

 

 

This will display only the customers who belong to the same company to which the current logged in employee does.

 

Any suggestions for improvement to the code would be much appreciated.

 

Cheers!

 

Henrik

Link to comment
Share on other sites

  • 1 month later...

Hi Henrik

Thank you for your code. I suppose it won't be very different to display only customers who belong to the same group to which the logged in employee does, won't it be ?

I'm trying this for days, unsuccessfully. Could you help me please ?

 

Here is the code i made

 

$this->filter = 'AND a.`id_default_group` IN (SELECT cg.id_customer from '._DB_PREFIX_.'customer_group cg where id_group = '.$id_group.')';

 

Regards,

Dominic

Link to comment
Share on other sites

hi Henrik !

thank's for replying. oh yes, i'd appreciate so much your help! I just changed the filter, no other change.

$id_group is the id of the group which the logged employee belongs to.

looking forward to hearing from you.

Dominic

Link to comment
Share on other sites

Hi Dominic!

 

There are two problems with what you want to accomplish:

 

1. The employees don't belong to any group. That's precisely why I implemented the company model. An alternative is to optionally attach each employee to a group. This can make sense in situations where you want to segment the customers and each employee should only see his own segment (and I believe this could be what you are trying to accomplish). So you must modify ps_employee and override the employee class like I did above.

 

2. You join on two different values in your code id_default_group and id_customer. It cannot work. Once you have done the things in step 1 your filter should read something like:

 

$this->filter = 'AND a.id_default_group IN (SELECT e.id_group from '._DB_PREFIX_.'employee e where e.id_employee = '.$cookie->id_employee);

 

considering that the name of your new field in ps_employee is id_group.

 

Hope this can help.

 

Best Regards

 

Henrik

Link to comment
Share on other sites

Thank you Henrik

Yes, that's exactly what i need to do. Create as many customers groups as salesmen and filter access so each salesman should see only his customers.

I try your suggestion and get back to you as possible.

Dominic

Link to comment
Share on other sites

Hi again Henrick,

alas ! it doesn't work... For sure you know my problem, let me explain the way i choosed to solve it, and where i am stopped. You're the only person who can help me Henrick, i did not found any information on the forum althought the thing i'm trying to do could be very very useful to many prestashop users, i think.

 

I need to hide some of the customers in the admin list of customers, regarding of which employee is loggued.

Exactly that functionality filters the list according to which of the company's salesman is logged.

 

So i decided to process that way:

 

1) creation of a restricted profile 'salesman' in the admin employees section

 

2) creation of a group of customers following that rule : a group called 'martin' groups together the customers managed by salesman Martin

 

3) i catch the name of the salesman when he logs

 

4) in the customers list, i only display those who belong to the group named identically to that salesman

 

I'm okay with all these points except the last one, the 4th.

I choosed that method because i d'id'nt want to alter the tables.

 

What do you think about that Henrick ?

 

Regards,

Dominic

Link to comment
Share on other sites

Henrick, 'found it !

$this->_filter = 'AND a.id_customer IN (SELECT cg.id_customer FROM '._DB_PREFIX_.'customer_group cg WHERE cg.id_group = '.$id_filter_group.')';

where $id_filter_group is the id of the group to filter by.

 

thank's for your help Henrick

Dominic

Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...

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...