Post by Arbeon » Thu Jul 07, 2016 4:42 pm

I am working on a script that grabs all the category and product data from my opencart webshop. Since i use a application to run this script i can't use the MVC structure of opencart, the php script has to be located at the rootfolder of opencart.

Currently i have this code:

Code: Select all

<?php

	if (is_file('./admin/config.php')) {
		require_once('./admin/config.php');
	}

	require_once(DIR_SYSTEM . 'startup.php');
	//require_once(DIR_SYSTEM . 'library/cart/user.php');


	$application_config = 'admin';
	$registry = new Registry();

	$loader = new Loader($registry);
	//$loader->model('catalog/product');
	$registry->set('load', $loader);

	$config = new Config();
	$config->load('default');

	$config->load($application_config);
	$registry->set('config', $config);
	$registry->set('request', new Request());
	$response = new Response();

	$response->addHeader('Content-Type: text/html; charset=utf-8');
	$registry->set('response', $response);

	$registry->set('cache', new Cache($config->get('cache_type'), $config->get('cache_expire')));
	$registry->set('url', new Url($config->get('site_ssl')));

	$language = new Language($config->get('language_default'));
	$language->load($config->get('language_default'));

	$registry->set('language', $language);
	$registry->set('document', new Document());

	$event = new Event($registry);
	$registry->set('event', $event);

	if ($config->get('db_autostart')) {
		$registry->set('db', new DB($config->get('db_type'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port')));
	}

	if ($config->get('session_autostart')) {
		$session = new Session();
		$session->start();
		$registry->set('session', $session);
	}

	if ($config->has('action_event')) {
		foreach ($config->get('action_event') as $key => $value) {
			$event->register($key, new Action($value));
		}
	}

	if ($config->has('config_autoload')) {
		foreach ($config->get('config_autoload') as $value) {
			$loader->config($value);
		}
	}

	if ($config->has('language_autoload')) {
		foreach ($config->get('language_autoload') as $value) {
			$loader->language($value);
		}
	}

	if ($config->has('library_autoload')) {
		foreach ($config->get('library_autoload') as $value) {
			$loader->library($value);
		}
	}

	if ($config->has('model_autoload')) {
		foreach ($config->get('model_autoload') as $value) {
			$loader->model($value);
		}
	}

	class Myclass extends Controller
	{

		function login($usr, $pwd)
		{
			if ($this->user->login($usr, $pwd)) {
				return TRUE;
			} else {
				echo('Error: Login failed.');
				die;
			}
		}

		function cleanPost($post)
		{
			$post = mb_convert_encoding($post, 'UTF-8', 'UTF-8');
			$post = htmlentities($post, ENT_QUOTES, 'UTF-8');
			return $post;
		}

		function getProductCount()
		{
			$this->model->load('catalog/product');
			$products = $this->model_catalog_product->getProducts();
			print_r($products);
		}
	}

	$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
	$registry->set('db', $db);
	$registry->set('user', new Cart\User($registry));

	$myAPI = new Myclass($registry);
	if ($myAPI->login('user','password')) {
            getProductCount()
	}

?>
This codesnippet let's me login and use the product.php file located at: opencart\admin\controller\catalog. But when i run the code I get an empty array. So my question is: How do i include all the models/controllers in a custom made script in the rootfolder, or what am i doing wrong?

Thanks in advance!
(if i get it working i'll post it here!)

Newbie

Posts

Joined
Thu Jul 07, 2016 4:27 pm

Post by straightlight » Tue Jul 12, 2016 8:52 pm

There seem to be more and more posting regarding 3rd party code integration into Opencart while there doesn't need to be. Integration is not about adding 3rd party codes into the platform, it is rather about creating a relay library file which the Opencart registry can propagate between the two extremities - the platform and the 3rd party library. This has already been done with the openbay library from the core, this is not a new invented / created idea as it is the most API compatible solution to integrate new solutions.

Another example you can take a look at would be at my contributions on my signature.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by Arbeon » Tue Jul 12, 2016 9:20 pm

straightlight wrote:There seem to be more and more posting regarding 3rd party code integration into Opencart while there doesn't need to be. Integration is not about adding 3rd party codes into the platform, it is rather about creating a relay library file which the Opencart registry can propagate between the two extremities - the platform and the 3rd party library. This has already been done with the openbay library from the core, this is not a new invented / created idea as it is the most API compatible solution to integrate new solutions.

Another example you can take a look at would be at my contributions on my signature.
Thanks for your answer straightlight, but this doesn't really answer my question. I have to locate my script at the rootfolder of OpenCart. Do you know if this is possible and perhaps how?

Newbie

Posts

Joined
Thu Jul 07, 2016 4:27 pm

Post by straightlight » Tue Jul 12, 2016 9:23 pm

Arbeon wrote:
straightlight wrote:There seem to be more and more posting regarding 3rd party code integration into Opencart while there doesn't need to be. Integration is not about adding 3rd party codes into the platform, it is rather about creating a relay library file which the Opencart registry can propagate between the two extremities - the platform and the 3rd party library. This has already been done with the openbay library from the core, this is not a new invented / created idea as it is the most API compatible solution to integrate new solutions.

Another example you can take a look at would be at my contributions on my signature.
Thanks for your answer straightlight, but this doesn't really answer my question. I have to locate my script at the rootfolder of OpenCart. Do you know if this is possible and perhaps how?
The script of the root folder you are referring to must probably be about a callback file. If so, a callback file in Opencart does not need to be on the root folder as I don't really recommend it either. If you'd like to share what you're trying to deploy from Opencart, a more accurate answer and solution could be provided afterwards.

In the mean time, one of the example you could rely on would be from the catalog/controller/payment folder which most of the payment module files contains a callback method.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

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

Post by Arbeon » Tue Jul 12, 2016 10:25 pm

straightlight wrote:
Arbeon wrote:
straightlight wrote:There seem to be more and more posting regarding 3rd party code integration into Opencart while there doesn't need to be. Integration is not about adding 3rd party codes into the platform, it is rather about creating a relay library file which the Opencart registry can propagate between the two extremities - the platform and the 3rd party library. This has already been done with the openbay library from the core, this is not a new invented / created idea as it is the most API compatible solution to integrate new solutions.

Another example you can take a look at would be at my contributions on my signature.
Thanks for your answer straightlight, but this doesn't really answer my question. I have to locate my script at the rootfolder of OpenCart. Do you know if this is possible and perhaps how?
The script of the root folder you are referring to must probably be about a callback file. If so, a callback file in Opencart does not need to be on the root folder as I don't really recommend it either. If you'd like to share what you're trying to deploy from Opencart, a more accurate answer and solution could be provided afterwards.

In the mean time, one of the example you could rely on would be from the catalog/controller/payment folder which most of the payment module files contains a callback method.
Once agian thank you for your quick reply!

I've figured it out, the code which i've posted worked. There was something wrong with the language ID. Thanks for your help.

Newbie

Posts

Joined
Thu Jul 07, 2016 4:27 pm
Who is online

Users browsing this forum: No registered users and 12 guests