Post by hrevis25 » Thu Aug 01, 2019 5:47 am

Hello,
I'm just starting to develop some simple opencart extensions with the use of vqmod and i'd like to ask where should i place the sql alteration code of the db in order to add a new column in the db..

Thanks

Active Member

Posts

Joined
Wed Apr 19, 2017 8:27 pm

Post by OSWorX » Thu Aug 01, 2019 4:08 pm

wh1t3man2nd wrote:
Thu Aug 01, 2019 5:47 am
I'm just starting to develop some simple opencart extensions with the use of vqmod and i'd like to ask where should i place the sql alteration code of the db in order to add a new column in the db..
1. forget VQMod, use OCMod
2. simply add the code for the database inside the main controller of the extension
3. if you do not use any controller, only with VQMod or OCMod touching the database is not possible

If you plan to publish that extension, then:
4. if you want to manipulate an existing table, forget that also
5. create a new table (do not touch existing tables)

otherwise you can do what you want.

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


User avatar
Guru Member

Posts

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

Post by thekrotek » Thu Aug 01, 2019 4:30 pm

OSWorX wrote:
Thu Aug 01, 2019 4:08 pm
3. if you do not use any controller, only with VQMod or OCMod touching the database is not possible
This, of course, is not true. You can do whatever you want with the database by adding queries to any places you need. And yes, it includes creating new tables as well

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by OSWorX » Thu Aug 01, 2019 5:16 pm

thekrotek wrote:
Thu Aug 01, 2019 4:30 pm
OSWorX wrote:
Thu Aug 01, 2019 4:08 pm
3. if you do not use any controller, only with VQMod or OCMod touching the database is not possible
This, of course, is not true. You can do whatever you want with the database by adding queries to any places you need. And yes, it includes creating new tables as well
Partly correct.
You cannot add code to any VQMod or OCMod which manipulates directly the database.

What is possible, is to create some lines which are added to any controller or model - and there you can do what you need/want.
Which is aquivalent to:
.. by adding queries to any places you need ..
Which is also not 100% correct, because you cannot add such queries inside template files (.php and/or .tpl or/and .twig) (have seen such already!).

@krotek: if you answer a question, then in a way it is clear and noobs do not misunderstand!

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


User avatar
Guru Member

Posts

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

Post by thekrotek » Thu Aug 01, 2019 5:23 pm

OSWorX wrote:
Thu Aug 01, 2019 5:16 pm
Partly correct.
Partly correct and "touching the database is not possible" are two different things, which was the point. It doesn't really matter, if you use a controller to create a table or XML file to add a corresponding function to another controller. One way or another you have to execute the controller class. So it's actually "possible" versus "not possible". It's not only possible, but very much valid in most cases, when you need to complete a simple task. Instead of creating a whole controller, you can create a simple modification, which will do the same, but with the less code.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by hrevis25 » Thu Aug 01, 2019 9:10 pm

OSWorX wrote:
Thu Aug 01, 2019 4:08 pm
wh1t3man2nd wrote:
Thu Aug 01, 2019 5:47 am
I'm just starting to develop some simple opencart extensions with the use of vqmod and i'd like to ask where should i place the sql alteration code of the db in order to add a new column in the db..
1. forget VQMod, use OCMod
2. simply add the code for the database inside the main controller of the extension
3. if you do not use any controller, only with VQMod or OCMod touching the database is not possible

If you plan to publish that extension, then:
4. if you want to manipulate an existing table, forget that also
5. create a new table (do not touch existing tables)

otherwise you can do what you want.
Well, what i did was to create a basic module controller and then create a "protected" function that checks for the existence of the db column.

As for the one you say about creating a new table i find it a bit useless for this particular function, since it will be an "on - off" switch for showing a particular field of the product.

Active Member

Posts

Joined
Wed Apr 19, 2017 8:27 pm

Post by hrevis25 » Thu Aug 01, 2019 9:11 pm

thekrotek wrote:
Thu Aug 01, 2019 5:23 pm
OSWorX wrote:
Thu Aug 01, 2019 5:16 pm
Partly correct.
Partly correct and "touching the database is not possible" are two different things, which was the point. It doesn't really matter, if you use a controller to create a table or XML file to add a corresponding function to another controller. One way or another you have to execute the controller class. So it's actually "possible" versus "not possible". It's not only possible, but very much valid in most cases, when you need to complete a simple task. Instead of creating a whole controller, you can create a simple modification, which will do the same, but with the less code.
In my case i've just created an index controller and created a function that checks for the db fields.

Active Member

Posts

Joined
Wed Apr 19, 2017 8:27 pm

Post by OSWorX » Fri Aug 02, 2019 1:06 am

wh1t3man2nd wrote:
Thu Aug 01, 2019 9:10 pm
As for the one you say about creating a new table i find it a bit useless for this particular function, since it will be an "on - off" switch for showing a particular field of the product.
That has a good reason!
In the case you (or somebody else) create a new extension and want to publish it in the OpenCart Marketplace (there also compatible for the OpenCart Cloud), you are not allowed to manipulate existing tables!
You are only allowed to create a new table and call the values of that newly created table additionally.

That's why.

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


User avatar
Guru Member

Posts

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

Post by hrevis25 » Tue Aug 06, 2019 1:48 am

OSWorX wrote:
Fri Aug 02, 2019 1:06 am
wh1t3man2nd wrote:
Thu Aug 01, 2019 9:10 pm
As for the one you say about creating a new table i find it a bit useless for this particular function, since it will be an "on - off" switch for showing a particular field of the product.
That has a good reason!
In the case you (or somebody else) create a new extension and want to publish it in the OpenCart Marketplace (there also compatible for the OpenCart Cloud), you are not allowed to manipulate existing tables!
You are only allowed to create a new table and call the values of that newly created table additionally.

That's why.
Ok finally found it! Had to check it for my own, since i had to understand the install and uninstall function!

I've added the queries in those two functions! Thanks though for any help provided!!

Active Member

Posts

Joined
Wed Apr 19, 2017 8:27 pm

Post by OSWorX » Tue Aug 06, 2019 4:03 am

wh1t3man2nd wrote:
Tue Aug 06, 2019 1:48 am
Ok finally found it! Had to check it for my own, since i had to understand the install and uninstall function!

I've added the queries in those two functions! Thanks though for any help provided!!
Just to add what is meant.

Since OpenCart 2.x the core has 2 included functions (can be found inside the file admin/controller/extension/extension/XXXX.php).
XXXX has to be replaced by module, payment, and so on ..

These 2 funtions are:
1. install
2. uninstall


Both are installing/uninstalling the extension and set correct user permissions (only for the user who is installing it !).
And inside both, they check if the extension itself has also these 2 functions: install and uninstall.

IF they exist, the developer can add inside whatever he wants to be installed (or also uninstalled).
Also creating new database tables.

That's all in short.

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


User avatar
Guru Member

Posts

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

Users browsing this forum: No registered users and 44 guests