Post by Gohloum » Sun Jul 08, 2018 10:43 am

Hello,

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.

Newbie

Posts

Joined
Sun May 13, 2018 10:41 am

Post by thekrotek » Sun Jul 08, 2018 4:47 pm

What exactly do you want to install/rollback etc? What do you mean by that and what specific functions are you looking for?

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 straightlight » Sun Jul 08, 2018 9:24 pm

Request unclarified. However, the user did mentioned he is not sure what he's looking for.

@Gohloum: Please clarify the request. Forum rules unfollowed.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Gohloum » Mon Jul 09, 2018 9:52 pm

@Gohloum: Please clarify the request. Forum rules unfollowed.
My apologies. I am running OC 2.2.0.0 and it's a vanilla install on my local machine.
What exactly do you want to install/rollback etc? What do you mean by that and what specific functions are you looking for?
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".

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?

Newbie

Posts

Joined
Sun May 13, 2018 10:41 am

Post by straightlight » Mon Jul 09, 2018 10:11 pm

With a new module/extension feature requiring a new table, what is the best way to go about creating the table?
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. :)

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Gohloum » Mon Jul 09, 2018 11:11 pm

straightlight wrote:
Mon Jul 09, 2018 10:11 pm
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. :)
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?

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!

Newbie

Posts

Joined
Sun May 13, 2018 10:41 am

Post by thekrotek » Mon Jul 09, 2018 11:22 pm

Just add install() and uninstall() functions to your controller and make them public, that's all. Do everything you like with database inside these functions.

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 straightlight » Mon Jul 09, 2018 11:31 pm

After the index() block of codes, below the closing statement near the button, just add the following names and add your statements in them:

Code: Select all

public function install() {
    // Your install statement here.
}

Code: Select all

public function uninstall() {
    // Your uninstall statement here.
}

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Gohloum » Mon Jul 09, 2018 11:39 pm

Thanks guys for the info and very speedy responses! Kudos to you and happy coding! :)

Newbie

Posts

Joined
Sun May 13, 2018 10:41 am

Post by glolar » Wed May 06, 2020 11:38 pm

thekrotek wrote:
Mon Jul 09, 2018 11:22 pm
Just add install() and uninstall() functions to your controller and make them public, that's all. Do everything you like with database inside these functions.
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


User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA
Who is online

Users browsing this forum: No registered users and 12 guests