Jump to content

Multistore employee access


Recommended Posts

When I create a new shop using the webservice and a new employee using the webservice, both are assigned correctly and in the database table ps_employee_shop and the new employee is only assigned to his current shop:

i.e.

 

id_employee    id_shop

1                        1

1                        2

2                        2

 

So in the above example id_employee 1 is the admin, and 2 is the new employee created, so as you can see it looks fine, he only has access to his shop.

 

The problem is that whenever that employee logins to the admin panel, there is something (probably a hook) that gives the employee access to the main store, inserting the new record. 

 

So now the table looks like this:

 

id_employee    id_shop

1                        1

1                        2

2                        2

2                        1

 

I don't understand why it gives users access to the main shop, even if the user is created with a low permissions profile.

 

What is the hook or file that is inserting this record?

 

Is there a way to disable this in the admin panel?

 

Any input will be appreciated!  :rolleyes:

 

Thanks,

 

By the way I'm using the latest PS version 1.6.0.6 

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

  • 4 months later...
  • 2 weeks later...

You can use the API 'employees' method:

http://doc.prestashop.com/display/PS16/Web+service+reference

 

Question is: How do you assign that employee to the correct shop?

thanks Wazzu for the reply

When I create a new employee using the webservice,  the new employee is only assigned to his main shop:

i.e.

table ps_employee_shop and

id_employee    id_shop

1                        1

2                        1

3                        1

So i have the same question now: How i can assign the new employer to the correct shop?

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

Well, I never got an answer as it's not implemented (what a shame)

So I extended web services and created a new method for dealing with ps_employee_shop table

 

First I created a /classes/EmployeeShop.php file based on some othe class file in that directory, something like this:

class EmployeeShopCore extends ObjectModel
{
/** @var int Determine employee id */
public $id_employee;

/** @var int Determine shop id */
public $id_shop;

/**
* @see ObjectModel::$definition
*/
public static $definition = array(
    'table' => 'employee_shop',
    'primary' => 'id_employee',
    'fields' => array(
	'id_employee' => array('type' => self::TYPE_INT, 'required' => true),
	'id_shop' =>     array('type' => self::TYPE_INT, 'required' => true),
    ),
);

protected $webserviceParameters = array(
    'fields' => array(
	'id_employee' => array('xlink_resource' => 'employees'),
	'id_shop' => array('xlink_resource' => 'shops'),
    ),
);

} 

Then I added the new method inside /classes/webservice/WebserviceRequest.php (line 299 in my example):

'employees' => array('description' => 'The Employees', 'class' => 'Employee'),
'employee_shop' => array('description' => 'Employees Shop assignation', 'class' => 'EmployeeShop'),
'search' => array('description' => 'Search', 'specific_management' => true, 'forbidden_method' => array('PUT', 'POST', 'DELETE')),

And that's how I'm making it, still WIP and of course no update-safe :-(

 

And there's more: even if you manage to create a multishop and an employee, you will face many other problems later, all of them related with multistore feature (categories, products, etc).

 

It seems prestashop web service isn't aware of multistore functionality at all :-(

  • Like 1
Link to comment
Share on other sites

Thanks wazzu for sharing your solution

 created  "EmployeeShop.php" Then I added the new method inside /classes/webservice/WebserviceRequest.php

but in the store's webservice (mystore/api), "employee_shop" is not displaed like customers, categories,employees . . . 

so please what is wrong ??

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

Hi wazzu,

 

it is solved but without any modification in prestashop code 

 

we can assign the new employer to the correct shop as follow:

 

creating webservice access:

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

here the PS_SHOP_PATH  is the path of the desired shop and not the  main shop

and in order to use the same PS_WS_AUTH_KEY of the main shop you shoud chek all the store in shop association (backoffice :Advanced Parameters-->Webservice)

Edited by daed (see edit history)
  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...