Magento 2 – How to add custom logs in Magento 2 for debugging?

 Use below code anywhere is Magento (Only for debugging)

PHP

NOTE: The above code is only for debugging purpose only, you should remove once you done debugging.

Magento 2 – How to get Current Cart Items?

Use the session to get the current cart quote items

PHP
PHP
NOTE : Magento\Checkout\Model\Cart is deprecated.

Magento 2 – Speed Optmization tips, increase your magento website speed

21 Tips to improve Magento 2 Application performance

  1. Production Mode
    – Run below command in terminal to get current application mode:
    $ bin/magento deploy:mode:show
    – Now set the application mode to production:
    $ bin/magento deploy:mode:set production
    It will take a while to switch the mode
    If you want to skip the compilation for any reason use below command :
    $ bin/magento deploy:mode:set production -s
  2. Minify JS and CSS
  3. Check TTFB and try to reduce it (check the time using magento profiler)
  4. Enable Flat Categories and Products (Sometimes Risky)
  5. Enable GZIP compression
  6. Never Use JS bundling (As suggested by Magento best practices)
  7. Upgrade to latest(stable) PHP version and use OPcache
  8. Use Varnish Cache instead of built in Magento cache. (optional)
  9. Image optimisation
  10. Check every 3rd-party extensions (Avoid conflicts between 3rd party extensions in console)
  11. Upgrade hosting to fasted server (never used shared hosting for magento)
  12. Check code SQL query execution time (optimize MySql queries)
  13. Enable profiler and check the time (use IP restriction mode).
  14. Use CDN (Content Delivery Network) if there are bulk and heavy images in your store.
  15. Check your website speed in waterfal, use defer
  16. Disable unnecessary module (you can also disable magento code modules if not needed by keep check class dependencies)
  17. Remove cacheable=”false” from XML that will prevent page caching (User Private Content instead of disable the cache for the page)
  18. Use AMP (Accelerated Mobile Pages)
  19. Update Magento 2 version to the latest and stable
  20. Use APIs instead of controller for specific actions
  21. Use elastic search instead of MySql

Some website URL where you can check you website speed:

  1. https://developers.google.com/speed/pagespeed/insights/
  2. light house testing : https://developers.google.com/web/tools/lighthouse
  3. https://www.webpagetest.org/ , https://gtmetrix.com/ , https://tools.pingdom.com/
  4. Check website from multiple locations https://geopeeker.com/


Magento 2 : How to disable MSI in magento 2? (Ver. 2.3.4)

Add below code on composer :

JSON

Then run composer update

Magento 2 – Get Controller name, Module name, Action name and Router name

PHP
PHP

Magento 2 – Enable other options in TinyMCE

Create plugin of Wysiwyg configuration file in your module

etc/di.xml

XML

Now create plugin class in your module: 

Company/Module_Name/Plugin/Config.php

PHP