Post by straightlight » Sat Jan 24, 2015 3:45 am

Code: Select all

$api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
This methodology is incorrect. The API ID should not be based on the store but rather on the selected service which the user name and password needs to authenticate to. One example would be to indicate the admin orders. Each tabs should have integrated fields processed from admin modules in order to create a store front-end API controller file used with JSON so that each store representative could select the API provider and which values would need to be adapted to the orders from modules before representatives could officially submit the orders to customer on the store front-end.

Relying on admin modules would avoid override and conflicted decisions between distributors and merchants based on administrative decisions.

Since OC v2.0+ already provides features for custom fields purposes, this would be more than ideal to integrate.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sun Jan 25, 2015 2:44 am

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 2 guests