0 Shares 1098 Views 1 Comments

Best Development Practices in Magento 2 – Expert Opinions Included

Wajid Hussain Nov 14, 2016
best-development-practices-in-magento-2

Magento is one of the leading e-commerce platform in the world. Most of the big brands in the world use Magento for their e-business because of its flexibility, reliability and open-source nature.

Nowadays, online businesses that are using other ecommerce platforms are migrating to Magento with rapid pace because of it’s powerful inbuilt functionalities and rich features which continue to evolve, and the best bit is that it’s the only ecommerce platform that is genuinely driven by a community of great developers.

Along came Magento 2…

Just when the world was realizing the true potential of this powerful ecommerce platform, in the end of 2015, Magento released it’s new version “Magento 2” which turns out to be a phenomenal update and in some ways a more advanced version than its predecessor. Magento 2 is powered by PHP framework that really puts a developer’s life to ease.  

Listed below are some of the New Features of Magento 2:

  1. New structure
  2. Full NGINX support
  3. Redis
  4. Full page cache
  5. Varnish cache
  6. CSS preprocessing
  7. CSS and JS Minification
  8. Catalog images caching
  9. Code generation
  10.  Requirejs for improved JS performance
  11. Session storage management
  12. XML validation

Best Development Practices in Magento 2

Now, beside the other ecommerce platforms, Magento 2 specifically is a bit technical and requires advanced development skills. So, a lot of the developers get stuck while in the development process and then they seek expert’s advice from the Magento Community.  

So, we thought, why not directly ask from the experts that in their opinion what are some of the best development practices in Magento 2 and which approach is the best. So, mentioned below are the responses that we got from Magento Developers which can really help anyone who’s just getting started in Magento 2 or even an advanced developer can learn a trick or two. So, here it goes:

marius

Marius Strajeru
Magento Master 2016

The official docs and reverse engineering. That’s all I’ve used so far, and magento stackexchange of course.

 

 

 

tobias

Tobias Hartmann
Lead Frontend Developer at Sitewards

About Magento 2, as I said in the interview, we don’t know about a best practice. We tried to get information about it from conferences and by asking people but there are a lot different opinions about it and I personally think that this is a problem. Such a big framework should give solutions to that and to the modern workflows and should not raise such big questions. So far what we did in a magento 2 project we applied overrides on the frontend styles and switched classes within the templates but did not use the ui lib, how it should be used, because it appears to be too complex. And for sure, as Magento says by its own, don’t base on the Luma theme because it might change completely. The base should be the blank theme. Since the snowdog scss theme is on a good way I would prefer this for upcoming magento 2 projects.

bartek

Bartek Igielski
Front End Developer at Snowdog

– Write everything as a module and keep semantic versioning

– Magento (front-end) codebase isn’t great, remember to follow best practices, not their code standards (i.e. use BEM or other naming methodology, use SASS, ES6…)

– Do code review for every chunk of code and run automated tests – even simples checks using linters (ESLint, SASS-Lint, Stylelint, PHP_CS)

– Report bugs and contribute to Magento project – it’s open source, so if nobody reports a bug or propose some solution, probably it will not be fixed or changed.

vinai

Vinai Kopp
Trainer, Developer, Consultant

I’d say, “Decouple your code as much as possible from Magento 2 implementation details, or, if that isn’t possible, be conscious about the coupling. Wrappers for core classes are a good thing.

Also develop with Varnish as the FPC in mind, so don’t think every request will reach Magento. The built in FPC behavior is different and code that works with it can’t be assumed to work with Varnish.”

 sean

Sean Breeden
Magento Developer at Jamersan

Not sure if anyone else covered this or not but here’s my 2 cents on a good place to start with best practices:

A simple recommendation that I can make for working with Magento 2 is to adopt the same coding standards that Magento is using if you aren’t following them already.

For years, I worked on projects that required fast turnaround times so it caused me to lose focus on the importance of adhering to standards. Quality suffered and my progress seemed to stall out. It wasn’t until I started strictly following coding standards again that I saw significant improvements in my ability to write good code.

Magento recommends following the Basic Coding Standard and Coding Style Guide when creating extensions. There’s a lot of common sense things in there that any developer can use to improve. Not only will your code become easily readable, it may have a possibly surprising side-effect of increasing your skills!

Basic Coding Standard – http://www.php-fig.org/psr/psr-1/

Coding Style Guide – http://www.php-fig.org/psr/psr-2/

daniele

Daniele Rutigliano
CEO Ecommerce manager at Aproweb web agency

First of all it is necessary to analyze the needs of commitment and the features of the project. In some cases Magento 2 could be not right version and there are not knowledge and plugins to fast use.

At the second you have to install your ecommerce on test server. As with Magento 1.x you have not edit the core software but to use the override way. At the end check the log files and resolve ALL bugs and errors: your Magento will be faster.

riccardo

Riccardo Tempesta
Co-Foundeer, CTO at IDEALIAGROUP srl

Fighting against Magento 2 coding can be an hard work and it requires good programming skills and framework knowledge.

There are good practices you can follow to achieve a good result. With “good result” we mean a better stability, a shorter coding time and less headaches.

We wrote down 10 of the most important rules in the Magento programmers life:

Rule 1.
Never start coding Magento 2 without knowing at least a bit of Magento 2 framework theory. Magento 2 is one of the most complex framework in the world and exploring its code without knowing where to search can be really frustrating.

Rule 2.
Always follow Magento 2 coding guidelines, because you will not probably be the only one working on your code. Remember: “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”

Rule 3.
Magento 2 requires a lot of additional coding but it is based on simple and clear concepts, so if it is too complicated then probably it is not the right way to do it.

Rule 4.
Do not waste your time and use tools like “MSP_CodeMonkey” or “MSP_DevTools” to automatically write boilerplate code and debug your application. They are free while your time is not. They do not make mistake while you can.

Rule 5.
Use the right IDE, we use PhpStorm with Magicento2 and xdebug integration. They save you a lot of time. We know it is not cool as programming with “vi”, but we are in 2016.

Rule 6.
If you do not know how to do it, then look at Magento source code. Magento code is often a source of inspiration when you are approaching something new.

Rule 7.
Write integration tests and test units. Upgrading a Magento version can break some of you custom modules or third party modules and integration tests can save your week-end.

Rule 8.
Always use git to version your code, use an automated deployment tool like capistrano and use a local virtual machine for development (vagrant or docker can be good tools).

Rule 9.
Be careful when using third party modules, someone did not correctly understand rule number 2. Before using them in production take some time to explore their code and make sure they are ok.

Rule 10.
You do not talk about Fight Club.

So, there you go! Magento Developers and experts have shared their experiences regarding the Best Development Practices in Magento 2. Now, you might agree or disagree with the methods stated in it, and that’s perfectly fine. As I said before, Magento is a community-driven platform, so everyone is welcome to share their experiences.

If there’s anything you’d like to share regarding development practices in Magento 2, feel free to share with us in the comments section below.

Wajid Hussain

Wajid Hussain

Community Manager at Arpatech
Wajid Hussain has a vast experience in Magento and PHP fields. He is currently a Community Manager at Arpatech. He keeps himself engaged with latest e-commerce and Magento trends and also happens to be an avid football fan. You can follow him on Twitter at @wajidstack or contact him through e-mail wajid.hussain[at]arpatech.com
Wajid Hussain
  • Manish Mittal

    Thanks Mr Wajid..Post is very helpful!