Post by lolx » Tue Jan 17, 2017 2:13 pm

Hi there,

I am creating a script I want to run with a cron but I don't want to hook it up to my store as a plugin.

I would like to copy some of the functions from a model but they all use the database object ($this->db->query(...)

Is there a way I can use this object in a script that isn't connected to my store?


If so can you guide me regarding what files I needs to include?

Newbie

Posts

Joined
Sat Oct 22, 2011 1:26 pm

Post by mikeross » Thu Mar 09, 2017 4:19 pm

I'm no moderator, but here's my suggestion. Use PHP and it's PDO library to gain access to the MySQL database for this. As for what SQL queries to run, look in the catalog/model/catalog/product.php model class file as an example. I still don't know if there's a way to load some framework wrapper class that loads the config file and the database classes, and then loads this model class -- that's not documented well enough for me yet to know. However, at least I can look at that product.php file and know how OpenCart's database schema works so that I can do the proper SQL queries for what I need. If you struggled with the code a bit, you might be able to write your own wrapper class that loads the database config file, the database class file, and then the product model class. That would allow you to do queries without having to type so many SQL statements. Plus, as the model classes have new features and bug fixes, which might break your existing SQL queries, you can get around that problem because you won't be doing direct SQL in such a case.

Newbie

Posts

Joined
Thu Mar 09, 2017 10:50 am

Post by lolx » Thu Mar 09, 2017 11:36 pm

mikeross wrote:
Thu Mar 09, 2017 4:19 pm
I'm no moderator, but here's my suggestion. Use PHP and it's PDO library to gain access to the MySQL database for this. As for what SQL queries to run, look in the catalog/model/catalog/product.php model class file as an example. I still don't know if there's a way to load some framework wrapper class that loads the config file and the database classes, and then loads this model class -- that's not documented well enough for me yet to know. However, at least I can look at that product.php file and know how OpenCart's database schema works so that I can do the proper SQL queries for what I need. If you struggled with the code a bit, you might be able to write your own wrapper class that loads the database config file, the database class file, and then the product model class. That would allow you to do queries without having to type so many SQL statements. Plus, as the model classes have new features and bug fixes, which might break your existing SQL queries, you can get around that problem because you won't be doing direct SQL in such a case.
Hi Mike!

Thanks for replying. What I ended up doing is taking the database queries in the model and just removing the opencart model. This way I could use the same functions without OpenCart's built in database wrapper because I couldn't figure out how to load that.

Newbie

Posts

Joined
Sat Oct 22, 2011 1:26 pm
Who is online

Users browsing this forum: No registered users and 7 guests