Magento 2 Basics

Magento 2 ViewModel

How to Create a ViewModel in Magento 2

Magento 2 ViewModel is a feature that allows developers to pass dynamic data and logic to templates without bloating block classes or injecting business logic into .phtml files. By using a ViewModel, you keep your templates clean, maintainable, and easier to test. In this tutorial, we’ll...
Magencode - Magento API endpoint

How to Create a Magento 2 API Endpoint

Magento 2 provides a robust Web API framework that allows developers to expose custom functionality as REST or SOAP endpoints. This is incredibly valuable for connecting your store to third-party platforms like ERPs, CRMs, or mobile apps. In this guide, we will create a Magento...
Magencode - Magento 2 Controller

How to Create a Magento 2 Controller

A Magento 2 controller is the entry point for a URL request on the storefront or admin. In this tutorial, you’ll build a complete storefront route for the module Magencode_MyModule —including routing, a controller action, a block, a layout handle, and a PHTML template— so...
Magencode - Magento 2 Cron Job

How to Create a Cron Job in Magento 2

Magento 2 has a built-in cron system that allows developers to schedule automated tasks. If you need to run a recurring action—like syncing data, generating reports, or clearing logs—a properly configured Magento 2 cron job is the way to do it. This tutorial will walk...
Magencode - Magento 2 Plugins

How to Create a Plugin in Magento 2

Magento 2 gives developers the ability to customize system behavior without rewriting core code. Plugins—also known as interceptors—allow you to hook into any public method of a class and execute your logic before, after, or around it. In this guide, we’ll walk through how to...
Magencode - CLI Command Magento 2

How to Create a Magento 2 CLI Command

Creating a custom CLI command in Magento 2 can significantly improve your development process. Whether you're automating admin tasks or extending functionality, using the command-line interface makes your work faster and more modular. This tutorial explains how to create a CLI command in Magento 2...
magencode - observer in magento 2

How to Use an Observer in Magento 2

If you’re developing custom Magento 2 modules, mastering observers is key to extending functionality without touching the core. Observers let you hook into Magento events and run your own code — ideal for customizing checkout, orders, customers, and more. In this tutorial, we’ll show you how...
magencode - how to create a model in magento 2

How to Create a Model in Magento 2

Magento 2 is a powerful and highly customizable eCommerce platform that lets developers build custom extensions and features tailored to specific project needs. A key part of Magento 2 extension development is creating models—PHP classes that handle database interactions and manage application data. Creating a Module Start...
magencode - how to create a block in magento 2

How to Create a Block in Magento 2

In this tutorial, you'll learn how to create a block in Magento 2 by building a simple custom module step by step. Blocks in Magento 2 are used to pass data from the backend to templates and are essential when working with the view layer....
magencode - create route magento 2

How to Create Frontend Routes in Magento 2

Creating a custom frontend route in Magento 2 is a common task when building new features or pages for your store. In this tutorial, we’ll walk you through the process of creating a frontend route using a real example module called Magencode_MyModule. You’ll learn how...