Magento is one of the best eCommerce solutions for top internet businesses. When you’re preparing for Magento marketplace your first step is to validate your extension. In this post, We’re releasing important tips to validate Magento 2 composer package and coding standards before submitting to the Marketplace.
One survey from Magento says, approximately 20% of extensions are rejected every week because of bad coding standards and improper packaging. Prior Magento 2 extension development process, Magento developers should keep noted few points. Magento has provided the package validation tool, Which detects any kind of packaging errors to reduce the module rejections from the Marketplace.
How To validate your package?
- Clone the repository https://github.com/magento/marketplace-tools or Download the file validate_m2_package.php
- Now place your module zipped file in the same folder where you placed the validate_m2_package.php file.
- Note: To zip your package, navigate to root path of your module i.e /app/code/Vendor Name/Module Name/ and then zip your package. Make sure composer.json remains in the root path of your zipped package.
- Now execute the following command
$ <path_to_php> validate_m2_package.php -d vendor-modulename.zip
where <path_to_php> is the path to php compiler and vendor-modulename.zip should be name of your module zipped file.
Note: Make Sure composer.json file must be present at the top-level or one-level down of the zip file, with required fields completed.
-d – Provides debugs messages. Optional.
If you package passes all the validation then no success message will be printed. Validation tool only display the error and warnings message if it find any. We can ignore the warning message but we have to solve all the error message to process further.
Magento Extension Quality Program (EQP)
Magento also provide us with the Magento Extension Quality Program (EQP) tool as well. It’s the test coding standards of your module.
How to Install Coding Standard?
- Clone the repository https://github.com/magento/marketplace-eqp or Download the whole repository.
- Go to “magento-coding-standard” Directory, It contains the 2 coding standards
- MEQP1 for Magento 1.x
- MEQP2 for Magento 2.x
- Run The Following Command
Phpcs <path_to_your_module> –standard=MEQP2 (for magento 2 extension)
$ vendor/bin/phpcs /…/fullpath/m2/app/code/Vendor/Module –standard=MEQP2
It will check all the coding standards error in your module. If any error detected it display you can ignore the warning but you have to solved the error. It also provides us with auto correction of the error using phpcbf.
To solved the error and warning automatically run the following command
phpcbf <path_to_your_module> –standard=MEQP2 (for magento 2 extension)
If no error & warning detected then it doesn’t display and kind of success message.
With the above tool, package validation ensures the code quality which helps to pass Level 1 review from Magento Team. And it greatly reduces the chance of rejection of module from the Marketplace. So make sure you test your module with this tools before submitting to the marketplace.