Search Optimisation in Magento 2

Here is the custom Builder Plugin to sort the Search results to get accurate results <?php namespace JJSearchCustomizationPluginModelAdapterIndex; use MagentoFrameworkAppObjectManager; use MagentoFrameworkAppRequestInterface; use MagentoElasticsearchModelAdapterIndexBuilder; class CustomBuilder { public function afterBuild(Builder $subject, $result) { // Use ObjectManager to get request safely in plugin context $request = ObjectManager::getInstance()->get(RequestInterface::class); $searchQuery = trim($request->getParam(‘q’) ?? ”); $inputLength = strlen($searchQuery); if… Continue reading Search Optimisation in Magento 2

How to configure Newsletters in Magento 2

Configuring newsletters in Magento 2 allows you to engage with your customers, inform them about new products, promotions, and updates, and ultimately drive sales. Here’s a comprehensive guide to setting up and managing newsletters in your Magento 2 store: 1. Configuration Settings: Log in to your Magento 2 Admin Panel. Navigate to Stores > Settings… Continue reading How to configure Newsletters in Magento 2

Types of products in Magento2

Simple Product Configurable Product Virtual Product Grouped Product Bundle Product Downloadable Product Type 1: Simple Product Explanation: Simple Product is the most popular product type of a store. In Magento, it is also defined as its name, which means that this kind of product is sold in each single item ( non-variation). Every single product… Continue reading Types of products in Magento2

Change Product by Type in Magento 2

This can be achieved exclusively through the database, either manually or via an SQL query. To perform a bulk change of product types using SQL in Magento 2, follow these steps: Log in to phpMyAdmin. Navigate to the SQL tab and enter the following command: UPDATE catalog_product_entity SET type_id=”simple” WHERE type_id = “downloadable”; This command… Continue reading Change Product by Type in Magento 2

THINGS TO REMEMBER on the product types in magento2

Although Simple Product and Virtual Product all belong to grouped product, they don not have custom option, so you should notice when selecting products for grouped product The grouped products in Magento 2 has the option to buy ALL or just one of the set while the bundle products you must buy ALL not buy… Continue reading THINGS TO REMEMBER on the product types in magento2

The Difference Between a Simple and Configurable Product in Magento 2

When adding a simple product in Magento, it’s linked to one SKU and doesn’t have different versions. On the other hand, a Magento 2 configurable product is connected to a group of several simple products. Each variation is made through a specific attribute in Magento and is linked to its own SKU. These choices show… Continue reading The Difference Between a Simple and Configurable Product in Magento 2

Magento 2: How to validate phone number by their country?

alidation rules are written in validation.js (lib/web/mage/validation.js), so you need override it. requirejs-config.js var config = { map: { ‘*’: { “Magento_Ui/js/lib/validation/rules”: “Vendor_Module/js/lib/validation/rules” } } }; rules.js: add rule like this but for countries you want to check. ‘phoneUK’: [ function (value) { return utils.isEmpty(value) || value.length > 9 && value.match(/^((?(0|+44)[1-9]{1}d{1,4}?)?s?d{3,4}s?d{3,4})$/); }, $.mage.__(‘Please specify a valid phone number’)… Continue reading Magento 2: How to validate phone number by their country?

Magento phone number should accept special character like (-) and should limit to 15 characters but currently it is accepting 10 characters only

In checkout_index_index.xml <item name=”validation” xsi:type=”array”> <item name=”min_text_length” xsi:type=”number”>10</item> <item name=”max_text_length_phone” xsi:type=”number”>15</item> <item name=”validate-number” xsi:type=”number”>0</item> </item> and then in vendor/magento/module_ui/view/base/web/js/lib/validation/rules.js “max_text_length_phone”: [ function (value, params) { return !_.isUndefined(value) && value.length <= +params; }, $.mage.__(‘Phone number cannot exceed 15 characters.’) ], the above code is for validation text and for adding regex as we require, so in… Continue reading Magento phone number should accept special character like (-) and should limit to 15 characters but currently it is accepting 10 characters only

magento 2 restrict phone number field in admin panel

You want to restrict phone number field and it should accept only 10 digits number then need to create custom validator addRule. I have created custom module with custom validator rule for make custom Phone Number validation. File path: magento/app/code/Vendor/PhonenumverValidation/registration.php <?php use MagentoFrameworkComponentComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::MODULE, ‘Vendor_PhonenumverValidation’, __DIR__); File path: magento/app/code/Vendor/PhonenumverValidation/etc/module.xml <?xml version=”1.0″?> <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Module/etc/module.xsd”> <module… Continue reading magento 2 restrict phone number field in admin panel

Magento2: How to create password protected cms page?

To make the cms pages, you have to use event/observer controller_action_predispatch_cms_page_view ON this event,fire an observer which will check current user is loggedin or not. If user is not loggedin this redirect to login page. events.xml define at app/code/{vendorname}/{ModuleName}/etc/frontend/ at code is like: <?xml version=”1.0″?> <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Event/etc/events.xsd”> <event name=”controller_action_predispatch_cms_page_view”> <observer name=”add_login_checker” instance=”{VendorName}{Modulename}ObserverRestrictCmsPage” /> </event> </config> Observer file RestrictCmsPage.php located at app/code/{vendorname}/{ModuleName}/Observer/ Observer code like… Continue reading Magento2: How to create password protected cms page?