Jump to content

How to instantiate a Controller from a module or other Controller ?


Vincent Decaux

Recommended Posts

Hello all !

What I want : building a widget for Elementor, this widget will take an ID categoery as parameter, and display the category tpl.

I just want to use the Prestashop CategoryController to achieve this.

So I created an override of CategoryController, and in my widget I use this code :

public function renderIqitElementorWidget($name, $options, $preview = false)
{
    Tools::setFallbackParameters([
      'id_category' => $categoryId,
      'content_only' => 1,
    ]);

    // get the result in pure HTML, not in ajax
    unset($_GET['ajax']);

    $categoryController = new CategoryController();
    $categoryController->init();
    $categoryController->initContent();
    // override to display specific view
    $categoryController->widgetCategory();
    $categoryController->display();
}

But I am not sure I can't do it this way, for now I have this error : 

Quote

FatalThrowableError

Call to a member function get() on null

in Controller.php line 795

at ControllerCore->get('prestashop.core.filter.front_end_object.main')in FrontController.php line 575

I don't know the way to render the display of a category, with facets and product and pagination easily ?

Is it possible ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...