问题
I am preparing a custom module for prestashop. I want to use in it some classes that exist in prestashop already (Orderdetail.php).
How can I do this? Is the code below sufficient or do I need to include something else in addition?
$order = new OrderDetail;
回答1:
Yes, the native classes can be called like that.
$order_detail = new OrderDetail();
However to use custom classes you need to include their files in the script you want to use them.
include_once 'path_to_custom_class_file';
class MyModule extends Module {
public function aMethod() {
$myClass = new MyClass();
}
}
回答2:
To make an instance of your module you have to use this code:
$mymodule = Module::getInstanceByName('mycustommodule');
Than you can use method of your module core. E.g.
$mymodule->myCustomMethod('x', 'y');
来源:https://stackoverflow.com/questions/40023358/use-existing-classes-in-prestashop-module