Openencart Fundamentals - Can I write a custom controller to use in a view or do I need to use modules?

I am working on an Opencart theme and find that I need access to different variables than the ones provided by the default controllers.

For example, in the Category view, I would like to access the full product image, not the thumbnail that the controller provides by default.

From Wordpress I would use just a function call to get a different image size, but my guess is that in MVC this function should be in the controller.

However, I see no way to write a custom controller and editing the original means huge problems when upgrading.

As the main question, is the only solution to write a module? Is this good practice when developing a theme for opencart? For some reason I didn't find a very clear explanation of how I should work with opencart themes (a la wordpress codex).


source to share

1 answer

It doesn't need to be done in the controller at all, the view can access the same information as the controller. You just need to use this in the product outline

$prod = $this->model_catalog_product->getProduct($product['product_id']);
$full_image = empty($prod['image']) ? 'no_image.jpg' : $prod['image'];


Please note that you must resize the image using the tool / image model resizing method according to the dimensions you want to fit.



All Articles