Post by hypemedia » Fri Nov 11, 2016 1:08 am

I have created a custom library and I want to load a model into it.

I have de the

Code: Select all

public function __construct($registry) {
		$this->config = $registry->get('config');
		$this->db = $registry->get('db');
		$this->request = $registry->get('request');
		$this->session = $registry->get('session'); 
		$this->load = $registry->get('load');

		$this->detectEnviroment();
	}
and then I will like to load this:

Code: Select all

$this->load->model($this->environment . '/shipping_list');
$this->load->model_checkout_shipping_list->updateStock($products);
But if do so I get an error that the model_checkout_shipping_list is NULL.
In opencart 1.5.6 it was working.
I am using opencart 2.2 now.

Any suggestions on what I am doing wrong?

Active Member

Posts

Joined
Fri Aug 17, 2012 5:39 pm

Post by johnroshan » Fri Mar 22, 2024 4:27 pm

// Try doing do this

Code: Select all

public function __construct($registry) {
   $this->config = $registry->get('config');
   $this->db = $registry->get('db');
   $this->request = $registry->get('request');
   $this->session = $registry->get('session');
   $this->load = $registry->get('load');

   $this->load->model('checkout/shipping_list'); // i think in your case the model is in your checkout folder.

   //after that load the model using the "$registry".
   $this->model = $registry->get('model_checkout_shipping_list');
}
// Now you can use the model anywhere in the library

Code: Select all

$this->model->updateStock($products);
// please make sure that this $this->model = $registry->get('model_checkout_shipping_list'); line of code must be in the _construct method.

Newbie

Posts

Joined
Wed Jul 13, 2022 8:43 pm
Who is online

Users browsing this forum: No registered users and 18 guests