Post by soscodes » Mon Apr 29, 2024 4:22 pm

Hey, I am using opencart 4.0.2.3 and I want to overwrite some core functionality, for example I want to add some custom filters to getProducts function of admin/model/catalog/product.php.
like append

Code: Select all

		if (!empty($data['filter_custom'])) {
			$sql .= " AND pd.`custom_field` LIKE '" . $this->db->escape((string)$data['filter_custom'] . '%') . "'";
		}
or I want to change AND condition to OR. How I can do this?

Newbie

Posts

Joined
Fri Sep 20, 2019 6:50 pm

Post by JNeuhoff » Mon Apr 29, 2024 6:55 pm

Event handlers. Having said that, don't use OpenCart 4 for live websites, OpenCart 4 is still subject to development and bugfixes.

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


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by paulfeakins » Mon Apr 29, 2024 8:05 pm

JNeuhoff wrote:
Mon Apr 29, 2024 6:55 pm
Event handlers.
These are the main way in the current release (although you could use vQmod) but as above, I'd wait for the next release of 4 before using it, as the next release should have OCMOD.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by soscodes » Mon Apr 29, 2024 8:05 pm

Any document and example for using event handler to append/inject custom code into function?

If OpenCart 4 is not stable yet, then why is it officially available for download and installation?

Newbie

Posts

Joined
Fri Sep 20, 2019 6:50 pm

Post by straightlight » Mon Apr 29, 2024 9:33 pm

soscodes wrote:
Mon Apr 29, 2024 4:22 pm
Hey, I am using opencart 4.0.2.3 and I want to overwrite some core functionality, for example I want to add some custom filters to getProducts function of admin/model/catalog/product.php.
like append

Code: Select all

		if (!empty($data['filter_custom'])) {
			$sql .= " AND pd.`custom_field` LIKE '" . $this->db->escape((string)$data['filter_custom'] . '%') . "'";
		}
or I want to change AND condition to OR. How I can do this?
Affected strings cannot be changed by using Event Triggers. It can only be done with OCMod which has been integrated in OC v4.1.0.0 (dev) release on Github.

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 WaxedPerfection » Mon Apr 29, 2024 9:57 pm

soscodes wrote:
Mon Apr 29, 2024 8:05 pm
If OpenCart 4 is not stable yet, then why is it officially available for download and installation?
Trusting the advice of experienced developers who work with OpenCart day in and day out is invaluable. Their insights come from practical experience and troubleshooting, often uncovering nuances that might not be immediately apparent from official documentation. Following their recommendations, even if it contradicts the official stance, can save you from potential headaches down the road.

See for yourself:
viewtopic.php?t=231401

https://www.waxedperfection.co.uk/ Car Detailing Product Blog's and Review's


Active Member

Posts

Joined
Sun Mar 26, 2017 8:23 pm

Post by soscodes » Tue Apr 30, 2024 2:05 pm

WaxedPerfection wrote:
Mon Apr 29, 2024 9:57 pm
soscodes wrote:
Mon Apr 29, 2024 8:05 pm
If OpenCart 4 is not stable yet, then why is it officially available for download and installation?
Trusting the advice of experienced developers who work with OpenCart day in and day out is invaluable. Their insights come from practical experience and troubleshooting, often uncovering nuances that might not be immediately apparent from official documentation. Following their recommendations, even if it contradicts the official stance, can save you from potential headaches down the road.

See for yourself:
viewtopic.php?t=231401
Absolutely! Relying on the guidance of seasoned developers who have extensive experience with OpenCart is incredibly valuable. If OpenCart feels that this version is not stable, the forum link shared above should be added to the main page so that developers are aware of it. Previously, I was using Magento, which releases stable versions only.

Newbie

Posts

Joined
Fri Sep 20, 2019 6:50 pm

Post by soscodes » Tue Apr 30, 2024 2:12 pm

straightlight wrote:
Mon Apr 29, 2024 9:33 pm
Affected strings cannot be changed by using Event Triggers. It can only be done with OCMod which has been integrated in OC v4.1.0.0 (dev) release on Github.
Okay. If there aren't too many customizations, can we use OpenCart 4.0.2.3 for our live website? We've already invested two months in transitioning from 3.0.3.6 to 4.0.2.3.

Also, until the official release of OpenCart 4 with ocmod, can I use event functions to replace core/parent functions by copying the entire code for the triggered function?

Newbie

Posts

Joined
Fri Sep 20, 2019 6:50 pm

Post by OSWorX » Tue Apr 30, 2024 4:48 pm

It's useless (and more work for all of us here!) posting in 2 different thread nearly same questions!
Either here or in the other thread. viewtopic.php?p=869450

THX!

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by paulfeakins » Tue Apr 30, 2024 10:02 pm

soscodes wrote:
Tue Apr 30, 2024 2:12 pm
Also, until the official release of OpenCart 4 with ocmod, can I use event functions to replace core/parent functions by copying the entire code for the triggered function?
You can try. Some developers like using events and claim they can do what OCMOD can. However, I am not one of them and neither are any of the developers in my team.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by straightlight » Tue Apr 30, 2024 11:07 pm

soscodes wrote:
Tue Apr 30, 2024 2:12 pm
straightlight wrote:
Mon Apr 29, 2024 9:33 pm
Affected strings cannot be changed by using Event Triggers. It can only be done with OCMod which has been integrated in OC v4.1.0.0 (dev) release on Github.
Okay. If there aren't too many customizations, can we use OpenCart 4.0.2.3 for our live website? We've already invested two months in transitioning from 3.0.3.6 to 4.0.2.3.

Also, until the official release of OpenCart 4 with ocmod, can I use event functions to replace core/parent functions by copying the entire code for the triggered function?
I would not use OC v4.x releases until the official release gets published either from the Github Opencart releases or from the opencart.com website when the time comes. As for the Event Triggers, the Event engine is not meant to replace code, it is meant to repull the data and edit them accordingly by expanding the code by the time it, either, begins or reaches the end of each methods with the exception of language packs. However, for language packs, people tends more to call their own language files from their Event controllers rather than expanding existing language files from the core into their extensions.

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 19 guests