Back to Top

Access Opencart data through command line

Updated 7 April 2016

Opencart, in version, released support of composer and lots of other things. But still opencart lack in operating through command line, if anyone wishes to do so. Today we’ll learn how to start using opencart from command line (ubuntu). This will be done using Symfony console component through composer.

At the very first we’ll install composer at the root directory on opencart installation and include below composer.json file.


After creating json file, install it and you’ll get vendor directory. Create a directory named app and a file named console, which will have below screenshots code.


Searching for an experienced
Opencart Company ?
Find out More

Now in the root directory create structure as src>PhpMaster->Command, in Command directory create a file of your choice as I’ve created GetProduct.php.

In the starting of the file define everything as it is in below screenshots.


Now class GetProduct will have two main methods, configure and execute. These are the two main method that is used to configure the command and execute it.

Configure method will contain details about the command like it’s name, option or any other information about the command as you can see in below screenshot-


Execute method is used to do the defined task by the above command, like I’ve written the class to get product detail in your system’s command prompt.So here the scenario come in the scene that how it will connect to the database, so for this, the simplest way it to include the config.php file and create your own connection to the database, or you can also use opencart’s defined method to connect. Below I’ve used my own connection method that is same as opencart.



Now run the command (app/console phpmaster:GetProduct -p 30) as below and you’ll get the desired result that you have rendered in the execute method. To display content in tabular form I’ve used component’s table format.



. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home