Magento 2 Extension Development - Commonly Faced Issue & How To Troubleshoot Them?
Recently I was asked to develop a mage 2 Shipping extension. I am basically a JavaScript developer and working in PHP with class heavy framework like Zend was hard battle initially.
In this process i learnt a lot on what not to do or to consider. I would like to share my knowledge on the same.
Biggest thing to consider is the case of Module Name, Folder Name, Class Name etc.
Starting with Naming
The module name can be comprised of any number of words but only the first letter should be capital.
eg: if the module is on generating shipping label then name should be “Generatingshippinglabel”. Any other combination will cause issue in different platform like GeneratingShippingLabel.
In case of Folder Name, Class Name should be in CamelCase i.e GeneratingShippingLabel.
Cache
Yes, cache…
Pages in Magento starts slowly, as it needs to cache all the data during the initial load. As the page loads all the XML and other configuration will be cached. And yes, XML configuration will not be updated even if you update XML after caching.
The one and only solution is to clear cache.
“php ./bin/magento cache:clean”
“php ./bin/magento cache:flush”
What to do when new classes are added but not working?
The solution to most of the problem in Magento 2 is
“php bin/magento setup:di:compile”
This will generate Interceptor Classes. Yes Interceptor Classes, in this process all dependencies will be injected, also your whole code base will be compiled and will throw error if any.
Next thing to do after this is clean cache.
But sometimes cache will not be deleted due some timeout issue. This you can check in system.log @ var/log/system.log. After you run the above commands error will be logged in system log if any. In this case blindly remove “var/cache”
“rm -rf var/cache/*”
These are some issues I faced while developing the module. Will update this article as I find more.
Until next time happy coding.
Also, let me know if I have missed any important topic.
