January 12, 2024

Magento 2 – Useful Commands for Developers – Part 1

Welcome to a blog tailored for seasoned Magento 2 developers, designed to enhance your skills in Magento Development. In this comprehensive guide, we’ll explore lesser-known commands like dev:di:info, shedding light on their significance for efficient Magento website development. Whether you’re a solo developer or part of a Magento Development Company, mastering these commands will undoubtedly elevate your expertise, making you an invaluable asset in the world of Magento for eCommerce development. As we unravel the potential of setup:backup and setup:rollback, your toolkit expands, ensuring seamless development practices that are highly sought after by those looking to Hire Magento Developers for their projects. Join us on this journey to amplify your Magento Development game and contribute to the success of eCommerce ventures powered by Magento.

bin/magento dev:di:info

What does it do?

When you execute php bin/magento dev:di:info followed by the name of a class, say “Magento\Catalog\Model\Product,” magic unfolds. This command provides a comprehensive breakdown of the Dependency Injection (DI) configuration for that class, giving you a detailed insight into its inner workings.

Why is it Useful?

  1. Constructor Details: Get a clear view of all the constructor parameters, including their names, requested types, and configured values. This is invaluable when extending Magento classes, ensuring you’re aware of all dependencies.

  2. Class Extension Information: If the class is extended elsewhere in the codebase, dev:di:info reveals the extending class. This insight is crucial for understanding class hierarchies and avoiding unexpected overrides.

  3. Plugins Overview: Discover all plugins attached to different methods of the class. This is especially helpful when dealing with customization, as it outlines the chain of actions performed on the class.

				
					DI configuration for the class Magento\Catalog\Model\Product in the GLOBAL area

Preference: Magento\Catalog\Model\Product\Interceptor

Constructor Parameters:
+--------------------------------+--------------------------------------------------------------------------+------------------+
| Name                           | Requested Type                                                           | Configured Value |
+--------------------------------+--------------------------------------------------------------------------+------------------+
| context                        | Magento\Framework\Model\Context                                          |                  |
| registry                       | Magento\Framework\Registry                                               |                  |
| extensionFactory               | Magento\Framework\Api\ExtensionAttributesFactory                         |                  |
| customAttributeFactory         | Magento\Framework\Api\AttributeValueFactory                              |                  |
| storeManager                   | Magento\Store\Model\StoreManagerInterface                                |                  |
| metadataService                | Magento\Catalog\Api\ProductAttributeRepositoryInterface                  |                  |
| url                            | Magento\Catalog\Model\Product\Url                                        |                  |
| productLink                    | Magento\Catalog\Model\Product\Link                                       |                  |
| itemOptionFactory              | Magento\Catalog\Model\Product\Configuration\Item\OptionFactory           |                  |
| stockItemFactory               | Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory              |                  |
| catalogProductOptionFactory    | Magento\Catalog\Model\Product\OptionFactory                              |                  |
| catalogProductVisibility       | Magento\Catalog\Model\Product\Visibility                                 |                  |
| catalogProductStatus           | Magento\Catalog\Model\Product\Attribute\Source\Status                    |                  |
| catalogProductMediaConfig      | Magento\Catalog\Model\Product\Media\Config                               |                  |
| catalogProductType             | Magento\Catalog\Model\Product\Type                                       |                  |
| moduleManager                  | Magento\Framework\Module\Manager                                         |                  |
| catalogProduct                 | Magento\Catalog\Helper\Product                                           |                  |
| resource                       | Magento\Catalog\Model\ResourceModel\Product                              |                  |
| resourceCollection             | Magento\Catalog\Model\ResourceModel\Product\Collection                   |                  |
| collectionFactory              | Magento\Framework\Data\CollectionFactory                                 |                  |
| filesystem                     | Magento\Framework\Filesystem                                             |                  |
| indexerRegistry                | Magento\Framework\Indexer\IndexerRegistry                                |                  |
| productFlatIndexerProcessor    | Magento\Catalog\Model\Indexer\Product\Flat\Processor                     |                  |
| productPriceIndexerProcessor   | Magento\Catalog\Model\Indexer\Product\Price\Processor                    |                  |
| productEavIndexerProcessor     | Magento\Catalog\Model\Indexer\Product\Eav\Processor                      |                  |
| categoryRepository             | Magento\Catalog\Api\CategoryRepositoryInterface                          |                  |
| imageCacheFactory              | Magento\Catalog\Model\Product\Image\CacheFactory                         |                  |
| entityCollectionProvider       | Magento\Catalog\Model\ProductLink\CollectionProvider                     |                  |
| linkTypeProvider               | Magento\Catalog\Model\Product\LinkTypeProvider                           |                  |
| productLinkFactory             | Magento\Catalog\Api\Data\ProductLinkInterfaceFactory                     |                  |
| productLinkExtensionFactory    | Magento\Catalog\Api\Data\ProductLinkExtensionFactory                     |                  |
| mediaGalleryEntryConverterPool | Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool |                  |
| dataObjectHelper               | Magento\Framework\Api\DataObjectHelper                                   |                  |
| joinProcessor                  | Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface          |                  |
| data                           |                                                                          | <empty array>    |
| config                         | Magento\Eav\Model\Config                                                 |                  |
| filterCustomAttribute          | Magento\Catalog\Model\FilterProductCustomAttribute                       |                  |
+--------------------------------+--------------------------------------------------------------------------+------------------+


