Magento 2 Development
Develop new features, perform task programmatically and hon your developer skills
- 8 min read
As you create your store, there are multiple stages to go through: starting with and gradually moving to live. Each stage has corresponding tasks to keep your website running.
Magento 2 handles this through the deploy mode functionality. There are three Magento modes: default, development, and production. Each facilitates different store operations.
However, to use Magento 2 modes effectively, you need to know what each is useful for. This is exactly what you will find out today: what Magento modes are, how they differ, and how to switch between them without downtime.
Key takeaways
Magento 2 offers three deploy modes — default, developer, and production.
Each deploy mode controls how your store behaves in different environments. This affects performance, error visibility, and all changes and updates.
Default mode is a transitional mode used right after installation. In this mode, Magento automatically generates static files for a convenient setup. But it's inefficient long-term, so youihor
- 9 min read
When working with Magento, you've probably come across terms like Magento modules, extensions or plugins in Magento quite often. Each plays a unique role in your Mageno store performance, compatibility and scalability.
While they might seem interchangeable — they are not. And knowing the difference helps you make more strategic decisions about your store customisations.
So, whether you're a store owner looking for a new feature or a developer working on some customisation, you're in the right place.
In this guide, you'll learn all about the differences between Magento modules, extensnions and plugins in Magento. We'll explain what each one really means and how to use them to cover the specific needs of your business.
Magento Basics: What Are Extensions, Modules, and Plugins?
One thing that makes Magento stand out among other eCommerce platforms is its flexibility and the way it handles customisations. But before you start tweaking the code to add new features, you need to understandihor
- 12 min read
The Magento admin panel is a backend system that helps store owners manage products, orders, customers and much more from one place. However, the default admin panel is not always enough to meet the unique needs of your business.
But there is a solution — a сustom Magento admin panel. You can add new functionality to your backend to make it simpler to use, thus improving the team's workflow.
In this guide, you'll explore how to set up the Magento admin according to your requirements. You'll find out how to make it more convenient to navigate and manage.
A bonus is one of our that can make some of these processes faster and easier.
Why Customisation of Magento Admin Panel Matters?
The Magento admin panel is the engine that drives your online store. It's a place where your team spends most of their time managing products, configuring settings, and more.
Yet, a lot of store owners continue using the simple default panel. They simply don't realise that a personalised backend can make all ofihor
- 6 min read
Magento 2 file system permissions are an integral part of the platform's setup. It requires different permissions for files and directories for smooth operation and development. Hence, it's twice as crucial to configure the permissions properly.
In this guide, you'll learn everything about Magento file permissions, including their definition, types, configuration methods, and best practices.
If you want monitor your file permissions to make sure they're never violated, check out the Extension.
What are Magento File Permissions?
Magento file system permissions define what actions users can perform with the files and directories. They concern the reading (r), writing (w), and execution (x) rights of the owner, group, and other users.
For the system to run properly, you need to set the correct permissions so that the scripts and queries are executed without breaking. There are various permission types you may consider using, each offering a specific set of eligible actions.
Moreoverihor
- 5 min read
Every time you need to do some testing, roll out an update or fix a bug, you need to enable the Magento 2 maintenance mode. It initiates the display of the "Service Temporarily Unavailable" messages across all your website pages.
So, regardless of other , the maintenance mode causes the most inconvenience for both merchants and users. Especially if they don't know what that mode is about.
That's why today you'll get all the answers about what is Magento maintenance mode, why it matters and how to use it properly. We'll also share some secrets about enabling maintenance mode in Magento without downtime.
Intrigued? Let's get started!
What is Magento 2 Maintenance Mode?
Magento 2 maintenance mode is a process of temporarily disabling users from accessing your website while you perform updates, customizations, or other improvements. If you enable maintenance mode, website visitors will see a maintenance page with a custom message.
Some exceptions exist when users from certain IPs can accessihor
- 4 min read
You don't have to imagine how frustrating 503 maintenance pages and other error messages are. Everyone hates them — merchants lose potential customers while the latter get interrupted when shopping. It's a lose-lose situation.
Every developer knows that errors on the page are a part of the Magento deployment, including the process. But very few actually know how to avoid it with the zero downtime deployment.
So today we'll break down every detail of how the zero downtime deployment works and why you need it. You'll also learn whether can you actually achieve zero downtime without buying Magento Commerce.
But let's start with the basics first.
How Does Magento Deployment Work?
Deployment is a method of building modules, patches and other code and delivering it to end users through different environments. In other words, it's pushing new code from one environment to the other.
These environment usually include:
Local — where developers build the code.
Testing — where developersihor
- 4 min read
As a Magento 2 developer, you know how tedious performance debugging can be. Finding out is not as easy as it seems. So any tools that help you on the way come in handy. In most cases, the Magento 2 profiler helps with the performance-related debugging best.
While you may use some third-party extensions for the job it takes time to find an effective solution for your specific case. Thus, we'll look closer at the good old Magento 2 profiler and ways to improve it.
If you only start working with Magento, this is a great overview of the profiling functionality. Yet, adept developers can refresh their knowledge of the subject.
Let's get right to it.
What is Magento 2 Profiler?
Magento 2 profiler is a default tool for performance debugging. It gives insights into the loading time of various blocks as well as the amount of allocated and used memory to perform the task.
The profiler features a table with page blocks and resources used to load them. These details create a clear picture and allowihor
- 5 min read
Magento operates huge loads of information related to categories, products, prices, search results, etc. As you know, all this info is organized in separate tables so the needed details can be fetched promptly.
That's when Magento 2 reindex comes into play. It's a crucial process that keeps all the data relevant and helps to manage your store effectively both on the frontend and backend. Thus, the more you know about the better.
In this guide, you'll learn what Magento reindex is, how to run it, how to fix reindex-related errors if any, and more. So, let's get to the point.
What is Magento 2 Reindex?
Magento 2 utilizes indexers to organize all the data it works with. Each data type has its indexer which in turn is responsible for the corresponding index table.
Therefore, there are separate index tables for prices, search terms, and products, to name a few. This way, when the request is sent, Magento fetches the data from these separate tables instead of the main table.
Wheneverihor
- 3 min read
Magento 2 catalog price rules allow you to create encouraging offers and prompt your customers to finalize the purchase. Unlike , catalog rules are applied to the entire catalog, not just the shopping cart.
Traditionally, you via the admin panel. That's where you specify the rule information and conditions for the discounts to be applied. But you can perform all these steps using coding, too.
So, today you'll learn how to create a catalog price rule in Magento 2 programmatically.
Create Magento 2 Catalog Price Rule Using Dependency Injection
One of the safest methods to go for is dependency injection. To apply this method, use the code below:
<?phpdeclare(strict_types=1);namespace Vendor\Module;use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;use Magento\CatalogRule\Model\RuleFactory;use Magento\Framework\Exception\CouldNotSaveException;use Psr\Log\LoggerInterface;class CreateCatalogPriceRule{ protected $ruleFactory; protected $catalogRuleRepository; protected $logger;ihor
- 2 min read
Magento 2 categories help make your store organized and easy to browse through. They enhance navigation greatly since customers can jump from one category to another without looking for some item in the entire catalogue.
As you know, you can easily in the admin panel. That's the most common way. But there is also a different approach.
You can also create a category in Magento 2 programmatically. In this guide, you'll find two methods to do so.
Create Magento 2 Category Using Dependency Injection
One of the methods to create a category programmatically is to use dependency injection. Here is the code you have to run:
<?phpdeclare(strict_types=1);namespace Vendor\Module;use Magento\Store\Model\StoreManagerInterface;use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;use Magento\Catalog\Model\CategoryRepository;use Magento\Framework\Exception\NoSuchEntityException;use Magento\Framework\Exception\CouldNotSaveException;use Psr\Log\LoggerInterface;class CreateCategoryService{ protectedihor
- 2 min read
Providing high-quality customer service is one of the pillars of a successful business. Magento 2 offers you extensive features for out of the box. Thus, you can configure customer name, address, login, , and more.
However, the default options are not always sufficient if you need to gather some specific info. That said, you'll need to create custom customer attributes.
Unfortunately, Magento 2 doesn't offer the simple admin panel setup of this functionality. So, you need to add customer attributes programmatically.
Don't know how? No worries, you're about to find out!
1. Create a Magento 2 module
Magento handles customer attributes using the EAV model structure and the Data Patches to alter the info. Thus, this is what we'll apply today.
So, before adding customer attributes, you need to . If you already have a suitable one, you can just use it.
The method below requires you to have a module to run the code. So make sure you have it.
2. Create the InstallData.php file
The next stepihor
- 2 min read
Magento 2 CMS blocks allow you to put specific content in the spotlight. If you share some announcements, discounts, or special offers using CMS blocks. This makes your customers finding and applying them much more probable.
You can create , that's one way. However, it's also possible to create new CMS blocks in Magento 2 programmatically. This is exactly what you'll learn today.
First, you need to and add the Setup folder to it. Then, create an InstallData.php file in app/code/Vendor/Extension/Setup and add the following code:
<?phpnamespace Vendor\Extension\Setup;use Magento\Cms\Model\BlockFactory;use Magento\Framework\Setup\InstallDataInterface;use Magento\Framework\Setup\ModuleContextInterface;use Magento\Framework\Setup\ModuleDataSetupInterface;class InstallData implements InstallDataInterface{ private $blockFactory; public function __construct(BlockFactory $blockFactory) { $this->blockFactory = $blockFactory; } public function install(ModuleDataSetupInterfaceihor
- 2 min read
are mostly created on the frontend by customers themselves. However, there may be cases when store managers need to create customer accounts from the admin panel.
Nonetheless, creating customer accounts manually may be time-consuming if you need to create a few. Thus, it may be more convenient to create customer in Magento 2 programmatically.
It's exactly what you'll learn today.
Create Customer Using Dependency Injection
To begin with, you can create a customer programmatically using the dependency injection method. Just use the code below:
<?phpdeclare(strict_types=1);namespace Vendor\Module\Model;use Magento\Store\Model\StoreManagerInterface;use Magento\Customer\Api\Data\CustomerInterfaceFactory;use Magento\Customer\Api\CustomerRepositoryInterface;use Magento\Framework\Encryption\EncryptorInterface;class CreateCustomerService{ /** * @var StoreManagerInterface */ protected $storeManager; /** * @var CustomerInterfaceFactory */ protected $customerFactory; /** * @var CustomerRepositoryInterfaceihor
- 2 min read
Making the content of your store responsive and easy to browse through guarantees improved customer experience and seamless shopping. With this thought in mind, will probably be your first resort.
To assign products to categories you need to select them manually in the Products in Category section in the admin panel. However, this may get rather tedious especially if you have an extensive catalog.
Thus, you might want to optimize this process and today you'll learn how. Keep reading to learn how to add products to category programmatically in Magento 2.
Add Products to Category Using Dependency Injection
One of the most common methods of adding products to categories is dependency injection. Just use the code below.
<?phpdeclare(strict_types=1);namespace Vendor\Module\Model;use Magento\Catalog\Api\CategoryLinkManagementInterface;use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;class AssignProductsToCategoryService{ /** * @var CategoryLinkManagementInterfaceihor
- 10 min read
Over the years, proved to be a trustworthy eCommerce platform for successful store development. Thousands of people decided to give it a shot and now continue to grow and scale their businesses.
The area of has also been expanding. No wonder so many developers work with different Magento branches trying to find their place in this extensive architecture and create a career.
Becoming a certified Magento 2 developer opens more opportunities for you as a professional. The question is, where do you start?
We've prepared all the answers here. You'll learn what Magento certifications are available for you, and what they require and cover. Besides, we'll share some useful tips to help you pass the certification successfully.
Ready to start?
What is Magento 2 Certification?
Magento certification, or Adobe certification, is the verification and validation of your professional knowledge of Magento 2 development and/or management. Once passed, you receive a badge confirming your Magento developerihor
- 3 min read
Although Magento is quite a smooth platform to work with, some may still appear on the way. Thus, as a Magento developer, you need to know what is happening behind the scenes to fix the inconsistencies promptly.
In any case, when something is wrong, the first thing to check is the Magento 2 error log. The logs seem quite confusing, for both — those who only started working with Magento and even experienced developers.
So today we'll try to make things clearer for you to understand what are Magento error logs and how to work with them.
What is Error Log in Magento 2?
Magento error log is a place where error messages, notices, and warnings are stored. The error is displayed right away, on the page, if you work in . However, that's not the case with the production mode.
Sometimes, various inconsistencies happen without you noticing. Or you may receive a message, like "", without clear details as to what happened exactly. This is your cue to go and check the error logs.
There you'll findihor
- 4 min read
is one of the most essential steps your customers take in their journey. Thus, it's in the best interest of every store owner to make it as seamless as possible.
That said, the default checkout fields in Magento 2 are not always enough for the requirements of your store. You might need to gather some additional info about customers to improve your service. In this case, you should know how to add custom fields in Magento 2 checkout.
If you haven't figured out how to do it yet, this is exactly what you'll learn today.
By default, Magento 2 doesn't provide an option to add custom checkout fields via the admin panel. That's why you'll need to do it programmatically by following the below steps. So, let's get right to them.
1. Create a New Module
For starters, make up your mind as to what field you want you add. For instance, you may go for the "delivery_date" field. The next step is to using the following method.
Create a Magefan/DeliveryDate/registration.php file and add the following content:ihor
- 3 min read
One of the many steps in the workflow is creating an order. In most cases, customers place orders from the frontend. Yet it happens sometimes that this task falls on the store managers. They might need to assist customers, apply custom prices or just merely test the process.
That said, you can . That's one option. Yet it is also possible to create orders in Magento 2 programmatically. In this article, you'll learn two ways to do that.
So, let's get right to them.
Create Order Using Dependency Injection
One of the safest ways to go is to use the dependency injection. The code below will help you create an order programmatically in Magento 2.
<?phpnamespace Magefan\OrderEdit\Model;use Magento\Framework\Exception\NoSuchEntityException;use Magento\Store\Model\StoreManagerInterface;use Magento\Quote\Api\CartManagementInterface;use Magento\Customer\Api\CustomerRepositoryInterface;use Magento\Quote\Model\QuoteFactory;use Magento\Catalog\Api\ProductRepositoryInterface;use Magento\Customer\Api\AddressRepositoryInterface;classihor
- 2 min read
As much as store owners would like to have no refunds, this is not entirely possible. Customers may purchase the wrong size, colour, etc., receive incorrect items or change their minds unexpectedly. Merchants too may oversee various order-related details. Thus, a refund policy is a necessity to ensure reliable store-customer relations.
In Magento 2, a refund is referred to as a credit memo. It defines the amount of money a customer is supposed to receive back. Usually, . Yet, you can also do this using code.
So in this article, you'll learn how to create a credit memo in Magento 2 programmatically.
Create Credit Memo Using Dependency Injection
One of the recommended options to go for is the dependency injection method. The following code will help you create a credit memo programmatically.
<?phpnamespace Venodr\MyModule\Model;use Magento\Sales\Api\OrderRepositoryInterface;use Magento\Framework\Exception\NoSuchEntityException;use Magento\Sales\Model\RefundOrder;use Magento\Sales\Model\Order\Creditmemo\ItemCreationFactory;classihor
- 2 min read
Having your customers divided into groups can benefit your sales greatly. This helps to find a personalized approach and target the right customers with the right messages. To say nothing of the enhanced store performance and shopping experience.
You can certainly create in the admin panel. Yet, if you'd like to manage this task through coding, there is an option for you too. And in this article, you'll learn how to create a customer group in Magento 2 programmatically.
Create Customer Group Using Dependency Injection
Using dependency injection, create a file in your module, and then call the execute function of that class CreateCustomerGroup in any place of your code to create a customer group.
<?php
namespace Vendor\Extension\Model;use Magento\Customer\Model\GroupFactory;class CreateCustomerGroup{ protected $groupFactory; public function __construct(GroupFactory $groupFactory) { $this->groupFactory = $groupFactory; } public function execute(string $customerCodeihor
- 2 min read
The process of in Magento 2 consists of numerous steps. One of the last ones is creating a shipment. It is a relatively simple task, but it's useful to know how to cope with it as quickly as possible.
On one hand, you can . This method is entirely manageable and not time-consuming. On the other hand, you might prefer an alternative — create a shipment in Magento programmatically. And in this article, you'll learn more about it.
Create a Shipment Using Dependency Injection
It is one of the most common ways to create a shipment. So, in order to create a shipment in Magento 2 programmatically using dependency injection, use the below code:
<?php
namespace Vendor\ModuleName;
class ClassName
{ public $orderRepository;
public $convertOrder;
public $shipmentNotifier;
public function __construct(
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
$this->productRepository = $productRepository;
}
public functionihor