Post by codinginspect » Fri May 27, 2022 9:15 pm

Does anybody know view file code like we do in Ocmod ?

for example this is view code:
{% for store in stores %}
<a href="{{ store.href }}" target="_blank" class="dropdown-item">{{ store.name }}</a>
{% endfor %}

with ocmod we can set search string
<a href="{{ store.href }}" target="_blank" class="dropdown-item">{{ store.name }}</a>
and replace with
<a href="{{ store.href }}" target="_blank" class="dropdown-item store-{{ store.id }}">{{ store.name }}</a>

Download sample ocmod.zip in this link.
https://www.codinginspect.com/test/modi ... .ocmod.zip

do not install this ocmod file on opencart store. it is only demonstration purpose only. To acheive same out with event system.

Does anybody know how we can acheive the same event system ?

User avatar
New member

Posts

Joined
Thu Feb 09, 2017 9:51 pm

Post by straightlight » Mon May 30, 2022 2:51 am

codinginspect wrote:
Fri May 27, 2022 9:15 pm
Does anybody know view file code like we do in Ocmod ?

for example this is view code:
{% for store in stores %}
<a href="{{ store.href }}" target="_blank" class="dropdown-item">{{ store.name }}</a>
{% endfor %}

with ocmod we can set search string
<a href="{{ store.href }}" target="_blank" class="dropdown-item">{{ store.name }}</a>
and replace with
<a href="{{ store.href }}" target="_blank" class="dropdown-item store-{{ store.id }}">{{ store.name }}</a>

Download sample ocmod.zip in this link.
https://www.codinginspect.com/test/modi ... .ocmod.zip

do not install this ocmod file on opencart store. it is only demonstration purpose only. To acheive same out with event system.

Does anybody know how we can acheive the same event system ?
You could either take a look on the latest OC v3.x release in your catalog/controller/extension/advertise/google.php file on how to use a /after event or use an extension from the Marketplace. Alternatively, you could see this topic: viewtopic.php?f=144&t=227710#p839437

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by DigitCart » Mon May 30, 2022 3:38 am

Hi

I'm not sure if this is a smart way or not, but I tested it and it works.
Note that I did this test with OpenCart version 3.0.2.0.

Event code: test
Event trigger: admin/view/common/header/after
Event action: extension/module/test

admin\controller\extension\module\test.php

Code: Select all

<?php
class ControllerExtensionModuleTest extends Controller {
	public function index($route = '', $data = array(), &$output = '') {
		$stores = array();

		$stores[] = array(
			'name' => $this->config->get('config_name'),
			'href' => HTTP_CATALOG,
			'store_id' => 0
		);

		$this->load->model('setting/store');

		$results = $this->model_setting_store->getStores();

		foreach ($results as $result) {
			$stores[] = array(
				'name' => $result['name'],
				'href' => $result['url'],
				'store_id' => $result['store_id']
			);
		}

		foreach ($stores as $store) {
			$output = str_replace('href="' . $store['href'] . '"', 'href="' . $store['href'] . '" data-store-id="' . $store['store_id'] . '"', $output);
		}
	}
}
In this example instead of adding a class store-{{ store.id }} I added a new attribute data-store-id.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by JNeuhoff » Mon May 30, 2022 6:50 pm

This has been discussed several times on the OpenCart forum, see e.g. viewtopic.php?f=144&t=221533 on how to a view/*/before event handler for modifying a template.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by straightlight » Tue May 31, 2022 6:04 am

DigitCart wrote:
Mon May 30, 2022 3:38 am
Hi

I'm not sure if this is a smart way or not, but I tested it and it works.
Note that I did this test with OpenCart version 3.0.2.0.

Event code: test
Event trigger: admin/view/common/header/after
Event action: extension/module/test

admin\controller\extension\module\test.php

Code: Select all

<?php
class ControllerExtensionModuleTest extends Controller {
	public function index($route = '', $data = array(), &$output = '') {
		$stores = array();

		$stores[] = array(
			'name' => $this->config->get('config_name'),
			'href' => HTTP_CATALOG,
			'store_id' => 0
		);

		$this->load->model('setting/store');

		$results = $this->model_setting_store->getStores();

		foreach ($results as $result) {
			$stores[] = array(
				'name' => $result['name'],
				'href' => $result['url'],
				'store_id' => $result['store_id']
			);
		}

		foreach ($stores as $store) {
			$output = str_replace('href="' . $store['href'] . '"', 'href="' . $store['href'] . '" data-store-id="' . $store['store_id'] . '"', $output);
		}
	}
}
In this example instead of adding a class store-{{ store.id }} I added a new attribute data-store-id.
The parameters are not added correctly. Referenced variables without the need to affect the types of variables can simply be used.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 48 guests