Skip to main content

Posts

Showing posts from May, 2023

How to add a dynamic homepage in Magento 2?

Magento provides the ability to have multiple homepages or a homepage with dynamic blocks that alter based on demand. However, there may be times when different homepages must be displayed based on customer groups/segments. This is possible with the dynamic block functionality, which is available in the Enterprise and Cloud editions. However, there is a constraint in that you have to maintain numerous blocks for multiple customer groups/segments. In that situation, you can alter the default functionality by using the code below: Step 1: Create a plugin for "Magento\Cms\Controller\Index\Index" by adding the below code in your module di.xml file. <type name="Magento\Cms\Controller\Index\Index"> <plugin name="dynamicHomepage" type="Mageinsight\Module\Plugin\DynamicHomepage" sortOrder="1"/> </type> Step 2: Add the plugin file as below: <?php namespace Mageinsight\Module\Plugin; use Magento\Framework\App\Config;

How caching is used in Magento

What is Caching? In computing, a cache is a high-speed data storage layer that stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data’s primary storage location. Caching allows you to efficiently reuse previously retrieved or computed data. How caching is implemented in Magento? The Magento page cache library contains a simple PHP reverse proxy that enables full page caching out of the box. A reverse proxy acts as an intermediary between visitors and your application and can reduce the load on your server. Magento's default caching mechanism provides different storage options that store cached data in 3 different sources: File System Database Redis There are different types of cache available by default in Magento. You can check here about different types. Any page new page added to the website is by default cachable. But a developer can make any page uncacheable by adding a small ch

How to add a new field in admin form using Block?

Although Magento recommends using ui_component for creating grid or form in admin, Magento core itself has multiple forms & grid which is created using block(Old technique). So let's see how to add a field using the block technique: For this first, we need to locate the block class which contains _prepareForm() method. And then we will create the Plugin for this class. Step 1 : Add the below code to the di.xml file of the 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\CheckoutAgreements\Block\Adminhtml\Agreement\Edit\Form"> <plugin name="add_embassy_field" type="MageInsight\CheckoutAgreements\Plugin\Block\Adminhtml\Agreement\Edit\Form" sortOrder="1"/> </type> </config> Step 2 : Create a new file inside yo