简体   繁体   English

更改Magento 2 REST API

[英]Change Magento 2 REST API

Hey guys I wonder if anyone can help with this. 大家好,我想知道是否有人可以提供帮助。 Now I am facing a problem at my company. 现在我在公司面临一个问题。 We are developing a Magento 2 Community multistore for our customers. 我们正在为客户开发Magento 2社区多店。

The idea is to have several stores in the same Magento 2 installation, where each store is for each independent company. 这个想法是在同一个Magento 2安装中拥有多个商店,每个商店都是针对每个独立公司的。 The problem is the integration with our ERP system. 问题是与我们的ERP系统集成。 With the API REST we have full control in the installation, even if we are not with the admin master credential. 使用API​​ REST,即使我们没有管理员主证书,我们也可以完全控制安装。 if we run commands like this in postman: https://magentostore.com/rest/V1/orders?searchCriteria we have all the orders in installation, all stores. 如果我们在邮递员中运行以下命令: https : //magentostore.com/rest/V1/orders?searchCriteria,我们将在安装中存储所有订单,所有商店。 So the companies with their credentials would have the same control and it is a very bad problem of security. 因此,具有凭据的公司将拥有相同的控制权,这是一个非常糟糕的安全性问题。 The stores would have access to data from each other. 商店将可以相互访问数据。

We have tried extensions for advanced permissions like Aitoc and Amasty but it's only works at a frontend level and does not take any effect in API REST. 我们已经尝试了扩展高级权限的扩展,例如Aitoc和Amasty,但是它仅在前端级别有效,并且在API REST中不起作用。 We know that Magento was not made for this kind of thing so my question is: 我们知道Magento不是为这种事情制作的,所以我的问题是:

is it possible to change the API REST to filter the queries by store? 是否可以更改API REST以按商店过滤查询? and where can I find these API REST queries? 在哪里可以找到这些API REST查询? I'd thank you so much. 非常感谢你。

So you can override api calls using webapi.xml file in your module, Just point it in your service interface and change acl if you want. 因此,您可以使用模块中的webapi.xml文件覆盖api调用,只需将其指向您的服务界面,并根据需要更改acl。 In your service interface inject the original one and add some your filter before calling original. 在服务界面中,注入原始文件,并在调用原始文件之前添加一些过滤器。

The second approach to write a plugin on OrderRepositoryInterface and add filter there (but first solution is better because this service is used not only in api so you may do not want to restrict all calls) 在OrderRepositoryInterface上编写插件并在其中添加过滤器的第二种方法(但第一种解决方案更好,因为此服务不仅在api中使用,因此您可能不想限制所有调用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM