Create a miniature module in Magento2

We will create a module called Skynet_Office.

The module will have two entities define below:

Deparment:A simple model with following fields:

  • entity_id : primary key
  • name : name of department,string value

2.Employee:an Eav model with following fields and attributes :

Fields:

  • entity_id : primary key.
  • department_id : foreign key,pointing to Department.entity_id
  • email :email of an employee,string value
  • first_name: first name of an employee,string value
  • last_name : last name of employee,string value

Attributes:

  • service_years: employee,s year of service,integer value.
  • dob: date of birth of employee,date-time value.
  • salary: monthly salary,decimal value.
  • vat_number : VAT number,(short) string value.

Every module starts with the registration.php and module.xml files.

Create the app/code/Skynet/Office/registration.php

<?php
/**
 * Module registration File
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Skynet_Office',
    __DIR__
);

The registration.php file is sort of an entry point to our module.

Now create the app/code/Skynet/Office/etc/module.xml file with the below content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Skynet_Office" setup_version="2.0.3">
        <sequence>
            < module name="Magento_Eav"/>
            <module name="Magento_Sales"/>
            <module name="Magento_Catalog"/>
            <module name="Magento_Customer"/>
            <module name="Magento_CatalogInventory"/>

        </sequence>
    </module>
</config>

The value of setup_version is important because we might use 9it with our in schema install script(InstallSchema.php) files,effective turning the install script into update script.

The sequence element element is Magento setting dependencies of our module.


Total Page Visits: 1883 - Today Page Visits: 2

Leave a Reply