Post by Dutch Pride Code » Fri Jun 25, 2021 5:28 pm

This is my first attempt to change anything small in OpenCart. Just started learning PHP so I am an absolute beginner. What I am trying to do is add a new form field to the Product Edit page, to store data about the product. Maybe not the right way to do this but any help is appreciated. I copied the "Location" field as this has all the properties I need: No front-end functionality, only stores input in database. Here's what I did so far:

OC 3.0.3.7 - Default theme - No modifications

IN admin / view / template / catalog / product_form.twig
ADD - line 145

Code: Select all

<div class="form-group">
  <label class="col-sm-2 control-label" for="input-supplier">{{ entry_supplier }}</label>
  <div class="col-sm-10">
    <input type="text" name="supplier" value="{{ supplier }}" placeholder="{{ entry_supplier }}" id="input-supplier" class="form-control"/>
  </div>
</div>
IN admin / model / catalog / product.php
ADD - line 4 + line 143

Code: Select all

"', supplier = '" . $this->db->escape($data['supplier']) . 
IN admin / language / en-gb / catalog / product.php
ADD - Line 112

Code: Select all

$_['entry_supplier']         = 'Supplier';
IN admin / controller / catalog / product.php
ADD - Line 652 - What is wrong with this?

Code: Select all

		if (isset($this->request->post['location'])) {
			$data['location'] = $this->request->post['location'];
		} elseif (!empty($product_info)) {
			$data['location'] = $product_info['location'];
		} else {
			$data['location'] = '';
		}

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by straightlight » Fri Jun 25, 2021 5:29 pm

What is wrong with this?
An event hasn't been created.

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 Dutch Pride Code » Fri Jun 25, 2021 5:36 pm

straightlight wrote:
Fri Jun 25, 2021 5:29 pm
What is wrong with this?
An event hasn't been created.
Thanks. Can I find an example of the events of other product fields somewhere? ???
EDIT: I think I found it

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by paulfeakins » Fri Jun 25, 2021 7:22 pm

straightlight wrote:
Fri Jun 25, 2021 5:29 pm
What is wrong with this?
An event hasn't been created.
You don't have to use Events but you should use OCMOD or vQmod.

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


User avatar
Guru Member
Online

Posts

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

Post by straightlight » Fri Jun 25, 2021 7:25 pm

paulfeakins wrote:
Fri Jun 25, 2021 7:22 pm
straightlight wrote:
Fri Jun 25, 2021 5:29 pm
What is wrong with this?
An event hasn't been created.
You don't have to use Events but you should use OCMOD or vQmod.
OCMod is on the road of deprecation and VQMod is third party. Which means, Events will be taking the lead on anyhow.

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 paulfeakins » Mon Jun 28, 2021 6:32 pm

straightlight wrote:
Fri Jun 25, 2021 7:25 pm
OCMod is on the road of deprecation and VQMod is third party. Which means, Events will be taking the lead on anyhow.
Yes, so I would suggest vQmod, as there are many things Events cannot do.

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


User avatar
Guru Member
Online

Posts

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

Post by straightlight » Mon Jun 28, 2021 6:36 pm

paulfeakins wrote:
Mon Jun 28, 2021 6:32 pm
straightlight wrote:
Fri Jun 25, 2021 7:25 pm
OCMod is on the road of deprecation and VQMod is third party. Which means, Events will be taking the lead on anyhow.
Yes, so I would suggest vQmod, as there are many things Events cannot do.
Other than private / protected methods, there's nothing the Events cannot do especially with the latest OC release since it's been patched for it.

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 paulfeakins » Mon Jun 28, 2021 6:48 pm

straightlight wrote:
Mon Jun 28, 2021 6:36 pm
Other than private / protected methods, there's nothing the Events cannot do especially with the latest OC release since it's been patched for it.
You can't modify part of a method.

So 2 extensions that use Events cannot make small changes to the same method.

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


User avatar
Guru Member
Online

Posts

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

