Here's a better example.
Assuming I would want to edit an order for a customer and use a model API file to do it, we would first need to create an API folder into the catalog/model folder on the store front-end. Then, distributors / contributors would have their model file provided to merchants from their package.
From catalog/controller/api/order.php file,
above:
Code: Select all
$this->model_checkout_order->editOrder($order_id, $order_data);
Simply adding the following would solved the issue after configuring the admin module with the route name and its status:
Code: Select all
// Send / Receive from API
if ($this->config->has('config_api_model_module') && is_array($this->config->get('config_api_model_module'))) {
foreach ($this->config->get('config_api_model_module') as $config_api_model_module) {
if ($config_api_model_module['status']) {
$model_name = strip_tags(html_entity_decode($config_api_model_module['name'], ENT_QUOTES, 'UTF-8'));
$this->catalog_model_api_{$model_name}->editAPI($json, $order_data);
}
}
}
In the custom API model file, we would have something like:
Code: Select all
class CatalogModelApiMyCustomName {
public function editAPI(&$json, &$order_data) {
// Put API coding here.
}
}
Under the createInvoiceNo() of admin/controller/sale/order.php file,
right below:
Code: Select all
$json['invoice_no'] = $invoice_no;
to add:
Code: Select all
// Send / Receive from API
if ($this->config->has('config_api_model_module') && is_array($this->config->get('config_api_model_module'))) {
foreach ($this->config->get('config_api_model_module') as $config_api_model_module) {
if ($config_api_model_module['status']) {
$model_name = strip_tags(html_entity_decode($config_api_model_module['name'], ENT_QUOTES, 'UTF-8'));
$this->catalog_model_api_{$model_name}->setOrderInvoice($json, $invoice_no);
}
}
}
Custom model file:
Code: Select all
class CatalogModelApiMyCustomName {
public function setOrderInvoice(&$json, &$invoice_no) {
// Put API coding here.
}
}
Order histories from admin/controller/sale/order.php file,
right below:
Code: Select all
$results = $this->model_sale_order->getOrderHistories($this->request->get['order_id'], ($page - 1) * 10, 10);
should have:
Code: Select all
// Send / Receive from API
if ($this->config->has('config_api_model_module') && is_array($this->config->get('config_api_model_module'))) {
foreach ($this->config->get('config_api_model_module') as $config_api_model_module) {
if ($config_api_model_module['status']) {
$model_name = strip_tags(html_entity_decode($config_api_model_module['name'], ENT_QUOTES, 'UTF-8'));
$this->catalog_model_api_{$model_name}->setOrderHistory($results);
}
}
}
Custom model file:
Code: Select all
class CatalogModelApiMyCustomName {
public function setOrderHistory(&$results) {
// Put API coding here.
}
}
This methodology would allow merchants to send / receive any data from API and add them to whatever which order table that may be required in order to export the data from the database whenever it's needed. It could also be added for adding and deleting values purposes.
No matter how many contributors and OC upgrades that will be involved, Local API and Remote API would always obtain the same results in the end.