Page 1 of 1
Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Tue Aug 07, 2018 7:20 pm
by okibobo
Is it possible to use only the OC Event system for these overrides?
I need to override the core index function of the product controller. I want to edit the core file and add this line:
$data['quantity'] = $product_info['quantity'];
to the function index() in "class ControllerProductProduct extends Controller"
and then I need add this line in product.twig file:
<span>{{ quantity }}</span>
I want to use only the OC Event system, not ocmod or vqmod.
It is real?
Thanks for help.
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Tue Aug 07, 2018 7:43 pm
by straightlight
Better to use the Override Engine extension to accomplish this. While it won't override the core, it will at least merge the variables that you wish to declare into the same location. An alternative would be to create a TWIG function in order to define your own variable which this custom variable name can then be used over the same TWIG file without affecting what's been defined already from the core.
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Wed Aug 08, 2018 1:37 am
by okibobo
Thank you Straightlight for you help.
Do you know if in the future releases are planning to add events support for this kind of change? What is your opinion? Is it better to use for overrides Opencart Event system or 3rd party extension Override Engine?
One more question for the Override Engine module. How to make more complex changes of the twig file. I mean overrides in which the str_replace function is not enough. For example I want to add more lines of code to product.twig. And str_replace is not very practical then.
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Wed Aug 08, 2018 1:41 am
by straightlight
For example I want to add more lines of code to product.twig. And str_replace is not very practical then.
If you want to add more lines, you can either rely on the use of OCMod, VQMod or the Override Engine which each provides the ability to use the
add case without the need to use the str_replace function or, as explained, to implement your own TWIG function by returning a new variable so that you can use it as a supplement into your target TWIG file.
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Wed Aug 08, 2018 1:52 am
by okibobo
Can you post here some example? Sorry, I am newbie in this override engine system.
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Wed Aug 08, 2018 1:54 am
by straightlight
See this post:
viewtopic.php?f=24&t=85873&hilit=override+engine . In the mean time, I would highly recommend to see this post as well:
viewtopic.php?f=190&t=165636
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Wed Aug 08, 2018 2:08 am
by okibobo
Ok, thanks. And what do you prefer? Override Engine or OC Event system?
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Wed Aug 08, 2018 2:18 am
by straightlight
Preferences are based on the required solution a programmer might need in order to avoid conflict with other extensions in the most possible ways to achieve.
Re: Is it possible to use only the OC Event system for override core controller and twig file?
Posted: Wed Aug 08, 2018 2:27 am
by okibobo
Thanks for your time, I understand what you mean.