Post by Jsf » Fri May 24, 2019 8:43 pm

Hello,

OpenCart Events systems (https://github.com/opencart/opencart/wiki/Events-System) looks interesting, but I has a question:
How to edit twig file without ocmod/vqmod? For example I need to replace one line in product_form.twig:

Code: Select all

{% if customer_group.customer_group_id == product_special.customer_group_id %}
to

Code: Select all

{% if customer_group.customer_group_id == product_special.customer_group_id and some_new_variable_equal_true %}
Please give a hint how can I do it.

User avatar
Jsf
New member

Posts

Joined
Sun Jan 26, 2014 4:08 am

Post by D3MO » Fri May 24, 2019 10:36 pm

without ocmod you can edit it either in theme editor or directly in ftp no other way

Opencart Expert | voldemaras@gmail.com
Skype - programanija | Gtalk - voldemaras@gmail.com
Extensions for Opencart @ https://www.opencartextensions.eu / or Opencart Marketplace

Need Custom Module? debug third party module or simply have any question related to Opencart? feel free to contact directly for a live chat session:) - INSTANT LIVE CHAT


User avatar
Active Member

Posts

Joined
Mon Apr 04, 2011 6:57 am

Post by diegospm » Sat May 25, 2019 5:31 am

Jsf wrote:
Fri May 24, 2019 8:43 pm
Hello,

OpenCart Events systems (https://github.com/opencart/opencart/wiki/Events-System) looks interesting, but I has a question:
How to edit twig file without ocmod/vqmod? For example I need to replace one line in product_form.twig:

Code: Select all

{% if customer_group.customer_group_id == product_special.customer_group_id %}
to

Code: Select all

{% if customer_group.customer_group_id == product_special.customer_group_id and some_new_variable_equal_true %}
Please give a hint how can I do it.
Just like @D3MO has specified, to change this line you can do in the OC native theme editor since version 3.0. But I do not recommend doing the editing with FTP or another remote method, because you will have to make backups locally of the files if you want to recover the last version or the original.

If you really need the event, you need to add a controller file and add an event trigger before into the class of that file. In the class that will receive the event you need to change the array key that you want to change in the twig file.

After that, you need to create a twig file that will receive the new render and then edit as needed.

Events are a milestone in the OC, but it's a not-so-clear subject yet and in my point of view, editing the twig file could has edited directly (without going through the controller). But there must be a good reason to be so, the devs/managers of the OC are incredible in designing the tools for platform.

Newbie

Posts

Joined
Thu Apr 18, 2019 8:49 am

Post by grgr » Sat May 25, 2019 11:35 am

Not sure you can even do that. One way to do it though would be to replace the template product_form.twig with your own template file (my_product_form.twig) with the changes you want in it.

First, add an event; normally do this this by the install function of a module but can be done directly in phpMyadmin
In module:

Code: Select all

        $this->model_setting_event->addEvent('change_product_form', 'admin/view/catalog/product_form/before', 'extension/module/my_module/changeProductFormTemplate');
By phpMyAdmin (change db name)

Code: Select all

INSERT INTO `3032`.`oc_event` (`event_id` ,`code` ,`trigger` ,`action` ,`status` ,`sort_order`) VALUES (NULL , 'change_product_form', 'admin/view/catalog/product_form/before', 'extension/module/my_module/changeProductFormTemplate', '1', '1');
Create the module file ..admin/controller/extension/module/my_module.php and put in the following code:

Code: Select all

<?php
class ControllerExtensionModuleMyModule extends Controller {
/*	
Name: 		change_product_form
Trigger:	admin/view/catalog/product_form/before
Action:		extension/module/my_module/changeProductFormTemplate
Order:		1
Purpose:	Change the product_form.twig template to my_product_form.twig template.
*/
	public function changeProductFormTemplate(&$route, &$data) {
		$route = str_replace('catalog/product_form', 'catalog/my_product_form', $route);
	}
}
Create your new template file: admin/view/template/catalog/my_product_form.twig

Image Image Image Image Image Image Image Image


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK

Post by Jsf » Sat May 25, 2019 2:48 pm

Thank you for replies. All mentioned methods not very good looking forward because unexpected problems with other modules may occur. Events is good when you need to add something new or replace data array in controller. But as I understand to make small replaces in template files still best way with ocmod.

User avatar
Jsf
New member

Posts

Joined
Sun Jan 26, 2014 4:08 am
Who is online

Users browsing this forum: No registered users and 7 guests