Post by straightlight » Mon Jun 28, 2021 7:45 pm

paulfeakins wrote:
Mon Jun 28, 2021 6:48 pm
straightlight wrote:
Mon Jun 28, 2021 6:36 pm
Other than private / protected methods, there's nothing the Events cannot do especially with the latest OC release since it's been patched for it.
You can't modify part of a method.

So 2 extensions that use Events cannot make small changes to the same method.
Which is even better in a sense because this methodology also avoids conflicts with other extensions which was also battled a lot on the forum in the past about line conflicts. Now that we're there, in other words, you're rather recommending people to head back to where we were in the first place rather than using Events.

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 by mona » Mon Jun 28, 2021 8:08 pm

Our opinions are of no importance, however the flip side of that argument is the strong possibility that it will create an environment that can end up with all extensions being incompatible with everything and lead to hard coding of all core files and make it impossible to track. So it may well achieve the opposite, which I accept might be the point. Although I also suspect it will just see the return of vQmod.

Events has not been adopted naturally, vQmod was a huge success, OCMOD had some resistance but personally the removing all files was a winner for me .. why fix something that isn’t broken?

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Mon Jun 28, 2021 8:14 pm

by mona wrote:
Mon Jun 28, 2021 8:08 pm
Our opinions are of no importance, however the flip side of that argument is the strong possibility that it will create an environment that can end up with all extensions being incompatible with everything and lead to hard coding of all core files and make it impossible to track. So it may well achieve the opposite, which I accept might be the point. Although I also suspect it will just see the return of vQmod.

Events has not been adopted naturally, vQmod was a huge success, OCMOD had some resistance but personally the removing all files was a winner for me .. why fix something that isn’t broken?
Isn't that coming from another well-known user. As for VQMod, it can only be a huge success when only one or those two extensions are being installed on a store but when it comes to several extensions running in the chain brings opposite results as opposed to Events. While I do agree with the files removal for OCMod, the concept with digging identical lines of codes remains the same with XML markups.

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 JNeuhoff » Mon Jun 28, 2021 8:14 pm

You can't modify part of a method.
Yes, you can. At least in the majority of case I've come across.
Man successful PHP software packages use event handlers, class extensions, or decorator design patterns for extensions or modifications.
XML is a structured markup language for machine- and human-readable documents, it is not meant to be a programming language.

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 » Mon Jun 28, 2021 8:16 pm

JNeuhoff wrote:
Mon Jun 28, 2021 8:14 pm
You can't modify part of a method.
Yes, you can. At least in the majority of case I've come across.
Man successful PHP software packages use event handlers, class extensions, or decorator design patterns for extensions or modifications.
XML is a structured markup language for machine- and human-readable documents, it is not meant to be a programming language.
Couldn't agree more here.

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 by mona » Mon Jun 28, 2021 8:39 pm

@ straightlight - I don’t know which one - it is a common phrase which fits to exactly what I wanted to say.

I did not say that events is not absolutely correct in certain situations and I accept that I could have used events more. However, you chose to miss the point. Events is not used more for a lot of reasons, that is not the point either. The risk that is being taken is that
a. it will in all probability see the return of vQmod.
b. it is likely to cause more incompatibility rather than less
c. it is likely to lead to more hard code changes and replacement of core files
d. chain extensions are less of an issue that completely replacing or hard coding.

I am not adverse to events and again - I have been neglecting some of its advantages, but that is not the same thing as removing OCMOD entirely and not expecting vQmod to return. That is my opinion and I will be asking @JNeuhoff privately at some point to look at what I can’t get it to do and show me how he can get it to do that - but that will cost me his time - how many developers are prepared to do that rather than edit the core file? This is my observation said with respect.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Mon Jun 28, 2021 8:44 pm

by mona wrote:
Mon Jun 28, 2021 8:39 pm
@ straightlight - I don’t know which one - it is a common phrase which fits to exactly what I wanted to say.

