Create a Custom Magento Module

Magento Custom Module

Magento will provide all feature but sometimes we want to extend Magento basic function or class, make some content based extension (plug-In) or make some website(ex. e-bay, Amazon), application(ex. payment method, shipping method) integration for Magento 2.

How to make Custom Module ?, Which file is required?, Where to put in Magento root folder?

Magento is a bunch of many modules. specific features have own module in Magento like for product module name “module-catalog”. Custom Module Structure is same like Magento default module structure.
In custom module three file is required.
1) registration.php
2) etc/module.xml
3) composer.json (required if module want to install using SSH.)

Sample File of all Required Files.

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'CodeWithGeek_Custom',
    __DIR__
);

Module.xml File is register module when deploy a magento. module.xml put in etc folder. “etc” folder located in Custom module root directory. In code is there, it means your module will be executed after tis module.

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="CodeWithGeek_Custom" setup_version="1.0.0"></module>
        <sequence>
            <module name="Magento_Backend"/>
             <module name="Magento_Sales"/>
            <module name="Magento_Quote"/>
            <module name="Magento_Checkout"/>
        </sequence>
</config>

composer.json

{
    "name": "codewithgeek/custom",
    "description": "CodeWithGeek Custom",
    "require": {
      "php": "~5.6.0|7.0.2|~7.0.6",
      "magento/magento-composer-installer": "*"
    },
    "type": "magento2-module",
    "version": "0.74.0-beta4",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "extra": {
        "map": [
            [
                "*",
                "CodeWithGeek/Custom"
            ]
        ]
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *