Read More
Read More
Menu Close

    Access Opencart data through command line

    Opencart, in version 2.2.0.0, 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.

    01

    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.

    02

    Searching for an experienced
    Opencart Company ?
    Read 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.

    03

    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-

    04

    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.

    05

    06

    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.

    07

     

    . . .
    Discuss on Helpdesk

    Leave a Comment

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


    Be the first to comment.

    Back to Top