Creating a Shipping Module for Magento 2

Creating a Shipping Module for Magento 2

In this new article I’m going to show you how to create a custom shipping module for Magento 2 platform. Here below you can see the structure of the module:

Creating a Shipping Module for Magento 2

1. At first let’s register our module in the system. In order to get that done we should create the following files:

app/code/BelVG/NewShipping/etc/module.xml

and app/code/BelVG/NewShipping/registration.php

2. We should provide an ability for users to configure the new shipping method. That’s why we must create new fields in admin panel (Stores->Configuration->Sales->Shipping Methods). And that is what will help us:

app/code/BelVG/NewShipping/etc/adminhtml/system.php

3. Here we create configuration file of our new module:

app/code/BelVG/NewShipping/etc/config.php

4. The next step is creating a model of shipping method, where we can describe the logical circuitry of app/code/BelVG/NewShipping/Model/Carrier/Shipping.php. And here it is necessary to implement these two methods: collectRates and getAllowedMethods.

Whereafter we should enable the module by running the following commands:

php bin/magento module:enable -c BelVG_NewShipping

php bin/magento setup:upgrade

And here in admin panel we are able to configure the shipping method:

Stores-> Configuration-> Sales-> Shipping Methods

Creating a Shipping Module for Magento 2

And what concerns the frontend, during the order placement process a user can simply select our new shipping method.

Creating a Shipping Module for Magento 2

Creating a Shipping Module for Magento 2



Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *