首先,您需要将事件添加到数据库中,您可以addEvent
在模块install
函数中使用函数,如下所示:
public function install(){
$this->load->model('setting/event');
$this->model_setting_event->addEvent('my_module', 'catalog/view/product/product/after', 'extension/module/my_module/edit_product_page');
}
或者手动添加:
INSERT INTO `oc_event` (`code`, `trigger`, `action`, `status`) VALUES ('my_module', 'catalog/view/product/product/after', 'extension/module/my_module/edit_product_page', 1);
现在创建这个文件:
catalog\controller\extension\module\my_module.php
及其内容:
<?php
class ControllerExtensionModuleMyModule extends Controller {
public function edit_product_page(&$route = '', &$data = array(), &$output = '') {
if (isset ($this->request->get['product_id'])) {
$product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
if ($product_info) {
// Display it before <li>Product Code:
$find = '<li>' . $data['text_model'];
$replace = '<li>Quantity: ' . $product_info['quantity'] . '</li>' . $find;
$output = str_replace($find, $replace, $output);
}
}
}
}
结果:
MacBook
品牌苹果
数量:929
产品编号:产品 16
奖励积分:600
库存量:有货