I did not say that events is not absolutely correct in certain situations and I accept that I could have used events more. However, you chose to miss the point. Events is not used more for a lot of reasons, that is not the point either. The risk that is being taken is that
a. it will in all probability see the return of vQmod.
b. it is likely to cause more incompatibility rather than less
c. it is likely to lead to more hard code changes and replacement of core files
d. chain extensions are less of an issue that completely replacing or hard coding.

I am not adverse to events and again - I have been neglecting some of its advantages, but that is not the same thing as removing OCMOD entirely and not expecting vQmod to return. That is my opinion and I will be asking @JNeuhoff privately at some point to look at what I can’t get it to do and show me how he can get it to do that - but that will cost me his time - how many developers are prepared to do that rather than edit the core file? This is my observation said with respect.
a. it will in all probability see the return of vQmod.
Opinion.

b. it is likely to cause more incompatibility rather than less
Opinion.

c. it is likely to lead to more hard code changes and replacement of core files
How may that be the case if methods needs to be called back separately from its original core?

d. chain extensions are less of an issue that completely replacing or hard coding.
Opinion.
That is my opinion
Yes, exactly.
how many developers are prepared to do that rather than edit the core file?
Those who are determined and dedicated to properly code their projects will be willing to do so.

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 JNeuhoff » Mon Jun 28, 2021 8:49 pm

From my experience, the biggest challenge I had to overcome, was to modify the twig template in view/*/before events. This has now been possible since OpenCart 3.0.2.0 or later, as well as in the upcoming OpenCart 4.x series.

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 » Mon Jun 28, 2021 8:51 pm

JNeuhoff wrote:
Mon Jun 28, 2021 8:49 pm
From my experience, the biggest challenge I had to overcome, was to modify the twig template in view/*/before events. This has now been possible since OpenCart 3.0.2.0 or later, as well as in the upcoming OpenCart 4.x series.
Correct, which is one of the reasons why I do recommend people to upgrade most of the time since it avoids the fallback to play with the default template in the mean time.

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 by mona » Mon Jun 28, 2021 9:30 pm

@straightlight - yes opinion - just like you have an opinion expressed as if it were fact, but it is still an opinion.
You have no idea about my dedication or the dedication of others, that is your opinion.

You always take intelligent discussions to a level of personal bullying, belittlement and abuse - it is so unnecessary - I value your experience but your manner .. geez - Discussing anything with you is so draining and unproductive.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by by mona » Mon Jun 28, 2021 9:44 pm

@JNeuhoff - edits to twig files that was well worth the effort - thank you.

The issue is editing the method - which of course is the point to have a before and after - but in some cases it is very long winded and in some cases the whole function needs replacing - which of course negates the point entirely. I do try to create my new work using events and 90% my work is independent anyway - so - it is less important to me than many others.

I am not criticising the events system - I am guilty of not using it where I could - but I have my opinion on removing OCMOD entirely that is all - I just think it will not achieve what you all want it to achieve - I think if the many voices are ignored or shouted down you loose the opportunity to avoid the return of vQmod.

I will PM you at some point if that is ok. You have many many many years ago helped me with something when I was very new to opencart - way back when the evil word was began with an M not a J .. wow was I a leper ..

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Mon Jun 28, 2021 9:58 pm

by mona wrote:
Mon Jun 28, 2021 9:30 pm
@straightlight - yes opinion - just like you have an opinion expressed as if it were fact, but it is still an opinion.
You have no idea about my dedication or the dedication of others, that is your opinion.

You always take intelligent discussions to a level of personal bullying, belittlement and abuse - it is so unnecessary - I value your experience but your manner .. geez - Discussing anything with you is so draining and unproductive.
What I stated about the dedication was not to put anyone down but to state as a fact that people who are willing to take that road to develop are able to do it and not about your dedication specifically. As for the bullying part, however, I don't seem to be the one only one getting this expression as others may have read from you. Nonetheless, I will leave that one aside since, unlike other users where the last time you mentioned that to him, I have no interest whatsoever to argue about it.

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