A great friend for Magento 2 developers is coming out soon

It’s been a while since I’ve thinking about a great tool that could help me out on my Magento 2 development process. I’ve checked out some of great CLI options like N98-Magerun, by Netz98, and Pestle created by Alan Storm. These are the two greatest tools that I’ve come across since when I started working with Magento back in 2010. Another great option a tool crafted as a plugin for PHPStorm IDE and called Magicento, created by Enrique Piatti and used by a lot of Magento developer all around the world.

Yeah, I admit that these kind of tool sometimes can make a Magento developer to not understand the workflow process and required process about Magento development but I thing that some things needs to be studied only a few times before being completely understood. One good example of that is the grid and form creation process for Magento administration panel, which requires some steps to be completed but once your understand all the files and processes involved in this creation it becomes a kind of boring job working on them every time you need a new admin form or grid. Why not to use a tool to make this work for you while you’re focusing in what really interests: the logic and business rule behind this creation.

Imagine a powerful tool that could create every piece of a Magento 2 module for you, or even more, a tool that could create the base of any kind of module your need to do. Yeah, I’m talking about an automator for Magento 2 development process that you could create the base of an entire payment module with. This tool could help you to spend more time implementing the logic and business rule that you need in your module and stop going to Google to get answers for your grid or form that are not working. Believe me, there’s a lot of pain when trivial things like that doesn’t work properly and it can make you to spend some hours of your life trying to understand the whys.

I’ve been given a lot of thoughts on that and them I decided to create a tool for my own use when I’m developing with Magento 2. Today, this tool is really far away from being the most complete or the most powerful CLI tool for working with Magento 2 but it’s intended to be one of the greatest tools that can help out a lot of Magento 2 developers in the all around the world in next months.

This tool is called Magentor. Why did I give this name to this tool? Well, it’s intended to make your life better and reduce the suffering of your life as a Magento 2 developer. I use to say that it’s your Magento Mentor.

It’s fully crafted up in PHP and it’s been created for be as simple as possible. For example, you could use this terminal command (from Magento 2’s root directory) to create a simple model for your module:

> magentor make:model <Model Class Name> <Module Name> <Vendor Name>

This line of tools would create a file for you in the following directory:

<Magento Root>/app/code/<Vendor Name>/<Module Name>/Model/<Model Class Name>

Then you can ask me if you need to pass the Vendor Name and Module name parameters every time you need to create a module. The answer is no! Let’s suppose that rather than running this command from Magento 2’s root directory you change the directory to /app/code// with the following command:

> cd <Magento Root>/app/code/<Vendor Name>/<Module Name>

In this case, Magentor was created to understand that you are into a module context so you can run a command with a fewer arguments:

> magentor make:model <Model Class Name>

This would have the same effect but using the current module directory for creating the model file.

Now, let’s suppose you want to create a Model, a Resource Model and a Resource Collection. Do you need to run three separated commands to achieve that? No! Why should you, man? Just add a simple option to your command and Magentor will understand what it needs to do:

> magentor make:model <Model Class Name> --create-resources

As you can see we only added the —create-resources option to the command but we can make it shorter:

> magentor make:model <Model Class Name> -r

That’s fine! Our model will be created along with its related resource models.

Assuming that our vendor would be Magentor, our module name would be CustomerChanges and our class would be Customer/Address the following files would be created with the above command.

Magentor/CustomerChanges/Model/Customer/Address.php
<?php

/**
 * Proudly powered by Magentor CLI!
 * Version v0.1.0
 * Official Repository: http://github.com/tiagosampaio/magentor
 *
 * @author Tiago Sampaio <tiago@tiagosampaio.com>
 */

namespace Magentor\CustomerChanges\Model\Customer;

use Magento\Framework\Model\AbstractModel;
use Magentor\CustomerChanges\Model\ResourceModel\Customer\Address as ResourceModel;

class Address extends AbstractModel
{
    /**
     * Initialize resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init(ResourceModel::class);
    }
}
Magentor/CustomerChanges/Model/ResourceModel/Customer/Address.php
<?php

/**
 * Proudly powered by Magentor CLI!
 * Version v0.1.0
 * Official Repository: http://github.com/tiagosampaio/magentor
 *
 * @author Tiago Sampaio <tiago@tiagosampaio.com>
 */

namespace Magentor\CustomerChanges\Model\ResourceModel\Customer;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;

class Address extends AbstractDb
{
    /**
     * Initialize database relation.
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init('table_name', 'field_name');
    }
}
Magentor/CustomerChanges/Model/ResourceModel/Customer/Address/Collection.php
<?php

/**
 * Proudly powered by Magentor CLI!
 * Version v0.1.0
 * Official Repository: https://github.com/tiagosampaio/magentor
 *
 * @author Tiago Sampaio <tiago@tiagosampaio.com>
 */

namespace Magentor\CustomerChanges\Model\ResourceModel\Customer\Address;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magentor\CustomerChanges\Model\Customer\Address;
use Magentor\CustomerChanges\Model\ResourceModel\Customer\Address as ResourceModel;

class Collection extends AbstractCollection
{
    /**
     * Initialize resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init(Address::class, ResourceModel::class);
    }
}

This is a simple task that Magentor can help you with and much more is coming soon.

If you wan to check this out and be inside of all the resources it’s going to have in the near future or if you want to contribute with the core development, please follow this project on Github in the official repository.

https://github.com/tiagosampaio/magentor

And remember, since this is a tool which is under development, don’t use it in production server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s