Post by dnaxcore » Fri Dec 14, 2018 11:19 pm

Developing an OpenCart module (my first time with this platform), I've created my module skeleton, for now I have my_module.php with install, uninstall, addModule and editModule methods + my_module.twig with my module view. Module is installable and editable, but I have problem with my module custom endpoints (front-end part of the module built in Vue.js and I need to somehow fit it in OpenCart module scheme):

My module main URL in OpenCart is : http://localhost/opencart_dev/admin/ind ... _id=someId

In order to my module actually work I need to pots/get data to various endpoints (admin-side endpoints) like:

http://localhost/opencart_dev/admin/ind ... dule/login

http://.../my_module/register

http://.../my_module/setting etc...

Basically what I need from OpenCart is something like register_rest_route() methods in Wordpress or front/admin controllers in PrestaShop?
How can I achieve it in Opencart?

Newbie

Posts

Joined
Fri Dec 14, 2018 11:17 pm

Post by OSWorX » Fri Dec 14, 2018 11:52 pm

Simply send the request (get or post) to the module like:

Code: Select all

index.php?route=extension/module/my_module/recieveGet
and inside the function

Code: Select all

public function recieveGet()
you do what you want to do.

If you want to send back some data, do it via (e.g. a message, a new result, etc.)

Code: Select all

$this->response->addHeader( 'Content-Type: application/json' );
$this->response->setOutput( json_encode( $result ) );
That result is sent to the view where you assign it to a placeholder or display a message.

Basically, everything exists if you study a bit the existing shop you already have in your hands.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by dnaxcore » Thu Dec 20, 2018 10:04 pm

Thanks a lot! That was the thing I was searching for.

I've tried to search something about composer in modules, but couldn't find anything.
So there goes my second question - I really need to use some libraries installed via composer, is there any way to do it in my module? When I try to add my vendor files into my module library folder it doesn't seem to work. Classes are not found, problably because they're not autoloaded, when I change 'use' for 'require_once' it starts to work, but changeing it in all my libraries doesn't seem to be a good idea.

Can I add some libs to the main opencart composer and force update it while installing a module? Or there is some other way around it?

Newbie

Posts

Joined
Fri Dec 14, 2018 11:17 pm
Who is online

Users browsing this forum: No registered users and 372 guests