首页 > 解决方案 > 如何从后台调用模块方法,特别是从订单页面

问题描述

我在 Prestashop 1.7 中创建了一个模块

我想从后台订单页面调用模块方法。

我正在覆盖订单页面视图以创建 url。

URL格式应该是什么

到目前为止我已经尝试过:

{url entity='module' name='mymodule' controller='mymodulecontroller' params=['order_id' => $order->id]}

它提供了如下链接:

http://localhost/ps17/module/mymodule/mymodulecontroller?order_id=4

我想在调用此方法时返回一个值。

不想给 JS 分配任何东西。

该模块没有配置页面。

有人可以阐明一下吗?我知道我的问题不是很清楚。我可以澄清你的问题。

我只有这些文件 MyModule.php Controller/Admin/MymoduleController.php Override/.......

模块被安装。覆盖不起作用,必须手动覆盖。挑战是使用 url 调用 MyModule.php 或 Controller/Admin/MymoduleController.php 的方法。

谢谢你!

标签: prestashop-1.7prestashop-modules

解决方案


Prestashop 有很多 Hooks。你必须在你的模块中使用它们,也不需要任何覆盖。

1- 在安装过程中在一些 Hooks 中注册你的模块

$this->registerHook('displayAdminOrder')

2- 在模块的 Hook 方法中运行代码

public function HookDisplayAdminOrder($params)
{
    // some of the codes to display something in display Hooks
    // Or some of the codes to do something in action Hooks
}

管理订单页面中的一些重要 Hooks:

  • actionOrderStatusPostUpdate
  • displayAdminOrder
  • displayAdminOrderTabContent
  • displayAdminOrderContentOrder
  • displayAdminOrderContentShip
  • displayAdminOrderLeft
  • displayAdminOrderRight 完整列表:Hooks PS1.7 列表

推荐阅读