I have a client that wants a simple upsell module based on his specific criteria as he will set the upsell items by hand. I have been able to create the basics for creating a module, being I have the controller, language, and view.tpl files stubbed out and the module is showing in the admin for installation and editing.
From here is I believe I need a model for representing my table to make the calls and encapsulate my simple data, and possibly a controller to make the calls. Also, I need to create a simple 2 column table with product_id for first column and upsell_id for second.
I realize I can just connect to the DB and do that part of the work with SQL and I have looked at some of the other model/controller classes and realize I can do this with brute force by hand coding, but I am assuming there is a more elegant way to accomplish this which will allow install/migration and uninstall/rollback features, I'm just not sure what I am looking for. In Rails, we have migration files for handling DB mods and can scaffle other associated classes when needed.
Thanks for any assistance in advance.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
@Gohloum: Please clarify the request. Forum rules unfollowed.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
My apologies. I am running OC 2.2.0.0 and it's a vanilla install on my local machine.@Gohloum: Please clarify the request. Forum rules unfollowed.
What I mean specifically is in relationship to tables being created and dropped in the database. With a new module/extension feature requiring a new table, what is the best way to go about creating the table? As I have been looking into module development, it would seem that during the installation process for some modules, scripts are run that create these tables on install and drop them on uninstall. Coming from a Rails background, this would make reasonable sense to me as we have migration files for accomplishing the same thing with the database: http://edgeguides.rubyonrails.org/activ ... tions.html So, I am trying to find information about the process of adding tables or columns to existing tables for new custom modules. If there is a preferred method than just adding what I need from the command line in MySQL, then I'd rather follow "Best Practices".What exactly do you want to install/rollback etc? What do you mean by that and what specific functions are you looking for?
So far, the only tutorials I have seen for module development at this point do not have any included information on this. They only have Controller, Language, and View file examples included (like the 'Popular Products' tutorial). Database connectivity with these examples comes from connections already established through the existing products db tables and existing controller. Therefore I am looking for tutorials, articles, information on creating custom modules/extensions that require custom tables and/or columns.
Does this help clarify?
Inside your extension controller module, you have the opportunity to use the install() and uninstall() public method names which automates the operation of database and / or files installation once the store owner hits the install button from the admin - > extensions - > extensions - > modules page.With a new module/extension feature requiring a new table, what is the best way to go about creating the table?
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Sweet! I'm actually reading this before looking at any code. I am assuming that the these functions just need to be overridden to include the necessary SQL queries to setup and tear down DB structures respectively?straightlight wrote: ↑Mon Jul 09, 2018 10:11 pmInside your extension controller module, you have the opportunity to use the install() and uninstall() public method names which automates the operation of database and / or files installation once the store owner hits the install button from the admin - > extensions - > extensions - > modules page.
If so, this seems pretty straight forward. Is there by any chance a tutorial/example that you know of which I can take a quick peek at?
Thanks again, this clarifies a lot!
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Code: Select all
public function install() {
// Your install statement here.
}
Code: Select all
public function uninstall() {
// Your uninstall statement here.
}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Can you please provide an example Controller file (OpenCart 3.x), showing installation/uninstallation of database tables? And where does this Controller file go in the /upload folder? Also, what causes the install() and uninstall() functions in the Controller to be executed when the user clicks the Upload button in Extensions > Installer?
I already have the MySQL code to create and load my two tables, and for testing purposes, I just ran the MySQL code in phpMyAdmin, but I need to automate the creation of the database tables.
I am new to creating extensions, so the statement "Just add install() and uninstall() functions to your controller and make them public" does not provide enough information.
Thanks in advance!
Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers
Users browsing this forum: No registered users and 47 guests