One of the core files classes/stock/StockAvailable.php contains:
class StockAvailableCore extends ObjectModel
{
public static function getQuantityAvailableByProduct($id_product = null, $id_product_attribute = null, $id_shop = null)
{
...
}
...
}
I want to call this getQuantityAvailableByProduct() method from my module.
So I tried to include this class (and it's father class and father's interface), extend it and call method like this:
require_once('../../src/Core/Foundation/Database/EntityInterface.php');
require_once('../../classes/ObjectModel.php');
require_once('../../classes/stock/StockAvailable.php');
$MyClass = new StockAvailableCore();
$MyClass->getStockAvailableIdByProductId($id);
And the error that I'm getting:
PHP Fatal error: Uncaught Error: Class 'ObjectModel' not found in /home/mantas/Server/honey/classes/stock/StockAvailable.php:34
What am i missing? And is this the correct way to extend a class and call method?
ObjectModel.php file
<?php
class ObjectModel{
//For example I created non-static function in ObjectModel class
public function getStockAvailableIdByProductId($id){
return "test";
}
//For example I created static function in ObjectModel class
public static function getStockAvailableIdByProductIdStatic($id){
return "teststatic";
}
}
?>
StockAvailable.php file.
<?php
//Extends used to inherit the parent class property
class StockAvailableCore extends ObjectModel
{
public static function getQuantityAvailableByProduct($id_product = null, $id_product_attribute = null, $id_shop = null)
{
}
}
?>
run.php file
<?php
require_once('ObjectModel.php');
require_once('StockAvailable.php');
$MyClass = new StockAvailableCore();
// Access the ObjectModel function
//to access the Non-static method need to create the object.
echo $MyClass->getStockAvailableIdByProductId($id);
//Static method access by class reference (::)
echo StockAvailableCore::getStockAvailableIdByProductIdStatic($id);
?>
You can call it just in this way StockAvailable::getQuantityAvailableByProduct($id_product, $id_product_attribute)
. And if you make your module according to Documentation you don't even need to include any files at the beginning of your code