Plugins:
+--------------------------------------------------------------------+--------------------+-------+
| Plugin                                                             | Method             | Type  |
+--------------------------------------------------------------------+--------------------+-------+
| Magento\CatalogInventory\Model\Plugin\AfterProductLoad             | load               | after |
| Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender | getIdentities      | after |
| Magento\Swatches\Model\Plugin\Product                              | getMediaAttributes | after |
| Magento\Cms\Model\Plugin\Product                                   | getIdentities      | after |
| Magento\Bundle\Model\Plugin\ProductIdentitiesExtender              | getIdentities      | after |
+--------------------------------------------------------------------+--------------------+-------+


Plugins for the Preference:
+--------------------------------------------------------------------+--------------------+-------+
| Plugin                                                             | Method             | Type  |
+--------------------------------------------------------------------+--------------------+-------+
| Magento\CatalogInventory\Model\Plugin\AfterProductLoad             | load               | after |
| Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender | getIdentities      | after |
| Magento\Swatches\Model\Plugin\Product                              | getMediaAttributes | after |
| Magento\Cms\Model\Plugin\Product                                   | getIdentities      | after |
| Magento\Bundle\Model\Plugin\ProductIdentitiesExtender              | getIdentities      | after |
+--------------------------------------------------------------------+--------------------+-------+

				
			
bin/magento setup:backup

What does it do?

Running php bin/magento setup:backup allows you to generate a backup of the complete codebase, media, and database. This command simplifies the backup process, offering a convenient snapshot of your Magento instance.

Why is it Useful?

  1. Comprehensive Backup: Create a backup encompassing the entire codebase, media files, and database, ensuring a comprehensive safety net.

  2. Effortless Execution: The straightforward command format (php bin/magento setup:backup) streamlines the backup process, making it accessible even for developers with minimal Magento command-line experience.

  3. Snapshot for Security: Before major changes, updates, or deployments, use setup:backup to create a snapshot. In case of unforeseen issues, you can swiftly revert to a known stable state.

bin/magento setup:rollback

What does it do?

Utilize php bin/magento setup:rollback when you need to roll back from backup files. This command allows you to revert to a previous state, mitigating potential issues and ensuring a smooth development process.

Why is it Useful?

  1. Recovery from Issues: When changes lead to unexpected problems, setup:rollback provides a straightforward way to return to a stable state.

  2. Code, Media, and Database Rollback: Roll back codebase, media files, and database changes simultaneously, ensuring consistency in your Magento instance.

  3. Handy Troubleshooting: In the face of unforeseen challenges, the ability to quickly roll back changes aids in troubleshooting and maintaining a reliable development environment.

In conclusion, armed with insights from dev:di:info, the resilience offered by setup:backup, and the safety net of setup:rollback, seasoned Magento 2 developers now possess a formidable arsenal. Navigating the intricate landscape of class customization and troubleshooting, whether working individually or within a Magento Development Company, becomes more accessible. These commands stand as pillars of support for seamless Magento website development, reinforcing your role as a sought-after developer in the thriving Magento ecosystem. As you continue your Magento 2 development journey, may these tools empower you to deliver exceptional results, whether you’re hired for Magento development projects or contributing to the success of eCommerce ventures. Here’s to a future of elevated Magento Development expertise!

Author

Share this post:
Facebook
Twitter
LinkedIn
WhatsApp

Discover more articles