General Questions

Getting started with Magento – Part 1

· 2 min read >

When I started working with Magento, I gradually learned. Some things I learned right away, others I learned about a long time later. Sometimes I come across information and think: “That would have helped me a lot in the beginning”. So I’m going to put together some brief information in a series of posts. I hope it helps you in your studies.

1. Deploy mode

It is important to know Magento’s deployment modes. If you are developing a store, it is interesting to use developer mode. If the store is already published and ready to sell, it must be in production mode.

When we clone a store that is in production to our local environment, we change the deployment mode of this copy to developer.

To see which mode is currently configured in the store, you can use the following command:

bin/magento deploy:mode:show

Magento has four modes (check the documentation here):

  • Production: Faster mode, uses all caches, files are precompiled and errors are logged in files.
  • Developer: Slower, file compilation takes place in real time, errors are shown to the user and the log is detailed.
  • Default: Hybrid of developer and production modes. It is the default mode and is already defined in the Magento installation.
  • Maintenance: When active, redirects users to a “Service Temporarily Unavailable” page and the .maintenance.flag file is created in the var/ directory.

2. Sample data

Very useful for studying. Magento has modules that inject sample content into the store. So, in a few minutes, we have a store with customers, orders, product, pages and blocks.

In the devdocs we have a few ways to install sample data. Remembering that I do not recommend that it be installed in stores that are being developed to go into production. I only recommend using it for study purposes.

3. Vendor x App

Composer modules are placed in the vendor/ directory. These files are not versioned and we must not make changes to them (just like we shouldn’t edit files inside pub/static/ directory). Our tweaks and any development is centered in the app/ directory. Modules are placed in app/code/ and themes in app/design/.

4. Naming conventions

There are conventions for module names. The module name, for example, follows the pattern Vendor_MyModule. The vendor is a unique name. For example, Magento core modules are named Magento. In the modules I develop for study, I put the vendor name as Salzano.

The module name is written in UpperCamelCase. So, for example, Magento’s Product Alert module is named Magento_ProductAlert.

There is a module name that we should avoid in our customizations: the term Ui. According to the Magento documentation, “Vendor_Ui notation, required when specifying paths, might cause issues”.

5. Template Hints

Need to change a page template but have no idea where the file is?

A quick way to find it is to enable Magento template hints. This can be done either from the admin panel or from the command line.

From the admin panel this can be done in Stores -> Settings -> Advanced -> Developer. In Debug tab set Enable Hints for Storefront with URL Parameter to Yes. I usually use with parameter option in URL. So I enable the hints by adding ?templatehints=magento to the URL.

Another way to enable it is with the command:

bin/magento dev:template-hints:enable

And to disable:

bin/magento dev:template-hints:disable

About the image that illustrates this post

Landscape with Two Oaks - Jan van Goyen
Landscape with Two Oaks, Jan van Goyen, 1641

“Landscape with Two Oaks”, by Jan van Goyes, done in 1641. Taken from the Rijksmuseum’s art collection, the national museum of the Netherlands.

“The two gnarled oak trees, brightly illuminated by a few rays of sunlight, stand out sharply against the threatening sky. Van Goyen drew the trees with his brush. He used thin, almost transparent paint for the foliage and thick, grainy paint for the furrowed trunks. The landscape’s near monochrome palette is enlivened by the blue and red doublets of the two figures resting.”