After Upgrade Magento version from 2.3.5 to 2.4.7, an error in the Admin Grid(Custom module) started to appear

In Magento 2.4.x, there were some changes in the constructor signatures and how collections are handled, particularly with UiComponentDataProviderSearchResult used for grids. Steps to Fix the Issue: Step 1: Update the Collection Class Your Collection class extends MagentoFrameworkViewElementUiComponentDataProviderSearchResult, which means that the constructor parameters need to match the updated signature in Magento 2.4.x. Here’s how you can update your Collection class constructor: namespace G4AMainSliderModelResourceModelMainSliderGrid;… Continue reading After Upgrade Magento version from 2.3.5 to 2.4.7, an error in the Admin Grid(Custom module) started to appear

Error “Your session has expired” when click on add to cart in magento 2

when clicking on product’s add to cart then it’s giving me error–> Your session has expired. Solution UPDATE `core_config_data` SET `value` = ‘http://127.0.0.1/zain/accessories/’ WHERE `core_config_data`.`path` = ‘web/unsecure/base_url’; UPDATE `core_config_data` SET `value` = ‘http://127.0.0.1/zain/accessories/’ WHERE `core_config_data`.`path` = ‘web/secure/base_url’; http://127.0.0.1/zain/accessories/ in this write your frontend url (home page url) what you have after that run command in your… Continue reading Error “Your session has expired” when click on add to cart 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

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?

Adding low to high and High to low

Toolrbar.php file <?php namespace JJCustomproductshowPluginCatalogBlockProductProductList; class Toolbar extends MagentoCatalogBlockProductProductListToolbar { /** * Set collection to pager * * @param MagentoFrameworkDataCollection $collection * @return MagentoCatalogBlockProductProductListToolbar */ public function afterGetAvailableOrders(Toolbar $subject, $availableOrders) { // Remove ‘position’ from available orders if it exists if (isset($availableOrders[‘position’])) { unset($availableOrders[‘position’]); } return $availableOrders; } public function setCollection($collection) { $this->_collection = $collection;… Continue reading Adding low to high and High to low

How to Remove SORT BY “Price” Option in Magento 2?

Step 1: Create a di.xml file at the below path appcodeVendorExtensionetc <?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=”MagentoCatalogModelConfig”>         <plugin name=”RemovePriceOption” type=”VendorExtensionPluginModelConfig”/>     </type>   </config> Step 2: After that, create Config.php in the following path VendorExtensionPluginModel And then add the code as follows <?php   namespace VendorExtensionPluginModel;   class Config {     public function afterGetAttributeUsedForSortByArray(MagentoCatalogModelConfig $catalogConfig, $options)     {         unset($options[‘price’]);         return $options;… Continue reading How to Remove SORT BY “Price” Option in Magento 2?

Email Template in Magetno for the order id and Item Grid Structure

Here is the Email template for the Order email with the order Id and the orders item grids {{template config_path=”design/email/header_template”}} <table>   <tr class=”email-intro”>     <td>       <p class=”greeting”>{{trans “%customer_name,” customer_name=$order_data.customer_name}}</p>       <p>      {{trans “Thank you for your web order from the SZCO website.Your web order ID is “}}{{var order.increment_id}}.         {{trans “Once your package ships we will send you… Continue reading Email Template in Magetno for the order id and Item Grid Structure

How to add custom tab in Customer Account Sidebar Magento 2

First of all, you will need to create customer_account.xml file here in your custom module.. app/code/SK/CustomerAccountTab/view/frontend/layout/customer_account.xml Content of the File <?xml version=”1.0″?> <!– /**  *  * @package  SKCustomerAccountTab  * @author  Kishan Savaliya <kishansavaliyakb@gmail.com>  */ –> <page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>   <body>     <referenceBlock name=”customer_account_navigation”>       <block class=”MagentoFrameworkViewElementHtmlLinkCurrent” name=”customer-account-navigation-new-tab”>         <arguments>           <argument name=”path” xsi:type=”string”>sk_route/front/index</argument>           <argument name=”label” xsi:type=”string”>Custom tab (SK)</argument>         </arguments>       </block>     </referenceBlock>   </body>… Continue reading How to add custom tab in Customer Account Sidebar Magento 2