Usually, the JSON can be printed using a simple logger but from Magento 2.4.4 onwards this will not print the array. For that, we have to use $logger->info(print_r($params,true)); (print_r($jsontobeprinted, true)) Var_dump can be also used for printing the contents in the variable.
Author: Bibin Johnson
Logger Working in Magento From V 2.4.1
There is a problem with the logger from the version of Magento 2.4.1 usually, we were using the logger as follows: This belongs to the old library From the new version of Magento we could use the loggers as follows: or
How to configure qty to use decimal quantities in magento 2
In some Cases we may need to use qty to use decimal in our store so inorder to enable this we have two provisions to select that to each product based or we can totally declare to allow decimal for qty values. Display settings for each individual productGo to the following link : Admin panel… Continue reading How to configure qty to use decimal quantities in magento 2
How to Create User Role in Magento 2?
Creating Magento 2 user roles is the security action you should take before adding any users to your store. It helps you define the level of permissions some users will be granted with in order to restrict their access to some of the Magento 2 admin panel sections. In order to create a user role in Magento 2 take the… Continue reading How to Create User Role in Magento 2?
Adding Remember Me To Magento Sign In and Sign Up Pages
Magento has default feature to keep the user logged in to a particular browser and for custom design it may not be visible . Add the following to custom module layout to Magento Customer>layout>customer_account_login.xml and customer_account_create.xml Turn on the persistence option in back end.
Method to add custom JS validation rule in Magento 2
Add requirejs-config.js file to the following location: app/code/[Vendor]/[Module]/view/frontend/requirejs-config.js Copy file vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js to app/code/[Vendor]/[Module]/view/frontend/web/js/lib/validation/rules.js Where you can add the custom validation code as following: That’s it. Overriding the inbuilt JS also done in the same,if you are using a custom , create a folder with the same naming pattern in the vendor folder structure and paste… Continue reading Method to add custom JS validation rule in Magento 2
Magneto Event before customer login to clear carts for logged out customers
Here the art will be updated with custom pricing for the customer when the customer logged in. With the help of a observer it can be done:- The event used to trigger the Observer will be :- controller_action_predispatch_customer_account_loginPost Observer will contain the repository of Quote,Customer section and cart.
Add a quote to cart and block adding new products to cart – Magento 2
When we submit a quote all products loaded in the quote will be added to cart , and adding a new product again to cart is not applicable ,so when ever we add a quote all the products loaded in the cart must be removed and replaced with that quote. Here is code to remove… Continue reading Add a quote to cart and block adding new products to cart – Magento 2
Checking whether same product exists in cart-Magento 2
If the a products contains many attributes other than Qty , adding the same product to cart again will collapases and mismatches the attributes of the product. To avoid or modify the situation we can check the same product already exists in the cart. Is can be done in the controller of add to cart.… Continue reading Checking whether same product exists in cart-Magento 2
Store Data as Json Encode in Magneto
Here we are storing a group data as json encode to database.Since Json Encode is inbuilt with magento. We have two values that must stored as value and key .So its a array here we get the values stored as ‘length’ and key as ‘qty’. this can be written with json_encode($lengtharray) into a database field.… Continue reading Store Data as Json Encode in Magneto