Magento (Adobe Commerce) Developer Reference & Cheatsheet
Learning Path
flowchart LR
A["Magento Overview"] --> B["Core Concepts"]
B --> C["Intermediate Topics"]
C --> D["Advanced Topics"]
D --> E["Practical Applications"]
A --> F["You Are Here"]
style F fill:#f90,color:#fff
Magento (now Adobe Commerce) is the leading enterprise e-commerce platform. Unlike WordPress (blogging turned CMS) or Drupal (content management framework), Magento was built from the ground up for selling products online. Its architecture reflects this focus: EAV for flexible product attributes, XML layouts for theme customization, and a plugin system for extending behavior without modifying core.
What You’ll Find
- Module directory structure (Vendor_Module convention)
- Layout XML — placing blocks in page containers
- Dependency injection with di.xml and plugins
- EAV (Entity-Attribute-Value) product model
- Common CLI commands for daily operations
- Checkout customization approach
Module Structure
Magento modules follow the Vendor_Module naming convention:
app/code/Vendor/Module/
├── etc/
│ ├── module.xml # Module declaration
│ └── di.xml # Dependency injection config
├── Block/ # View blocks (template data providers)
├── Controller/ # Controllers (request handlers)
├── Model/ # Business logic and models
├── view/
│ ├── frontend/ # Storefront templates and layouts
│ └── adminhtml/ # Admin panel templates and layouts
└── registration.php # Module registration<?php
// registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
?>
<!-- etc/module.xml -->
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0"/>
</config>Layout XML
Layout XML defines which blocks appear on which pages and in which order. Think of it as a blueprint for the page structure.
<!-- view/frontend/layout/catalog_product_view.xml -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Vendor\Module\Block\CustomInfo"
name="custom.info"
template="Vendor_Module::info.phtml"
after="product.info.main"/>
</referenceContainer>
</body>
</page>Common Layout Instructions
| Directive | Description |
|---|---|
referenceContainer | Target an existing container to modify |
referenceBlock | Target an existing block to modify |
block | Add a new block |
remove | Remove an existing block |
before / after | Position relative to another element |
move | Move a block to a different container |
Dependency Injection (di.xml)
Magento uses dependency injection extensively. The di.xml file configures class preferences, plugins, and virtual types.
Plugins (Interceptors)
Plugins let you modify the behavior of any public method without changing the original class:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Product">
<plugin name="custom_product_plugin"
type="Vendor\Module\Plugin\ProductPlugin"
sortOrder="10"/>
</type>
</config><?php
// Plugin methods: before, around, after
namespace Vendor\Module\Plugin;
class ProductPlugin
{
// before — modify arguments before the original method runs
public function beforeSetName(\Magento\Catalog\Model\Product $subject, $name)
{
return ['[Custom] ' . $name];
}
// after — modify the return value after the original method runs
public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
{
return $result . ' (Modified)';
}
// around — wrap the original method (full control)
public function aroundSave(
\Magento\Catalog\Model\Product $subject,
callable $proceed
) {
// Before original call
$result = $proceed(); // Call original method
// After original call
return $result;
}
}
?>
EAV (Entity-Attribute-Value)
Magento uses EAV for products and customer data. Instead of a fixed table schema, attributes are stored as rows in a value table:
<?php
// Working with product EAV attributes
$product = $this->productFactory->create();
$product->setSku('SKU-001');
$product->setName('Product Name');
$product->setPrice(19.99);
$product->setCustomAttribute('manufacturer', 'Acme Corp');
$product->setCustomAttribute('color', 'Blue');
$product->save();
// Loading with specific attributes
$product = $this->productRepository->get('SKU-001');
echo $product->getPrice(); // 19.99
echo $product->getCustomAttribute('manufacturer')->getValue(); // Acme Corp
?>
CLI Commands
# Setup and maintenance
bin/magento setup:upgrade # Run database schema updates
bin/magento setup:di:compile # Generate compiled DI configuration
bin/magento setup:static-content:deploy # Deploy static assets
bin/magento deploy:mode:set developer # Set developer mode
bin/magento deploy:mode:set production # Set production mode
# Cache
bin/magento cache:clean # Clean specific cache types
bin/magento cache:flush # Flush all cache
bin/magento cache:enable # Enable cache
bin/magento cache:disable # Disable cache
# Index
bin/magento indexer:reindex # Reindex all
bin/magento indexer:info # Show indexers
bin/magento indexer:reset # Reset indexer state
# Admin
bin/magento admin:user:create # Create admin user
bin/magento admin:user:unlock # Unlock admin account
# Maintenance
bin/magento maintenance:enable # Enable maintenance mode
bin/magento maintenance:disable # Disable maintenance modeCheckout Customization
Magento’s checkout is divided into steps handled by Knockout.js on the frontend and PHP services on the backend. Common customization points:
<!-- etc/frontend/di.xml — Override checkout service -->
<config>
<preference for="Magento\Checkout\Model\ShippingInformationManagement"
type="Vendor\Module\Model\ShippingInformationManagement"/>
</config>Common Checkout Plugins
| Plugin Target | Purpose |
|---|---|
Magento\Checkout\Model\ShippingInformationManagement | Modify shipping data before save |
Magento\Quote\Model\Quote | Modify quote totals |
Magento\Payment\Model\Method\AbstractMethod | Custom payment validation |
Magento\Sales\Model\Order | Modify order after placement |
Common Commands Quick Reference
# Daily operations
bin/magento cache:clean config layout block_html # Targeted cache clean
bin/magento indexer:reindex catalog_product_price # Reindex specific indexer
bin/magento cron:run # Run scheduled tasks
bin/magento info:adminuri # Show admin URL
bin/magento config:show web/unsecure/base_url # Show config value
bin/magento config:set web/secure/base_url https://example.com # Set config valueArchitecture Notes
- Built on Zend Framework / Laminas
- Uses Composer for dependency management
- All core functionality is overridable via plugins (never modify core)
- Database supports split read/write connections
- Full-page caching with Varnish supported natively
Common Mistakes
- Assuming all features work identically — always check browser/version compatibility.
- Skipping documentation — reference docs exist for a reason; consult them.
- Not testing edge cases — your setup may differ from tutorials.
- Overlooking security — always validate inputs and follow best practices.
- Copy-pasting without understanding — type code yourself to build real knowledge.
What’s Next
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro