magento-coding-standards

By Brian Holecko Certified Magento Developer at InteractOne

Abide by the Magento Code

Magento coding standards for Magento 1.x exist to aid in proper modifications to the system. Although these standards may seem overbearing, they are a reflection of the sensitivity and scope of the complex websites we work on. As a developer, if you are not going to follow these standards it’s a good idea to obtain client approval.

 

  • Core modifications
    • Code residing in app/code/core/ is intended to remain intact exactly as they were coded to allow for easy upgrades. It is possible to override this functionality by copying the files to app/code/local/, however, this should be done only in rare cases where a custom extension cannot override the core. A common example is modifying the translator function within app/code/core/Mage/Core/functions.php for WordPress integration.
    • A common mistake is to create a php file in the web root and include Mage.php which is problematic because it bypasses important core features.
    • It should also be noted to keep the web root free of extraneous files which can be accessed via public URL since they might contain sensitive data (DB dumps for example).
    • Be sure to keep all files in the distribution intact which are beneficial but might be missed during project installations and migrations. A common example is var/.htaccess which prevents these files from being publicly accessible.
  • Default theme files
    • Use a custom directory in either the default, enterprise, or rwd directories for theme modifications.
    • Do not copy layout XML files into custom theme directories. Any modifications to these files can be made using a custom layout XML file.
    • Use a custom CSS file for style modifications unless styles.css is going to be heavily modified.
  • Shell scripts
    • Make sure shell scripts extend Mage_Shell_Abstract and reside in the shell directory.
  • Custom code
    • If confused about how to solve a problem, consider using the core for example solutions.