Post by khaja.hussain » Thu Dec 29, 2016 1:16 am

Hello,

I created a file in system/library/KTLibrary.php and added the references in:
  1. in system/startup.php file added the code: require_once(DIR_SYSTEM . 'library/KTLibrary.php');
  2. in catalog/controller/startup/startup.php and admin/controller/startup/startup.php added code: $this->registry->set('ktLibrary', new KTLibrary($this->registry));
How do I get my ktLibrary reference in system/storage/modification/system/library/cart/cart.php

I am getting null when I call $this->registry->get('ktLibrary'); in above cart.php

Please help.
Thank you.


Posts

Joined
Thu Dec 29, 2016 1:03 am

Post by hydrowire » Tue Jan 03, 2017 12:50 am

1. you do not need to "require_once()" your 'library/KTLibrary.php' custom file as all files in 'library' folder will be loaded automatically.

2. since you are referencing 'ktLibrary' in library/cart/cart.php, make sure to set your 'ktLibrary' registry BEFORE OpenCart's own 'cart' registry in startup/startup.php:
your line:

Code: Select all

$this->registry->set('ktLibrary', new KTLibrary($this->registry));
must be placed BEFORE this line:

Code: Select all

$this->registry->set('cart', new Cart\Cart($this->registry));
3. also, in library/cart/cart.php, to load a registry, it should be:

Code: Select all

$this->ktLibrary = $registry->get('ktLibrary');
in the __construct() function

Hope that solves your problem.

Developing OpenCart Extensions since 2011. View my extensions



Posts

Joined
Wed Jan 26, 2011 5:41 pm
Who is online

Users browsing this forum: No registered users and 27 guests