Reputation: 1305
I have a file located at opencart_root/myfolder/myfile.php
, which I access via ajax call from opencart checkout page.
How to make OpenCart methods (e.g. cart->getProducts()
), constants (e.g. DB_HOSTNAME
) and sessions available in myfile.php
?
OpenCart version is 2.2.0
Upvotes: 2
Views: 794
Reputation: 22969
You can do it the way it's done with other library classes. First include your class (I'm assuming you've already done that. Then pass the $registry
to it in a constructor method inside index.php somewhere after $registry->set('cart', new Cart($registry));
:
$adapter = new Adapter($registry);
Now inside your constructor you can set:
$this->cart = $registry->get('cart');
And inside class methods:
$products = $this->cart->getProducts();
This should work up through Opencart 2200 where I believe the class instantiation should be done in system/framework.php
somewhere after the // Library Autoload
section.
If you don't want to use a constructor you can also pass $this->registry
directly to class methods.
Upvotes: 2