Bohdan Berezhniy
- 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
As you know Magento 2 provides various default options for creating an eCommerce store and gives you enough flexibility to customize it. However, some errors may appear on the way. And as a developer should know how to fix them.
One of the most common errors you might face is "An error has happened during application run. See exception log for details". There are various reasons for it to appear. So the solutions may vary as well.
If you are wondering how to deal with this error, you've landed on the right page. Today you'll learn more about the error and find a solution you can refer to.
What Causes the Error?
As we've already mentioned, "An error has happened during application run. See exception log for details" is one of the most .
It usually happens after you . Yet, you can also encounter it after upgrading your Magento to a higher version.
The error in question can be caused by multiple reasons. For example, the database connection is not accurate or the MySQL service is notihor
- 2 min read
If you know (and you most certainly do) then you must have landed on this page because it doesn't work as expected. When you configure our , you need to specify lazy load blocks for images to be lazy loaded.
Nevertheless, sometimes this doesn't work for content that has been added via page builder: CMS pages or blocks. So, in this guide, you'll learn how to lazy load images added via page builder in Magento.
To lazy load images added via page builder:
1. Navigate to the CMS block or page you want to lazy load images for.
2. Add a new row at the bottom of the content, and insert an HTML code from Elements.
3. Add the following comment to the HMTL row.
<!-- MAGEFAN_LAZY_LOAD -->
Note: it is important to use a new row at the bottom of the content, since if you add the command at the top of the existing block, it will be deleted.
4. Don't forget to Save the block, and then the CMS page (or block) and check the content on the frontend.
Check out our quickihor
- 4 min read
Running a Magento 2 store may not be as easy as it seems. There are lots of things you have to take care of, such as sales, orders, clients, etc., to say nothing of the development part. You should know how to or , as well as be aware of some other commands.
It's impossible to keep in mind all the commands for every single situation when you just start. So, that's why we created a list of useful Magento 2 commands that will save time and lessen the possibility of any errors.
Want to know more about Magento commands? Keep reading, this article is just what you need.
SSH
Command
Description
php bin/magento list
Generates a list of commands
help
Shows help for a command
Cache
Command
Description
php bin/magento cache:clean
Cleanes the cache types
php bin/magento cache:enable
Enables the cache types
php bin/magento cache:disable
Disables the cache types
php bin/magento cache:flush
Flushes the cache types
php bin/magento cache:status
Displays the cache status
Setup
Commandihor
- 9 min read
While there is a multitude of Magento 2 themes available on the market, you might still want to create custom theme for your store. Why? Templates, layouts, graphics and styles offered in a theme don't always satisfy your business requirements. Besides, the default Magento 2 themes Luma and Blank won't suffice if you're .
So, to create custom Magento 2 theme that conveys your brand's "feel" you need to resort to custom development.
In this guide, we'll walk you through all steps you need to take to create a theme for Magento and cover the basics of how to override basic and theme layouts.
Ready to start?
In case you're looking for a ready-to-use speed-optimized Magento 2 theme, we already have one — .
Before Custom Theme Development in Magento
The first important thing to remember before starting theme development in Magento is that you shouldn't change or edit the default Luma and Blank theme files. If you customize the default theme files, the update to the latest version of Magentoihor
- 2 min read
When it comes to purchasing decisions, customers pay attention to a lot of things in your store. Loading speed is one of the most important ones. While you can improve website speed by enabling lazy load or images or disabling the JS bundling, it is not always enough.
In this guide, you'll learn how to lazy load CMS blocks in Magento using the and Pages Extension.
CMS Blocks Display Modes
We've created two CMS pages with the same content: a banner and a product slider. One page contains a CMS block with default display mode, second — a CMS block with display mode Ajax load on first scroll.
Now, let's compare display modes Default and Ajax load on the first scroll.
CMS Block - Products Included In DOM
CMS Block - Products Loaded Via Ajax Request
Param
Default mode
Ajax load on first scroll mode
Page Size
26.2kb
15.9Kb
Time To Load Page Content
783 ms
591 ms
DomContentLoaded
1.43 s
1.11 s
Page Load
3.13 s
2.58 s
Page speed score is better if some elements like sliders, and widgetsihor
- 2 min read
If you're a Magento developer, you certainly know that effective store management often requires programming work. There are lots of tasks you need to perform — from running static content deploy and to and media URLs. Some of these are rather time-consuming or even complicated at times.
However, it is much easier if you know the proper methods to use.
In this article, in particular, you'll learn how to get media URLs in Magento 2.
Get Media URL Using Dependency Injection
The dependency injection method is among the most common ones when it comes to getting media URLs in Magento.
So, to apply it, go to your phtml block file and create a _construct function:
public function __construct ( \Magento\Store\Model\StoreManagerInterface $storeManager ) { $this->_storeManager = $storeManager; }
After that you can get a media URL in your phtml file:
$mediaUrl = $this ->_storeManager-> getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
echo $mediaUrl;
Get Media URLihor
- 2 min read
As you know, is quite a demanding process. It calls for full attention to the details and the ability to make quick decisions. Especially when it comes to customer-related information.
Just like , you should know how to get customer data by customer ID in Magento. And this is exactly what you'll learn today.
There are a few methods to use, so we'll look at each of them in detail.
Get Customer Data by Customer ID Using Factory Method
The factory method is among the most common ones. So, the code below will help you to get customer data by customer ID:
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerFactory = $objectManager->get('\Magento\Customer\Model\CustomerFactory')->create();
$customerId = 1;
$customer = $customerFactory->load($customerId);
print_r($customer->getData());
echo $customer->getEmail() . PHP_EOL;echo $customer->getFirstname(). PHP_EOL; echo $customer->getLastname(). PHP_EOL;
Get Customer Data by Customer ID Using APIihor
- 2 min read
Even though Magento 2 is a very flexible and easy-to-manage eCommerce platform, operating an online store may be rather challenging sometimes. Same as , getting products by ID is certainly a crucial skill.
Since it is one of the most frequent operation ones comes across when working with Magento, you have to know how to do it. There are a few ways to do so, and in this article, you'll learn how to use each of them.
Get Product by ID Using Factory Method
The most common way to get a product by ID in Magento 2 is to use the factory method. To do that, use the following code:
protected $_productFactory;public function __construct( \Magento\Catalog\Model\ProductFactory $productFactory) { $this->_productFactory = $productFactory;}
After that, get the product by ID, by executing the below command.
$product = $this->_productFactory->create()->load($id);
Get Product by ID Using API Repository
API repository is the other method you can choose. Execute the following code to get product objects:ihor
- 2 min read
Speed optimization is one of the ultimate goals of every store. That's why when trying to , you'll definitely come across lazy loading, one of the best ways to optimise images.
For those of you who don't know , it is a loading technique that helps you to load only images available within users' viewport. This helps to improve page loading and deffer unnecessary resources.
Image lazy load configuration is not that hard but you might sometimes encounter issues with configuring the lazy load of CSS background images. And that's what we'll be working on today.
How Do Lazy Load Extensions Work?
Before moving any further we need to revise the basic principle used in Lazy Load extensions to learn how to apply it to the CSS background images.
By default browser loads an image added in the src attribute of the image tag during page load:
<img src="image.jpg" />
e.g. so if your page has 50 images added the same way, as described above, all of them will be loaded at once during pageihor
- 3 min read
No matter how hard you try to prevent your store's data from a sudden disappearance, there is always a slight risk of different attacks or system failures. No matter how well-organized your store operation is, anything from and to updating Magento can cause some data to get lost.
To prevent this from happening you need backups. And luckily, you can back up Magento 2 in multiple ways.
Today, you'll learn about each of them in particular, so a copy of all the necessary data is created and can be easily restored.
Pro tip: use to get notified about when there are sensitive backup files in the Magento directory.
Create Magento 2 Backup via Admin Panel
To create and schedule backups in Magento 2:
1. Go to Stores > Configuration > Advanced > System > Backup Settings.
2. Enable the backup by choosing Yes in the corresponding field.
3. Select Yes in the Enable Scheduled Backup field if you want to back up your data regularly.
4. Specify the Scheduled Backup Type. You've got 4 optionsihor
- 2 min read
Since Magento architecture is structured in a way to store data in different database tables, all data have to be reindexed when you make any changes to your store. And while you can or even the , this process is still time-consuming.
In this guide, we want to help you optimize the process.
Since the Catalog Category Product indexer takes the longest to execute we'll take it as an example for this article. So, you can optimize execution time by changing with batch_size of the Catalog Category Product indexer.
However, to get a better picture of how this works, let's define what is a batch size and why you need to modify it.
How Magento Reindex Works?
Batch size is a number of indexes that will be processed at a time, one MySQL query.
Imagine that you have a store with 40k products, and you do some changes, like , to all of your products. This will cause 40K indexes to be invalidated.
Magento splits data for reindexing in the following way:
Number of batches = number of indexesihor
- 2 min read
Providing high-quality service requires you to optimize multiple processes in your store, including order management. That being said, looking for certain order details might take some time, especially with hundreds of products.
Nevertheless, Magento allows you to eliminate the hard work. You can get order data by increment ID in Magento in multiple ways, the same as you can or .
So, in this article, you'll learn how to use each method.
Get Order Data by Increment ID Using Factory Method
The factory method is used the most frequently. Use the following code:
protected $orderFactory;
public function __construct(
\Magento\Sales\Model\OrderFactory $orderFactory
) {
$this->orderFactory = $orderFactory;
}
public function getOrderByIncrementId()
{
$orderIncrementId = 10000003;
$order = $this->orderFactory->create()->loadByIncrementId($orderIncrementId);
}
Get Order Data by Increment ID Using API Repository
Here is one more option. You might as well use the API repository to get order by incrementihor
- 1 min read
Magento allows you to create and configure 6 different in the admin panel. Each product has a unique name, ID, and other details related to it. So, after you learn how to , you have to know how to get current product in Magento 2.
Get Current Product in Magento 2
To get current product details you need to use .
<?phpnamespace VendorName\ModuleName\Folder;class Example{ private $registry; public function __construct( \Magento\Framework\Registry $registry ) { $this->registry = $registry; } public function getCurrentProduct() { return $this->registry->registry('current_product'); }}?>
And now you can use getCurrentProduct() method:
// print current product dataif ($currentProduct = $example->getCurrentProduct()) { echo $currentProduct->getName() . '<br />'; echo $currentProduct->getSku() . '<br />'; echo $currentProduct->getFinalPrice() . '<br />'; echo $currentProduct->getProductUrl() . '<br />';ihor
- 1 min read
Once you know how to , you might also need to learn how to get the current category in Magento 2. Regardless if you want to provide discounts based on category or simply retrieve all category information, this guide will come in handy.
Get current category in Magento 2 in PHP class
<?phpnamespace Vendor\Module\Folder;class Example { private $registry; public function __construct(Magento\Framework\Registry $registry) { $this->registry = $registry; } public function getCurrentCategory() { return $this->registry->registry('current_category'); }}
Get current category in Magento 2 via Object Manager
<?php$currentCategory = \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Registry::class) ->registry('current_category');echo $currentCategory->getId();echo $currentCategory->getName();?>
Note: you should avoid direct use of the in your code since it hides real dependencies of the class.
So, as you can see, getting current category in Magento 2 is not that hardihor
- 6 min read
The deadlock issue is one of the biggest and most difficult , which every Magento developer comes across sooner or later. Once you start to search for how to fix deadlock issues in Magento, you will have a hard time finding an ultimate guide.
So, my guess is — it is probably not the first article you come across. But hopefully, you'll find the answer here.
In this article, you'll learn everything you need to know to understand and fix deadlock issues. Or at least significantly reduce them.
Why Do Magento Indexes Get Invalidated?
When you face the Magento deadlock issue, the first thing is to check Magento indexes and learn why they get invalidated. For that go to System > Tools > Index Management, make sure that you have set up index mode correctly and that your .
Magento index modes
Magento has two index modes:
Update on Save — reindex is done during product save (it is not recommended to enable this mode on production since it can significantly increase product saving time).
Updateihor
- 2 min read
With the extensive custom database, you always have to go to extra mile to to improve security. Two-factor authentication is one of those tiny security steps you have to take to avoid any security loopholes and data leaks.
Correspondingly it is an additional layer of security beyond credentials and every user attempting to log in goes through.
Though it is not recommended to , there are some exceptions. You can disable it if the store is in the development or testing stage.
Still, you don't have to disable two-factor authentication completely, you can do this for a specific user.
Note: to monitor if two factor authenticatioln is disabled enable the Extension.
To disable Two-factor authentication in Magento for a specific user:
1. Create a etc/di.xml file in your custom module:
<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\TwoFactorAuth\Model\TfaSession">ihor

