Magento 2 provides a set of CLI (Command Line Interface) commands that you can use to perform various tasks, such as managing the application, installing modules, running tests, and more. Here is a list of commonly used Magento 2 CLI commands along with a brief description of their purpose:
General Commands:
bin/magento setup:upgrade: Upgrades the Magento application, and applies database schema and data changes.
bin/magento setup:di:compile: Generates the DI (Dependency Injection) configuration files for faster performance.
bin/magento setup:static-content:deploy: Deploys static view files for the frontend and adminhtml areas.
bin/magento cache:flush: Flushes the cache storage, clearing all cached data.
bin/magento indexer:reindex: Rebuilds the index for catalog, search, and other indexed data.
bin/magento maintenance:enable: Enables maintenance mode, displaying a maintenance page to visitors.
bin/magento maintenance:disable: Disables maintenance mode.
Module-Related Commands:
bin/magento module:status: Lists the status of modules: enabled, disabled, or not found.
bin/magento module:enable: Enables a module.
bin/magento module:disable: Disables a module.
bin/magento module:uninstall: Uninstalls a module.
bin/magento module:config:status: Lists the configuration status of modules.
Database Commands:
bin/magento setup:backup: Creates a backup of the Magento application’s database and media files.
bin/magento setup:rollback: Rolls back the Magento application to a previous backup.
bin/magento setup:db-schema:upgrade: Upgrades the database schema.
bin/magento setup:db-data:upgrade: Upgrades the data in the database.
bin/magento setup:db:status: Checks if database schema or data requires upgrades.
Code Generation and Maintenance Commands:
bin/magento generate:module: Generates a new module.
bin/magento generate:controller: Generates a new controller in a module.
bin/magento generate:observer: Generates a new event observer in a module.
bin/magento dev:tests:run: Runs tests for a module or the entire Magento application.
These are just a few examples of the many CLI commands available in Magento 2.
You can explore more commands and their options by running bin/magento list or bin/magento –help.
Additionally, extensions and custom modules may provide their own CLI commands to perform specific tasks related to their functionality.
app/code/VendorName/ModuleName/
├── Block/
├── Controller/
├── etc/
│ ├── module.xml
│ ├── di.xml
│ ├── routes.xml
│ └── …
├── Helper/
├── Model/
├── Setup/
│ ├── InstallSchema.php
│ ├── UpgradeSchema.php
│ ├── InstallData.php
│ ├── UpgradeData.php
│ └── …
├── Ui/
│ └── component/
├── view/
│ ├── adminhtml/
│ │ ├── layout/
│ │ ├── templates/
│ │ └── …
│ └── frontend/
│ ├── layout/
│ ├── templates/
│ └── …
├── i18n/
├── Plugin/
├── Console/
├── Test/
│ ├── Unit/
│ └── Integration/
└── …
Let’s go through each directory and briefly describe its purpose:
Block: Contains PHP classes responsible for providing data and logic to the templates.
Controller: Contains PHP classes that handle user requests, process data, and generate responses.
etc: Contains module configuration files, including module.xml (module metadata), di.xml (Dependency Injection configuration), routes.xml (routing configuration), and other XML files for various purposes.
Helper: Contains PHP utility classes that provide reusable functions and methods.
Model: Contains PHP classes responsible for data storage, retrieval, and manipulation.
Setup: Contains files for module installation, upgrade scripts, and data fixtures.
Ui: Contains XML files that define user interface components for grids, forms, and list views.
view: Contains template and layout files for the frontend (frontend/) and adminhtml (adminhtml/) areas.
i18n: Contains translation files for internationalization.
Plugin: Contains PHP classes that modify or extend Magento’s core behavior using the Interception Plugin system.
Console: Contains PHP classes for creating custom command-line interface (CLI) commands.
Test: Contains unit tests (Unit/) and integration tests (Integration/) for the module.
Other directories: Depending on the module’s requirements, additional directories may be present, such as Observer/ for event observers, Api/ for custom web APIs, or Cron/ for cron job-related files.
The actual contents and structure may vary based on the specific needs of your module. However, following this general directory structure will help maintain consistency and make it easier to manage and understand the module’s components.
Magento 2 follows several design patterns to achieve modularity, extensibility, and maintainability. Here are some of the key design patterns used in Magento 2:
Model-View-Controller (MVC) Pattern:
As mentioned earlier, Magento 2 follows the MVC pattern to separate the concerns of data (Model), presentation (View), and application logic (Controller). This pattern helps to organize the codebase and make it more manageable.
Factory Pattern:
The Factory pattern is widely used in Magento 2 for object creation. It involves using factory classes to instantiate and configure objects, allowing for flexibility and encapsulation of object creation logic. Factories are commonly used to create models, blocks, and other Magento components.
Singleton Pattern:
The Singleton pattern ensures that only one instance of a class can exist throughout the application. In Magento 2, the Singleton pattern is often used for resource-intensive or globally accessible objects, such as database connection or configuration objects.
Observer Pattern:
The Observer pattern is employed extensively in Magento 2 for event-driven architecture. Observers listen to specific events triggered during the application’s execution and respond accordingly. This pattern allows for loosely coupled modules and enables extensibility without modifying the core code.
Dependency Injection (DI) Pattern:
Magento 2 heavily relies on the Dependency Injection pattern to manage object dependencies and promote loose coupling. DI allows classes to define their dependencies through constructor arguments or setter methods, making it easier to test and replace dependencies. Magento’s DI framework handles the instantiation and injection of dependencies.
Repository Pattern:
The Repository pattern is used in Magento 2 to abstract data access and manipulation operations. Repositories provide a uniform interface for interacting with persistent storage, such as databases, and encapsulate the underlying data access logic. This pattern helps to centralize data operations and improve code maintainability.
Strategy Pattern:
The Strategy pattern is utilized in Magento 2 for flexible and interchangeable algorithms. By employing this pattern, different implementations of an algorithm can be encapsulated as strategies and switched dynamically at runtime. Magento 2 uses the Strategy pattern in various contexts, such as pricing calculations or payment gateways.
Composite Pattern:
The Composite pattern is utilized in Magento 2’s block and layout system. Blocks can act as composite elements by containing child blocks within them. This pattern allows for the creation of complex nested structures while treating individual blocks and block hierarchies uniformly.
Decorator Pattern:
The Decorator pattern is employed in Magento 2 for extending or modifying the behavior of an object dynamically. Decorators wrap an object and provide additional functionality without changing its core implementation. Magento 2 utilizes decorators in various areas, such as caching, logging, and customizations through plugins.
Proxy Pattern:
The Proxy pattern is used in Magento 2 to control access to an object by creating a surrogate. Proxies can be used to add additional logic or perform actions before or after accessing the underlying object. Proxies are commonly used for lazy loading, caching, or security checks.
Iterator Pattern:
The Iterator pattern is employed in Magento 2 for traversing and accessing collections of objects in a standardized way. Iterators provide a consistent interface for iterating over data structures, such as arrays or database result sets. This pattern is used in various places within Magento, including collection objects and search results.
Template Method Pattern:
The Template Method pattern is used in Magento 2 to define a skeleton of an algorithm in a base class and allow subclasses to override specific steps. This pattern promotes code reuse and provides a consistent structure for executing common tasks with customizable behavior. Magento 2 utilizes the Template Method pattern in areas like email templates and block rendering.
Chain of Responsibility Pattern:
The Chain of Responsibility pattern is employed in Magento 2 to handle requests or events through a chain of processing objects. Each object in the chain has the opportunity to process the request or pass it along to the next object. This pattern enables loose coupling and flexibility in handling different types of requests or events.
Adapter Pattern:
The Adapter pattern is employed in Magento 2 to convert the interface of one class into another interface that clients expect. Adapters are used to bridge the gap between different interfaces and enable incompatible components to work together. This pattern is commonly used when integrating with external systems or services.
Proxy Pattern:
The Proxy pattern is used in Magento 2 to control access to an object by creating a surrogate. Proxies can add additional logic or perform actions before or after accessing the underlying object. Proxies are often used for lazy loading, caching, or security checks.
Service Locator Pattern:
The Service Locator pattern is utilized in Magento 2 for centralizing the retrieval of services or dependencies. The Service Locator acts as a registry that stores and provides access to various services throughout the application. This pattern promotes loose coupling by allowing components to request services without being directly aware of their implementations.
Value Object Pattern:
The Value Object pattern is used in Magento 2 to represent immutable objects that contain a set of values. Value objects are used to encapsulate and manipulate related data as a single unit. They are typically used for attributes, options, or configurations that do not change once created.
Command Pattern:
The Command pattern is employed in Magento 2 to encapsulate requests as objects, allowing for parameterization, queuing, and logging of operations. Commands decouple the sender of a request from the receiver, providing a flexible way to handle and manage operations. Magento 2 uses the Command pattern in areas such as cron jobs and message queues.
Magento 2 follows the Model-View-Controller (MVC) architectural pattern to organize and manage the codebase. The MVC pattern helps to separate the concerns of data, presentation, and application logic, making the codebase more modular and maintainable. Here’s how Magento 2 implements the MVC pattern:
Model:
The Model represents the data and business logic of the application. In Magento 2, models are responsible for data manipulation, storage, and retrieval. They interact with the database or external systems to fetch or update data. Models are typically located in the Model directory and follow the naming convention of \\Model.
View:
The View handles the presentation layer and is responsible for rendering the user interface. In Magento 2, views are implemented using a combination of templates, layouts, and blocks. Templates are responsible for displaying the actual HTML content, layouts define the structure of the page, and blocks provide the logic and data to the templates. View-related files are typically located in the view directory and follow the naming convention of _.
Controller:
The Controller receives requests from the user and coordinates the interaction between the Model and the View. In Magento 2, controllers are responsible for processing user actions, retrieving data from models, and returning appropriate responses. Controllers are typically located in the Controller directory and follow the naming convention of \\Controller.
The interaction between the Model, View, and Controller in Magento 2 follows a flow:
The user makes a request to a specific URL in the browser.
Magento’s routing mechanism maps the requested URL to a specific controller action.
The controller action is executed, where it can fetch or modify data using the relevant models.
The controller action prepares the necessary data and passes it to the appropriate view.
The view is rendered, combining the layout structure, block logic, and template content.
The rendered output is sent back as a response to the user’s request.
Blocks:
Blocks are an integral part of the View layer in Magento 2. They provide the logic and data required by the templates to render the final HTML output. Blocks are PHP classes that encapsulate specific functionality and are responsible for fetching and processing data. They can also contain business logic related to the presentation layer.
Blocks are instantiated and managed by the layout system. The layout XML files define the structure of a page or a section of a page and specify which blocks to include. Blocks can be placed within the layout XML files using various layout instructions, such as block, referenceBlock, or container.
Blocks can communicate with models to retrieve data or perform data manipulation. They can also interact with other blocks to share data or coordinate actions.
Helpers:
Helpers in Magento 2 are utility classes that provide reusable functions and methods. They are not directly tied to any specific layer of the MVC pattern but are commonly used within the Model, View, and Controller components.
Helpers encapsulate common functionality that can be used across different parts of the application. For example, a helper class might contain methods for data formatting, string manipulation, URL generation, or other general-purpose tasks. Helpers promote code reusability and reduce code duplication.
To use a helper in Magento 2, you typically call the helper class and the desired method statically, like HelperClass::methodName(). Magento provides a helper class called Magento\Framework\App\Helper\AbstractHelper, which you can extend to create custom helpers for your module.
Helpers can be accessed within various components of Magento 2, including controllers, blocks, templates, and other helpers, providing a convenient way to share common functionality and promote modular code design.
In summary, Blocks are responsible for providing data and logic to the templates for rendering, while Helpers are utility classes that offer reusable functions and methods for various parts of the application. Together with the Model, View, and Controller, Blocks and Helpers contribute to the modular and maintainable nature of Magento 2’s MVC architecture.
Overall, Magento 2’s implementation of the MVC pattern provides a structured way to separate concerns and handle different aspects of the application. This separation allows for better code organization, reusability, and maintainability.
Magento uses several database patterns to manage its data. Here are some of the key patterns used in the Magento database architecture:
Entity-Attribute-Value (EAV):
Magento extensively uses the EAV pattern to provide a flexible and extensible data model. This pattern allows for storing a wide range of attributes for entities (such as products, categories, and customers) in a single table, reducing the need for creating separate tables for each attribute. The EAV pattern provides flexibility for adding new attributes without altering the database schema.
Flat Catalog:
Magento includes the option to use a flat catalog for improved performance. In the flat catalog, product data is denormalized and stored in separate flat tables instead of the EAV structure. This allows for faster querying and improves the performance of product listing pages.
Indexing:
Magento employs indexing to optimize database queries and improve performance. Indexes are created on frequently queried columns to speed up search, filtering, and sorting operations. Magento supports multiple types of indexes, including flat indexes, full-text indexes, and price indexes.
Sharding and Horizontal Partitioning:
In high-scale environments, Magento can utilize sharding or horizontal partitioning techniques to distribute the database across multiple servers. Sharding involves dividing the data into logical partitions based on a specific criterion (e.g., customer ID or website ID) and storing each partition on a separate database server. This helps to scale the database horizontally and handle increased traffic and data volume.
Database Replication:
Magento supports database replication to improve performance and provide fault tolerance. Replication involves creating multiple copies of the database on different servers, where one server acts as the master for write operations, and the other servers act as replicas for read operations. This allows for load balancing and increases the availability and reliability of the system.
Caching:
Magento utilizes various caching mechanisms, such as Redis, Memcached, and Varnish, to reduce the load on the database and improve performance. Caching stores frequently accessed data in memory, reducing the need to query the database for every request.
These are some of the primary database patterns and techniques used in the Magento architecture. They help optimize performance, scalability, and flexibility in managing the vast amount of data associated with e-commerce websites.
Create Theme Directory: Inside your Magento installation, navigate to the app/design/frontend
directory. Create a directory for your theme. For example, VendorName/theme
.
Create Theme Configuration: Inside your theme directory, create a theme.xml
file. This file defines the theme configuration. Here’s an example of a theme.xml
file:
HTML
Modify the <title>
element with your theme’s title and update the <parent>
element to specify the parent theme. In this example, we are using the Magento/blank
theme as the parent.
- Create Theme Directories: Inside your theme directory, create the following directories:
web/css
: For custom CSS files.web/js
: For custom JavaScript files.web/images
: For custom images.Magento_Theme/layout
: For layout XML files.Magento_Theme/templates
: For template files
Create Stylesheets and JavaScript Files: Inside the web/css directory, create your custom CSS files (e.g., styles.css). Inside the web/js directory, create your custom JavaScript files (e.g., script.js).
Create Layout XML Files:
Inside the Magento_Theme/layout directory, create XML files to modify the layout of different pages. For example, you can create default.xml to modify the layout of all pages, catalog_category_view.xml to modify the category page layout, etc.
Create Template Files:
Inside the Magento_Theme/templates directory, create template files (e.g., header.phtml, footer.phtml, etc.) to override or customize the existing templates.
Configure Theme:
To configure your theme, create or modify the etc/view.xml file in your theme directory. This file allows you to configure various image-related settings, such as image resizing, quality, and product image dimensions.
Set Your Theme as Active:
In your Magento admin panel, go to Content -> Configuration. Select the store view for which you want to set your custom theme. In the Applied Theme column, select your custom theme and save the configuration.
Deploy Static Content:
Run the following command in your Magento installation root directory to deploy the static content:
HTML
Clear Cache:
Clear the Magento cache to ensure your changes take effect:php bin/magento cache:flush
To create a custom extension in Magento 2, follow these steps:
Set up the Extension Structure: In the root directory of your Magento installation, navigate to app/code
. Create a directory structure for your extension as follows:
HTML
Create the registration.php File: Inside the ModuleName
directory, create a registration.php
file with the following content:php
HTML
Create the module.xml File: Inside the ModuleName
directory, create a etc
directory. Inside the etc
directory, create a module.xml
file with the following content:xml
HTML
Create the etc/di.xml File: Inside the ModuleName/etc
directory, create a di.xml
file. This file will define the dependency injection configuration for your extension.
Create a Controller: Inside the ModuleName
directory, create a Controller
directory. Inside the Controller
directory, create another directory called Index
. Inside the Index
directory, create a PHP file with the following content:
HTML
Create a routes.xml File: Inside the ModuleName/etc
directory, create a frontend
directory. Inside the frontend
directory, create a routes.xml
file with the following content:
HTML
Run Setup Upgrade: Open a command-line interface, navigate to your Magento installation root directory, and run the following command:
HTML
Verify the Extension: Open a web browser and access your Magento store. You should be able to access the URL path defined in the controller. For example, if you defined the frontName as “route” in routes.xml
and the controller name as “index” in step 5, you can access the URL at /route/index/index
.
Create a Block: Inside the ModuleName
directory, create a Block
directory. Inside the Block
directory, create a PHP file with the following content:
HTML
Create a Layout XML File: Inside the ModuleName
directory, create a view/frontend/layout
directory. Inside the layout
directory, create an XML file (e.g., custom_layout.xml
) with the following content:
Create a Template File: Inside the ModuleName
directory, create a view/frontend/templates
directory. Inside the templates
directory, create a .phtml
file (e.g., custom_template.phtml
) and implement the desired HTML markup and PHP logic for your custom block.
Create a Controller to Handle Form Submission: Inside the ModuleName/Controller/Index
directory, create another PHP file (e.g., Save.php
) to handle the form submission and perform the desired actions. Implement the necessary logic inside the execute()
method.
Update routes.xml
to Include the New Controller: Modify the existing routes.xml
file to include the new controller by adding another route entry:
HTML
Run Setup Upgrade: Again, run the following command to apply the changes:
HTML
Clear Cache: Clear the Magento cache to ensure that your changes take effect:
HTML
The Magento Admin is the central hub where you can manage all aspects of your Magento store. From products and inventory to customers and orders, the Admin gives you the power to control every aspect of your business.
The Admin is divided into two main sections: the Navigation pane and the Content pane. The Navigation pane provides a tree-like view of all the available sections in the Admin. The Content pane displays the current section and its contents.
The Admin is a powerful tool, but it can be a bit daunting at first. Here are a few tips to help you get started:
- Take your time. Don’t try to learn everything about the Admin all at once. Start by exploring the different sections and familiarize yourself with the basic features.
- Use the help. The Admin includes a comprehensive help system that can answer any questions you have. You can access the help system by clicking the Help button in the top-right corner of any page.
- Get help from the community. There is a large and active Magento community that can provide help and support. You can find help in online forums, chat rooms, and other resources.
Here is a brief overview of some of the key features of the Magento Admin:
- Products: The Products section allows you to create, manage, and edit your products. You can also set up product attributes, prices, and inventory levels.
- Customers: The Customers section allows you to manage your customers. You can view customer orders, track customer activity, and send customer emails.
- Orders: The Orders section allows you to manage your orders. You can view order details, track order status, and generate shipping labels.
- Reports: The Reports section allows you to generate reports on your store’s sales, customers, and products.
- Configuration: The Configuration section allows you to configure your store’s settings. You can set up payment methods, shipping methods, and other store-wide settings.
The Magento Admin is a powerful tool that can help you manage your Magento store effectively. With a little time and effort, you can learn how to use the Admin to its full potential.
Here’s an overview in detail of the admin panel in Magento and Adobe Commerce (formerly Magento Commerce):
- Dashboard: The dashboard provides an overview of your store’s key metrics, including sales, orders, and customer information. It gives you a quick snapshot of your store’s performance and allows you to track important data at a glance.
- Catalog Management: In the catalog section, you can manage your products, categories, and attributes. You can add new products, edit existing ones, assign them to categories, set prices, manage inventory, and define custom attributes for your products.
- Sales Management: The sales section allows you to manage orders, invoices, shipments, and credit memos. You can view and process orders, generate invoices for customers, create shipments, and issue credit memos as necessary.
- Customer Management: This section lets you manage customer accounts, view customer details, and handle customer service tasks. You can add new customers, edit existing accounts, view order history, manage customer groups, and communicate with customers through the built-in messaging system.
- Marketing and Promotions: In this section, you can create and manage marketing campaigns, promotions, and discounts. You can set up catalog price rules, and shopping cart price rules, create newsletters, manage customer reviews, and configure SEO settings.
- Content Management: The content section allows you to manage the content of your store, including static pages, blocks, and widgets. You can create custom pages, edit existing content, manage navigation menus, and control the layout of your store.
- Reports and Analytics: Magento provides various reporting tools to help you analyze your store’s performance. You can generate reports on sales, customers, products, and shopping cart activities. These reports provide valuable insights to make data-driven decisions and optimize your store’s performance.
- Store Configuration: This section is where you can configure various settings for your store. You can manage store information, set up payment methods, shipping methods, tax settings, email templates, and currency options, and configure other general settings.
- Extensions and Marketplace: Magento has a vast ecosystem of extensions and themes that can enhance the functionality and appearance of your store. In the admin panel, you can manage installed extensions, install new ones, and browse the Magento Marketplace to discover additional extensions and themes.
This is a high-level overview of the admin panel in Magento and Adobe Commerce. The interface may vary slightly based on the version and specific customizations made to your installation. The admin panel provides a comprehensive set of tools to manage and configure your e-commerce store effectively.
Overview:
To start with Magento or Adobe Commerce (formerly known as Magento Commerce), you’ll need to follow these steps for the installation process:
- System Requirements: Before you begin, ensure that your system meets the minimum requirements for Magento. Check the official Magento documentation or Adobe Commerce documentation for the specific requirements based on the version you are installing.
- Download the Installation Package: Visit the official Magento website or Adobe Commerce website and download the installation package that matches your desired version. Make sure to choose the appropriate version based on your requirements, whether it’s the open-source edition or the commerce edition.
- Set Up the Web Server: Magento requires a web server like Apache or Nginx. Install and configure the web server based on the instructions provided in the official documentation. Ensure that the server meets all the prerequisites mentioned.
- Set Up a Database: Magento utilizes a database to store its data. Set up a database server such as MySQL or MariaDB, and create a new database for your Magento installation. Take note of the database credentials (database name, username, and password) as you’ll need them during the installation process.
- Extract the Magento Files: Once you have downloaded the Magento installation package, extract the contents to the root directory of your web server. This location will typically be your web server’s public HTML folder.
- Configure Magento: Open a web browser and navigate to your Magento installation by accessing the URL where you placed the files. You will be presented with the Magento installation wizard. Follow the instructions to configure your installation. During this process, you’ll need to provide your database credentials, set up an admin account, and customize additional settings as required.
- Complete the Installation: After completing the configuration, the Magento installation will begin. Wait for the installation process to finish. This may take a few minutes. Once the installation is complete, you will be redirected to the admin login page.
- Log in to the Admin Panel: Access the Magento admin panel by navigating to the appropriate URL and using the admin credentials you set during the installation. From here, you can start customizing your store, managing products, and configuring various settings.
Remember to refer to the official Magento or Adobe Commerce documentation for more detailed installation instructions, troubleshooting steps, and best practices.
Detail
Magento and Adobe Commerce are both powerful e-commerce platforms that can be used to create a successful online store. However, there are some key differences between the two platforms that you should be aware of before you decide which one is right for you.
Magento is an open-source platform that is free to download and use. However, it can be more complex to install and configure than Adobe Commerce. Magento also has a larger community of developers and extensions, which can be a benefit if you need help with customization or troubleshooting.
Adobe Commerce is a cloud-based platform that is hosted and managed by Adobe. This makes it easier to get started with Adobe Commerce, as you don’t need to worry about setting up or maintaining your own server. Adobe Commerce also offers a wider range of features and integrations than Magento, which can be a benefit for larger businesses.
Here are the steps on how to install Magento:
- Set up your server. Magento has a number of system requirements that your server must meet in order to run the platform. You can find a list of these requirements on the Magento website.
- Install Composer. Composer is a dependency manager that is used to install Magento. You can download Composer from the Composer website.
- Download Magento. Once you have installed Composer, you can download Magento using the following command:
Code snippet
composer create-project --repository=https://repo.magento.com magento/project-dir-name
- Create a database. Magento requires a database to store its data. You can create a database using your favorite database management system.
- Configure Magento. Once you have created a database, you need to configure Magento. You can do this by following the instructions in the Magento documentation.
Here are the steps on how to install Adobe Commerce:
- Sign up for an Adobe Commerce account. You can sign up for an Adobe Commerce account on the Adobe website.
- Choose a plan. Adobe Commerce offers a variety of plans to choose from, depending on your needs.
- Deploy your store. Once you have chosen a plan, you can deploy your store. Adobe Commerce offers a variety of deployment options, including on-premises, cloud, and hybrid.
- Configure your store. Once your store is deployed, you need to configure it. You can do this by following the instructions in the Adobe Commerce documentation.
Which platform should you choose?
The best platform for you will depend on your specific needs and requirements. If you are looking for a powerful and flexible platform that offers a wide range of features and integrations, then Adobe Commerce is a good choice. However, if you are looking for a more affordable option that is easy to set up and manage, then Magento may be a better choice.
Here is a table that summarizes the key differences between Magento and Adobe Commerce:
Feature | Magento | Adobe Commerce |
---|---|---|
Cost | Free | Paid |
Hosting | Self-hosted or hosted by a third party | Hosted by Adobe (On-premise can be self-hosted) |
Features | More limited | More comprehensive |
Integrations | The smaller community of developers and extensions | The larger community of developers and extensions |
Ease of use | More complex to install and configure | Easier to install and configure |
Magento 2 has three deployment modes: default, developer, and production. Each mode has its own set of features and benefits, and the best mode for you will depend on your specific needs.
- Default mode is the most basic mode and is designed for development and testing. In default mode, Magento compiles code and generates static view files on demand, which can improve performance. However, the default mode also exposes errors and warnings to users, which can make it unsuitable for production environments.
- Developer mode is designed for developers who need to make changes to Magento’s code or configuration. In developer mode, Magento does not compile code or generate static view files, which makes it easy for developers to make changes and see the results immediately. However, developer mode also exposes errors and warnings to users, which can make it unsuitable for production environments.
- Production mode is designed for live websites. In production mode, Magento compiles code and generates static view files during deployment, which improves performance. Magento also hides errors and warnings from users, which improves the user experience.
Here is a table that summarizes the key differences between the three modes:
Mode | Features | Benefits | Drawbacks |
---|---|---|---|
Default | Compiles code and generates static view files on demand | Improves performance | Errors and warnings are exposed to users |
Developer | Does not compile code or generate static view files | Easy for developers to make changes and see the results immediately | Errors and warnings are exposed to users |
Production | Compiles code and generates static view files during deployment | Improves performance | Errors and warnings are hidden from users |
In general, you should use the default mode for development and testing, the developer mode for making changes to Magento’s code or configuration, and the production mode for live websites.
Here are some additional things to keep in mind when choosing a deployment mode:
- Performance: The default mode has the best performance, followed by the production mode, and then the developer mode.
- Security: The production mode is the most secure mode, followed by the default mode, and then the developer mode.
- Usability: The production mode is the most user-friendly mode, followed by the default mode, and then the developer mode.
Ultimately, the best way to choose a deployment mode is to consider your specific needs and requirements.
- Magento Blog – The official blog of Magento, which features news, updates, and articles about the platform.
- MagePlaza – A blog that provides tutorials, tips, and insights on Magento and e-commerce.
- Inchoo – A blog that covers topics such as Magento development, design, and marketing.
- AheadWorks – A blog that provides Magento news, insights, and tips on marketing, design, and development.
- Sherrie Rohde – A blog that covers topics such as Magento community, events, and news.
- Firebear Studio – A blog that covers Magento, e-commerce, and integration topics.
- MagePsycho – A blog that provides Magento tutorials, tips, and extensions.
- Atwix – A blog that covers Magento development, design, and optimization topics.
- These are just a few examples of the many Magento blogs and websites available online.
- Classy Llama – A blog that covers a range of topics related to Magento, including development, marketing, and design.
- Magento Stack Exchange – A Q&A site for Magento developers and enthusiasts where you can find answers to common questions and ask for help.
- Creatuity – A blog that covers Magento development, marketing, and optimization.
- AionHill – A blog that provides Magento news, tips, and insights on marketing and design.
- DCKAP – A blog that covers topics such as Magento development, optimization, and integrations.
- Exinent – A blog that provides Magento tutorials, tips, and insights on development, optimization, and design.
- MageWorx – A blog that covers Magento topics such as extensions, customization, and optimization.
- Inviqa – A blog that covers Magento and e-commerce topics such as strategy, design, and development.
- Magefan – A blog that provides Magento tips, tutorials, and extensions.
- Wagento – A blog that covers Magento news, events, and development topics.
- Magento Tutorial – A blog that provides tutorials, guides, and tips on Magento development and customization.
- Alan Storm – A blog that provides in-depth tutorials and insights on Magento development.
- SwiftOtter Solutions – A blog that covers Magento topics such as development, optimization, and design.
- Meanbee – A blog that covers Magento development, optimization, and design topics.
- Integer_net – A blog that provides Magento tutorials, tips, and insights on development and customization.
- Forix – A blog that covers Magento development, optimization, and design topics.
- Magento Forum – A community-driven forum for Magento developers and enthusiasts to discuss and troubleshoot issues related to the platform.
- Magenticians – A blog that provides Magento tutorials, tips, and insights on development, marketing, and design.
- TechDivine – A blog that covers Magento topics such as development, optimization, and design.
- Atlassian Blog – A blog that covers topics related to Magento, including development and project management.
- CedCommerce – A blog that provides Magento tutorials, tips, and insights on development, optimization, and design.
- Codilar – A blog that covers Magento development, optimization, and design topics.
- Magenticians – A blog that provides Magento tutorials, tips, and insights on development, marketing, and design.
- Magentodevelopers – A blog that covers topics related to Magento, including development, optimization, and design.
- Magentool – A blog that provides Magento tutorials, tips, and insights on development, optimization, and design.
- Meetanshi – A blog that covers Magento development, optimization, and design topics.
- Onilab – A blog that covers Magento topics such as development, optimization, and design.
- Padoosoft – A blog that provides Magento tutorials, tips, and insights on development and customization.
- Silk Software – A blog that covers Magento topics such as development, optimization, and design.
- Sunflowerbiz – A blog that provides Magento tutorials, tips, and insights on development and customization.
- Techies India – A blog that covers Magento development, optimization, and design topics.
- The Pixel – A blog that provides Magento tutorials, tips, and insights on development and customization.
- Ubertheme – A blog that covers Magento development, optimization, and design topics.
- Web Solutions NYC – A blog that provides Magento tutorials, tips, and insights on development, optimization, and design.
- Webspeaks – A blog that covers Magento topics such as development, optimization, and design.
- Xumulus – A blog that provides Magento tutorials, tips, and insights on development, optimization, and design.
- Yireo – A blog that covers Magento development, optimization, and design topics.
- Aionhill – A blog that provides Magento tutorials, tips, and insights on development and optimization.
- Atwix – A blog that covers Magento development, optimization, and design topics.
- BelVG – A blog that provides Magento tutorials, tips, and insights on development and customization.
- Bitnami Magento Stack – A blog that covers topics related to Magento installation, configuration, and management.
- Classy Llama – A blog that provides Magento tutorials, tips, and insights on development, optimization, and design.
- Codisto – A blog that covers Magento topics such as e-commerce, development, and integration.
- CreativeMinds – A blog that provides Magento tutorials, tips, and insights on development, optimization, and design.
MailHog is an email testing tool for developers, Configuration and use are very easy, It will provide the UI to read the emails.
It will not send any email to anyone, it just keeps your all email local and you can easily read them.
Here are the steps to setup the MailHog in Ubuntu and WSL (Windows Linux)
$ sudo apt-get update
Get your current username
$ echo "$USER"
Saphal
$ sudo apt-get install golang-go
$ go get github.com/mailhog/MailHog
copy MailHog to the /usr/local/bin
$ sudo cp /home/USER/go/bin/MailHog /usr/local/bin/mailhog
NOTE: USER is your Linux username
$ go get github.com/mailhog/mhsendmail
copy mhsendmail to the /usr/local/bin path,
$ sudo cp /home/USER/go/bin/mhsendmail /usr/local/bin/mhsendmail
NOTE: USER is your Linux username
After this installation, You need to configure the email service to your PHP, Follow the below steps:
$ sudo nano /etc/php/8.1/apache2/php.ini
NOTE: 8.1 is my PHP version you can choose yours
Find sendmail_path in your php.ini
remove semicolon (;) from starting of the line
From
;sendmail_path = /usr/local/bin/mhsendmail
To
;sendmail_path = /usr/local/bin/mhsendmail
Now you are done with all setup, now go to CLI and run the below command
$ mailhog
After running the above command you will get the below output:
~$ mailhog
2023/01/30 11:43:45 Using in-memory storage
2023/01/30 11:43:45 [SMTP] Binding to address: 0.0.0.0:1025
[HTTP] Binding to address: 0.0.0.0:8025
2023/01/30 11:43:45 Serving under http://0.0.0.0:8025/
Creating API v1 with WebPath:
Creating API v2 with WebPath:
[APIv1] KEEPALIVE /api/v1/events
[APIv2] GET /api/v2/jim
[APIv2] GET /api/v2/messages
[APIv2] GET /api/v2/websocket
[APIv2] GET /api/v2/messages
[APIv1] KEEPALIVE /api/v1/events
NOTE: FOR WSL users if the URL (http://0.0.0.0:8025/) is not working try with the local host
localhost:8025
Please comment if any query
Source – https://github.com/mailhog/MailHog
In Magento 2, design patterns are reusable solutions to common software design problems. They provide a structured approach to solving specific challenges and help in creating scalable, maintainable, and flexible code. Magento 2 leverages several design patterns to achieve its architecture and functionality. Here are some design patterns commonly used in Magento 2:
Singleton Pattern: The Singleton pattern ensures that only one instance of a class is created and provides a global point of access to that instance. In Magento 2, singleton classes are often used for managing shared resources, such as database connections or configuration data.
Factory Pattern: The Factory pattern provides an interface for creating objects without specifying their concrete classes. It encapsulates the object creation logic, allowing flexibility in creating different types of objects based on specific conditions or configurations. In Magento 2, factory classes are used to instantiate and configure various components, such as models, blocks, and controllers.
Observer Pattern: The Observer pattern establishes a one-to-many relationship between objects, where multiple observers (listeners) are notified and updated when a particular event occurs. Magento 2 extensively uses the Observer pattern to implement its event-driven architecture. Developers can create custom events and attach observers to perform specific actions based on those events.
Proxy Pattern: The Proxy pattern provides a placeholder for an object, allowing control over its creation and providing additional functionality. Proxies can be used to manage expensive or resource-intensive operations, lazy loading, or caching. In Magento 2, proxies are used to instantiate and manage heavy objects, such as large collections or database connections, only when needed.
Decorator Pattern: The Decorator pattern allows behavior to be added to an object dynamically without affecting its underlying structure. Decorators wrap an object and provide additional functionality or modify existing behavior. In Magento 2, decorators are used to extend the functionality of classes, such as blocks, models, or helpers, by adding new methods or modifying existing ones.
Dependency Injection (DI) Pattern: Dependency Injection is a design pattern that facilitates loose coupling and promotes modular and testable code. It involves injecting dependencies into an object rather than having the object create or manage its dependencies. Magento 2 embraces the DI pattern extensively, allowing developers to configure dependencies through XML files and constructor or method injection.
Service Locator Pattern: The Service Locator pattern provides a centralized service registry that clients can use to locate and obtain instances of services or objects. It helps decouple the client from the specific implementation and allows for flexibility in service resolution. Magento 2 utilizes the Service Locator pattern through the Object Manager, allowing components to request and retrieve instances of services and resources.
Object Creation: The Object Manager is used to create instances of classes. Instead of directly using the new operator, developers can request objects from the Object Manager, which takes care of instantiating the appropriate class and resolving any dependencies.
Object Retrieval: The Object Manager provides a convenient way to retrieve objects from various parts of the system. It allows developers to fetch objects by their class name or interface, abstracting away the details of object lookup and instantiation.
Interception and Plugin System: The Object Manager plays a vital role in Magento 2’s interception and plugin system. It enables developers to intercept and modify the behavior of Magento classes by defining plugins. Plugins are classes that can be configured to execute before, after, or around the execution of target methods, allowing for customization and extension of core functionality.
Event-Driven Architecture: Magento relies on an event-driven architecture to provide extensibility and customization. Events and observers are used to hook into specific points in the system’s execution flow. Understanding how events work and how to create custom events and observers will enable you to extend and customize Magento’s functionality effectively.
Namespaces and Autoloading: Namespaces provide a way to organize and group classes, avoiding naming conflicts. Magento uses namespaces extensively to organize its codebase. Learn how to declare and use namespaces, and understand Magento’s autoloading
Composer: Composer is a dependency management tool for PHP that Magento utilizes. It allows you to declare and manage the dependencies of your Magento project efficiently. Learn how to work with Composer to install, update, and manage Magento extensions and dependencies.
Caching and Performance Optimization: Magento places great emphasis on performance optimization. Understanding PHP caching mechanisms, such as opcode caching (e.g., APCu, OPcache), and leveraging Magento’s built-in caching features (e.g., full-page cache, block cache) will help improve the performance of your Magento store.
Testing: Magento provides a testing framework based on PHPUnit. Learning how to write and run tests for your Magento modules and extensions is crucial for ensuring code quality, maintaining stability, and preventing regressions.
Service Locator Pattern: The Service Locator pattern provides a centralized service registry that clients can use to locate and obtain instances of services or objects. It helps decouple the client from the specific implementation and allows for flexibility in service resolution. Magento 2 utilizes the Service Locator pattern through the Object Manager, allowing components to request and retrieve instances of services and resources.
Strategy Pattern: The Strategy pattern allows for the definition of interchangeable algorithms or strategies. It encapsulates different algorithms behind a common interface, allowing clients to switch between strategies dynamically. Magento 2 employs the Strategy pattern in various scenarios, such as pricing calculations, payment methods, and shipping calculations, where different algorithms can be applied based on specific conditions or configurations.
Iterator Pattern: The Iterator pattern provides a way to sequentially access elements of a collection without exposing the underlying structure. It defines a common interface for iterating over a collection, enabling clients to traverse and manipulate elements uniformly. In Magento 2, iterators are used extensively for working with collections, allowing developers to iterate over sets of entities, attributes, and other structured data.
Front Controller Pattern: The Front Controller pattern centralizes the handling of incoming requests and dispatches them to the appropriate controllers or actions. It provides a single entry point to the application, allowing for consistent request handling and processing. In Magento 2, the front controller is responsible for routing and dispatching requests to the appropriate controllers based on the requested URL.
Template Method Pattern: The Template Method pattern defines the skeleton of an algorithm in a base class, allowing subclasses to override certain steps of the algorithm while preserving the overall structure. In Magento 2, this pattern is often used in the implementation of block classes and layout files, where the base class provides the structure for rendering a template, and subclasses can customize specific parts of the rendering process.
Composite Pattern: The Composite pattern treats a group of objects as a single object, allowing clients to work with individual objects or groups of objects uniformly. It creates a tree-like structure, where both individual objects and composite objects share a common interface. In Magento 2, the Composite pattern is used in the implementation of the layout system, where blocks can be composed hierarchically to build complex page structures.
Adapter Pattern: The Adapter pattern allows objects with incompatible interfaces to work together by creating a wrapper or adapter class that bridges the gap between them. It enables objects to collaborate without having to modify their existing interfaces. In Magento 2, the Adapter pattern can be used to integrate external libraries or systems by creating adapters that translate their interfaces into compatible formats.
Proxy Pattern: The Proxy pattern provides a surrogate or placeholder for an object, allowing control over its creation and access. Proxies can be used to add additional functionality, restrict access, or defer expensive operations until they are actually needed. In Magento 2, proxies are often used to implement lazy loading of objects or to provide additional security and validation checks.
Command Pattern: The Command pattern encapsulates a request as an object, allowing clients to parameterize and queue requests, as well as support undoable operations. In Magento 2, this pattern is used in the implementation of the command-line interface (CLI) and the message queue system, where commands are represented as objects and can be executed, queued, or logged for later processing.
Builder Pattern: The Builder pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations. It provides a step-by-step approach to building an object, allowing customization and flexibility in the construction process. In Magento 2, the Builder pattern is used in various contexts, such as building database queries or constructing complex configuration objects.
Flyweight Pattern: The Flyweight pattern is used to minimize memory usage by sharing common data between multiple objects. It aims to reduce the memory footprint by extracting and sharing common state, rather than storing it redundantly in each object. In Magento 2, the Flyweight pattern can be applied to optimize the handling of data structures or configurations that are frequently used.
Flyweight Pattern: The Flyweight pattern is used to minimize memory usage by sharing common data between multiple objects. It aims to reduce the memory footprint by extracting and sharing common state, rather than storing it redundantly in each object. In Magento 2, the Flyweight pattern can be applied to optimize the handling of data structures or configurations that are frequently used.
State Pattern: The State pattern allows an object to alter its behavior when its internal state changes. It encapsulates each state as a separate class and defines methods to transition between states. In Magento 2, the State pattern can be used to manage the behavior and transitions of entities or processes that have different states, such as order processing or customer interactions.
Visitor Pattern: The Visitor pattern separates the operations performed on an object structure from the objects themselves. It allows new operations to be added without modifying the objects’ classes. In Magento 2, the Visitor pattern can be used to define custom operations or actions on objects without modifying their implementation, providing a way to extend the functionality of existing classes.
Chain of Responsibility Pattern: The Chain of Responsibility pattern allows multiple objects to handle a request in a chain-like manner. Each object in the chain has the ability to process the request or pass it to the next object in the chain. In Magento 2, the Chain of Responsibility pattern can be used to implement request processing flows, such as handling events or executing commands, where different objects can participate in the processing chain.
When working with Magento, having a solid understanding of advanced PHP concepts is beneficial for developing and customizing the platform effectively. Here are some key advanced PHP concepts that are relevant to Magento:
Object-Oriented Programming (OOP): Magento is built using an object-oriented architecture, so a strong grasp of OOP principles is essential. Familiarize yourself with concepts such as classes, objects, inheritance, encapsulation, and polymorphism. Understanding how to create and use classes, define methods and properties, and work with objects will greatly help in Magento development.
Design Patterns: Design patterns are proven solutions to recurring design problems. Magento leverages several design patterns, such as Singleton, Factory, Observer, Proxy, and Dependency Injection patterns. Learning about these patterns and how they are applied in Magento will enhance your ability to work with the platform and develop scalable and maintainable code.
Dependency Injection (DI): Magento 2 heavily employs dependency injection as a design principle. DI allows for loose coupling between components, promotes modularity, and simplifies testing. Learn about constructor injection, method injection, and how to configure and use dependency injection in Magento modules.
Event-Driven Architecture: Magento relies on an event-driven architecture to provide extensibility and customization. Events and observers are used to hook into specific points in the system’s execution flow. Understanding how events work and how to create custom events and observers will enable you to extend and customize Magento’s functionality effectively.
Namespaces and Autoloading: Namespaces provide a way to organize and group classes, avoiding naming conflicts. Magento uses namespaces extensively to organize its codebase. Learn how to declare and use namespaces, and understand Magento’s autoloading mechanism, which automatically loads classes based on their namespace and file structure.
Composer: Composer is a dependency management tool for PHP that Magento utilizes. It allows you to declare and manage the dependencies of your Magento project efficiently. Learn how to work with Composer to install, update, and manage Magento extensions and dependencies.
Caching and Performance Optimization: Magento places great emphasis on performance optimization. Understanding PHP caching mechanisms, such as opcode caching (e.g., APCu, OPcache), and leveraging Magento’s built-in caching features (e.g., full-page cache, block cache) will help improve the performance of your Magento store.
Testing: Magento provides a testing framework based on PHPUnit. Learning how to write and run tests for your Magento modules and extensions is crucial for ensuring code quality, maintaining stability, and preventing regressions.
These are just a few advanced PHP concepts that are relevant to Magento development. Exploring these topics and gaining hands-on experience with Magento will enable you to build robust and scalable e-commerce solutions on the platform.
he Object Manager refers to a fundamental component of the Magento framework. It is a dependency injection (DI) container that manages the creation and retrieval of objects throughout the system. The Object Manager is responsible for resolving dependencies between classes and providing instances of requested objects.
While the Object Manager in Magento 2 provides a convenient way to access and instantiate objects, it is worth mentioning that best practices encourage the use of dependency injection via the constructor or method injection instead of directly relying on the Object Manager. This approach improves testability, and maintainability, and adheres to the principles of SOLID design.
The Object Manager in Magento 2 serves several purposes and is used in various scenarios:
Dependency Injection: The Object Manager is the central mechanism for dependency injection in Magento 2. It automatically resolves and injects dependencies into objects, reducing the need for manual instantiation and configuration. This promotes modular and loosely coupled code.
Object Creation: The Object Manager is used to create instances of classes. Instead of directly using the new operator, developers can request objects from the Object Manager, which takes care of instantiating the appropriate class and resolving any dependencies.
Object Retrieval: The Object Manager provides a convenient way to retrieve objects from various parts of the system. It allows developers to fetch objects by their class name or interface, abstracting away the details of object lookup and instantiation.
Singleton Management: Magento 2’s Object Manager also manages singleton instances. By default, it ensures that only one instance of a class is created and shared across the system. This is useful for maintaining a single stateful instance of certain classes, such as database connections or configuration objects.
Interception and Plugin System: The Object Manager plays a vital role in Magento 2’s interception and plugin system. It enables developers to intercept and modify the behavior of Magento classes by defining plugins. Plugins are classes that can be configured to execute before, after, or around the execution of target methods, allowing for customization and extension of core functionality.
Magento is an open-source e-commerce platform written in PHP.
It uses multiple other PHP frameworks such as Laminas (formerly known as Zend Framework) and Symfony.
Magento source code is distributed under Open Software License (OSL) v3.0.
Magento was acquired by Adobe Inc in May 2018 for $1.68 billion.
More than 150,000 [3] online stores have been created on the platform.
Varien published the first general-availability release of the software on March 31, 2008. Roy Rubin, the former CEO of Varien, later sold a share of the company to eBay, which eventually completely acquired and then sold the company to Permira; Permira later sold it to Adobe.
November 17, 2015, Magento 2.0 was released. Among the features changed in V2 were:
- significant performance and security improvements, especially when paired with PHP version 7+
- integrated server-side Apache Varnish caching with minimal tuning
- reduced database table locking issues
- enterprise-grade database scalability
- rich snippets for structured data
- new file structure with easier customization
- CSS pre-processing using LESS & CSS URL resolver
- modular code base structure, offering fine-grain customization
- improved coding patterns
- built-in client-side JavaScript minimization and optimization
- improved static content browser caching
magento_base_url/graphql
GraphQl Body
mutation {
generateCustomerToken(
email: String!
password: String!
) {
token
}
}
Example:
mutation { generateCustomerToken( email: "test@test.com" password: "testtest" ) { token } }
Responce
{
"data": {
"generateCustomerToken": {
"token": "lkh2c42342599f8d09sh23k5ne"
}
}
}
GraphQL module file – vendor/magento/module-bundle-graph-ql/etc/schema.graphqls
Request data – input object that defines which bundle products to add to the cart
mutation {
addBundleProductsToCart(
input: {
cart_id: "890ydb87bd7b1564trt4564hjgjk8hjk9hiy"
cart_items: [
{
data: {
sku: "24-WG080"
quantity: 1
}
bundle_options: [
{
id: 1
quantity: 1
value: [
"2"
]
},
{
id: 2
quantity: 2
value: [
"4"
]
},
{
id: 3
quantity: 1
value: [
"7"
]
},
{
id: 4
quantity: 1
value: [
"8"
]
}
]
},
]
}) {
cart {
items {
uid
quantity
product {
sku
}
... on BundleCartItem {
bundle_options {
uid
label
type
values {
id
label
price
quantity
}
}
}
}
}
}
}
Responce Data:
{
"data": {
"addBundleProductsToCart": {
"cart": {
"items": [
{
"uid": "MjI=",
"quantity": 1,
"product": {
"sku": "WSH12"
}
},
{
"uid": "MjQ=",
"quantity": 3,
"product": {
"sku": "24-WB01"
}
},
{
"uid": "MzI=",
"quantity": 1,
"product": {
"sku": "24-WG080"
},
"bundle_options": [
{
"uid": "YnVuZGxlLzE=",
"label": "Sprite Stasis Ball",
"type": "radio",
"values": [
{
"id": 2,
"label": "Sprite Stasis Ball 65 cm",
"price": 27,
"quantity": 1
}
]
},
{
"uid": "YnVuZGxlLzI=",
"label": "Sprite Foam Yoga Brick",
"type": "radio",
"values": [
{
"id": 4,
"label": "Sprite Foam Yoga Brick",
"price": 5,
"quantity": 2
}
]
},
{
"uid": "YnVuZGxlLzM=",
"label": "Sprite Yoga Strap",
"type": "radio",
"values": [
{
"id": 7,
"label": "Sprite Yoga Strap 10 foot",
"price": 21,
"quantity": 1
}
]
},
{
"uid": "YnVuZGxlLzQ=",
"label": "Sprite Foam Roller",
"type": "radio",
"values": [
{
"id": 8,
"label": "Sprite Foam Roller",
"price": 19,
"quantity": 1
}
]
}
]
}
]
}
}
}
}