SlideShare a Scribd company logo
Develop Magento 2 Custom Shipping Module
Officially Magento 2 is out. Amazing news for all the techies!
Since the release of Magento 2, in the middle of November 2015, it has taken the tech world
by a surprise because of its powerful features. Developers have been keeping busy in
migrating their Magento 1 extension to Magento 2.
Have you done that yet?
Are you aware of the new concepts of Magento 2?
If not, then it will be worthwhile for you to go through our first blog on ‘What-is-new-and-how-
to-migrate-for-magento-2-upgrade’
After you are well aware of the features of Magento 2, I am sure you would want to get some
hands-on experience on the latest bling in technology. Thus, for all my readers I am going to
explain it in easy steps how to develop a ‘Magento 2 Custom Shipping module’ that includes
some basic functionality and also covers most of the developmental aspects.
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
So, read on and learn how to develop Magento 2 custom shipping module in the easiest
manner!
For this, let us begin by building a simple HelloWorld shipping Module. This extension would
have undefined data that shall be stored in the database. On the product page, later the
values will be displayed on it.
If you are looking for more excitement, then we would also create myriad settings for
changing the behavior of the extension.
Excited? Let’s Begin!
1. Configuration Creation
We would begin by installing Magento 2 and then catalog will be created where the extension
files are stored. Please Note, that in Magento 2, files do not get distributed in the folders and
they follow a modular structure.
The catalog containing the newly created files of the extension will be said as:
appcodeShipHawkCustomshipping
Here ‘ShipHawk‘ being the name of the company that has developed the extension and
‘Customshipping‘, the name of the Magento 2 extension that we are developing.
Now let’s begin with coding our extension. The purposes have changed slightly when we
compare with the first version of Magento. As before, Extension configuration is placed in the
folder named “etc”.
Now, we create appcodeShipHawkCustomshippingetc catalog and place module.xml. Here
in this file, we will set the name of the extension and its different version.
The file shall appear like this: ShipHawkCustomshippingetcmodule.xml
<?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="ShipHawk_Customshipping" setup_version="1.0.1">
</module>
</config></pre>
<pre>
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
2. Creation of system.xml file.
appcodeShipHawkCustomshippingetcadminhtmlsystem.xml
All the shipping methods require a ‘config’ option. This enables all the system configuration
fields in the admin. Also, with the help of system.xml file, shipping method options can be
added.
For the creation of new configuration in the admin section following code should be written:
Store -> Settings -> Configuration -> Sales -> Shipping Methods -> Custom Shipping.
Take a glance at the contents of the ‘config’ file:
<?xml version="1.0"?>
<!--
/**
* @category MagePsycho
* @package MagePsycho_Customshipping
* @author magepsycho@gmail.com
* @websit http://www.magepsycho.com
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd">
- <system>
- <section id="carriers" translate="label" type="text" sortOrder="1" showInDefault="1"
showInWebsite="1" showInStore="1">
- <group id="mpcustomshipping" translate="label" type="text" sortOrder="2"
showInDefault="1" showInWebsite="1" showInStore="1">
<label>Custom Shipping</label>
- <field id="version" translate="label" type="label" sortOrder="0" showInDefault="1"
showInWebsite="0" showInStore="0">
<label>Version</label>
<frontend_model>ShipHawkCustomshippingBlockSystemConfigFormFieldVersion</front
end_model>
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
</field>
- <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Enabled</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
- <field id="title" translate="label" type="text" sortOrder="2" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Title</label>
</field>
- <field id="api_key" translate="label" type="text" sortOrder="3" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>API Key</label>
</field>
- <field id="name" translate="label" type="text" sortOrder="4" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Method Name</label>
</field>
- <field id="shipping_price" translate="label" type="text" sortOrder="5" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Price</label>
</field>
- <field id="origin" translate="label" type="text" sortOrder="6" showInDefault="1"
showInWebsite="1" showInStore="0">
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
<label>Default Origin Zipcode</label>
</field>
- <field id="sallowspecific" translate="label" type="select" sortOrder="7" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Ship to Applicable Countries</label>
<frontend_class>shipping-applicable-country</frontend_class>
<source_model>MagentoShippingModelConfigSourceAllspecificcountries</source_model
>
</field>
- <field id="specificcountry" translate="label" type="multiselect" sortOrder="8"
showInDefault="1" showInWebsite="1" showInStore="0">
<label>Ship to Specific Countries</label>
<source_model>MagentoDirectoryModelConfigSourceCountry</source_model>
<can_be_empty>1</can_be_empty>
</field>
- <field id="specificerrmsg" translate="label" type="textarea" sortOrder="9" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Displayed Error Message</label>
</field>
- <field id="showmethod" translate="label" type="select" sortOrder="10" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<frontend_class>shipping-skip-hide</frontend_class>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
</field>
- <field id="sort_order" translate="label" type="text" sortOrder="11" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Sort Order</label>
</field>
</group>
</section>
</system>
</config>
3. Create Module Configuration config.xml:
Create Module Configuration config.xml file under path
appcodeShipHawkCustomshippingetcconfig.xml:
<?xml version="1.0"?>
<!--
/**
* @category MagePsycho
* @package MagePsycho_Customshipping
* @author magepsycho@gmail.com
* @website http://www.magepsycho.com
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd">
- <system>
- <section id="carriers" translate="label" type="text" sortOrder="1" showInDefault="1"
showInWebsite="1" showInStore="1">
- <group id="mpcustomshipping" translate="label" type="text" sortOrder="2"
showInDefault="1" showInWebsite="1" showInStore="1">
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
<label>Custom Shipping</label>
- <field id="version" translate="label" type="label" sortOrder="0" showInDefault="1"
showInWebsite="0" showInStore="0">
<label>Version</label>
<frontend_model>ShipHawkCustomshippingBlockSystemConfigFormFieldVersion</front
end_model>
</field>
- <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Enabled</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
- <field id="title" translate="label" type="text" sortOrder="2" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Title</label>
</field>
- <field id="api_key" translate="label" type="text" sortOrder="3" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>API Key</label>
</field>
- <field id="name" translate="label" type="text" sortOrder="4" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Method Name</label>
</field>
- <field id="shipping_price" translate="label" type="text" sortOrder="5" showInDefault="1"
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
showInWebsite="1" showInStore="1">
<label>Price</label>
</field>
- <field id="origin" translate="label" type="text" sortOrder="6" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Default Origin Zipcode</label>
</field>
- <field id="sallowspecific" translate="label" type="select" sortOrder="7" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Ship to Applicable Countries</label>
<frontend_class>shipping-applicable-country</frontend_class>
<source_model>MagentoShippingModelConfigSourceAllspecificcountries</source_model
>
</field>
- <field id="specificcountry" translate="label" type="multiselect" sortOrder="8"
showInDefault="1" showInWebsite="1" showInStore="0">
<label>Ship to Specific Countries</label>
<source_model>MagentoDirectoryModelConfigSourceCountry</source_model>
<can_be_empty>1</can_be_empty>
</field>
- <field id="specificerrmsg" translate="label" type="textarea" sortOrder="9" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Displayed Error Message</label>
</field>
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
- <field id="showmethod" translate="label" type="select" sortOrder="10" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
<frontend_class>shipping-skip-hide</frontend_class>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
- <field id="sort_order" translate="label" type="text" sortOrder="11" showInDefault="1"
showInWebsite="1" showInStore="0">
<label>Sort Order</label>
</field>
</group>
</section>
</system>
</config>
4. Create a model class for the shipping carrier.
For this, you would require creating a file on the path for instance:
app/code/ShipHawk/Customshipping/Model/Carrier/Custom.php
After the creation of this file, coding is done.
For this, you need to follow some significant Magento 2 rules that are required for the
shipping method. Also, you will be required to properly code the php class.
All shipping class required for Magento 2 must extend as follows:
“MagentoShippingModelCarrierAbstractCarrier”
and then you are required to apply “MagentoShippingModelCarrierCarrierInterface“.
Also, you are required to create two php methods in the shipping model that are
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
“getAllowedMethods” and “collectRates“.
These two methods are required by the abstract and interface class.
Based on a configuration setting done for a shipping method, “collectRates” accepts
parameter “$request” as a class instance
“MagentoQuoteModelQuoteAddressRateRequest”. This calculates and returns the
shipping charges.
5. Model Shipping Carrier:
Finally, add custom shipping class.
<?php
namespace ShipHawkCustomshippingModelCarrier;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoFrameworkDataObject;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use MagentoShippingModelConfig;
use MagentoShippingModelRateResultFactory;
use MagentoStoreModelScopeInterface;
use MagentoQuoteModelQuoteAddressRateResultErrorFactory;
use MagentoQuoteModelQuoteAddressRateResultMethod;
use MagentoQuoteModelQuoteAddressRateResultMethodFactory;
use MagentoQuoteModelQuoteAddressRateRequest;
use PsrLogLoggerInterface;
use MagentoCustomerModelSession;
use MagentoFrameworkAppRequestInterface;
class Customshipping extends AbstractCarrier implements CarrierInterface
{
/**
* Carrier's code
*
* @var string
*/
protected $_code = 'mpcustomshipping';
/**
* Whether this carrier has fixed rates calculation
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
*
* @var bool
*/
protected $_isFixed = true;
/**
* @var ResultFactory
*/
protected $_rateResultFactory;
/**
* @var MethodFactory
*/
protected $_rateMethodFactory;
public $_productRepo;
protected $checkoutSession;
protected $quoteIdMaskFactory;
/**
* @param ScopeConfigInterface $scopeConfig
* @param ErrorFactory $rateErrorFactory
* @param LoggerInterface $logger
* @param ResultFactory $rateResultFactory
* @param MethodFactory $rateMethodFactory
* @param array $data
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
ErrorFactory $rateErrorFactory,
LoggerInterface $logger,
MagentoFrameworkAppHelperContext $context,
MagentoCheckoutModelSession $checkoutSession,
MagentoCustomerModelSession $customerSession,
MagentoFrameworkAppHttpContext $httpContext,
MagentoQuoteModelQuoteIdMaskFactory $quoteIdMaskFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCatalogModelProductRepository $productRepo,
ResultFactory $rateResultFactory,
MethodFactory $rateMethodFactory,
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
array $data = []
) {
$this->_rateResultFactory = $rateResultFactory;
$this->_rateMethodFactory = $rateMethodFactory;
$this->_productRepo = $productRepo;
$this->checkoutSession = $checkoutSession;
$this->customerSession = $customerSession;
$this->_storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data, $context);
}
/**
* Generates list of allowed carrier`s shipping methods
* Displays on cart price rules page
*
* @return array
* @api
*/
public function getAllowedMethods()
{
return [$this->getCarrierCode() => __($this->getConfigData('name'))];
}
/**
* Collect and get rates for storefront
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param RateRequest $request
* @return DataObject|bool|null
* @api
*/
public function collectRates(RateRequest $request)
{
/**
* Make sure that Shipping method is enabled
*/
if (!$this->isActive()) {
return false;
}
/** @var MagentoShippingModelRateResult $result */
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
$result = $this->_rateResultFactory->create();
//$shippingPrice = $customPrice;
$method = $this->_rateMethodFactory->create();
/**
* Set carrier's method data
*/
$method->setCarrier($this->getCarrierCode());
$method->setCarrierTitle($this->getConfigData('title'));
$shippingPrice = $this->getConfigData('shipping_price');
/**
* Displayed as shipping method under Carrier
*/
$method->setMethod($this->getCarrierCode());
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
return $result;
}
}
6. Create Helper class:
Create Helper class to receive the data from configuration:
ShipHawkCustomshippingHelperData.php
namespace ShipHawkCustomshippingHelper;
class Data extends MagentoFrameworkAppHelperAbstractHelper
{
const XML_PATH_ENABLED = 'shiphawk_customshipping/general/enabled';
const XML_PATH_DEBUG = 'shiphawk_customshipping/general/debug';
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
/**
* @var PsrLogLoggerInterface
*/
protected $_logger;
/**
* @var MagentoFrameworkModuleModuleListInterface
*/
protected $_moduleList;
/**
* @param MagentoFrameworkAppHelperContext $context
* @param MagentoFrameworkModuleModuleListInterface $moduleList
*/
public function __construct(
MagentoFrameworkAppHelperContext $context,
MagentoFrameworkModuleModuleListInterface $moduleList
//ShipHawkCustomshippingHelperData $customHelper
) {
$this->_logger = $context->getLogger();
$this->_moduleList = $moduleList;
//$this->_customHelper = $customHelper;
parent::__construct($context);
}
/**
* Check if enabled
*
* @return string|null
*/
public function isEnabled()
{
return $this->scopeConfig->getValue(
self::XML_PATH_ENABLED,
MagentoStoreModelScopeInterface::SCOPE_STORE
);
}
public function getDebugStatus()
{
return $this->scopeConfig->getValue(
self::XML_PATH_DEBUG,
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
MagentoStoreModelScopeInterface::SCOPE_STORE
);
}
public function getExtensionVersion()
{
$moduleCode = 'ShipHawk_Customshipping';
$moduleInfo = $this->_moduleList->getOne($moduleCode);
return $moduleInfo['setup_version'];
}
/**
*
* @param $message
* @param bool|false $useSeparator
*/
public function log($message, $useSeparator = false)
{
if ($this->getDebugStatus()) {
if ($useSeparator) {
$this->_logger->addDebug(str_repeat('=', 100));
}
$this->_logger->addDebug($message);
}
}
}
7. Create Shipping Method Version:
Create a block file Version.php under path
ShipHawkCustomshippingBlockSystemConfigFormFieldVersion.php for shipping method
current version:
<?php
namespace ShipHawkCustomshippingBlockSystemConfigFormField;
use MagentoFrameworkDataFormElementAbstractElement;
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
class Version extends MagentoConfigBlockSystemConfigFormField
{
const EXTENSION_URL = 'http://www.brihaspatitech.com/';
protected $_helper;
public function __construct(
MagentoBackendBlockTemplateContext $context,
ShipHawkCustomshippingHelperData $helper
) {
$this->_helper = $helper;
parent::__construct($context);
}
protected function _getElementHtml(AbstractElement $element)
{
$extensionVersion = $this->_helper->getExtensionVersion();
$extensionTitle = 'Custom Shipping';
$versionLabel = sprintf(
'<a href="%s" title="%s" target="_blank">%s</a>',
self::EXTENSION_URL,
$extensionTitle,
$extensionVersion
);
$element->setValue($versionLabel);
return $element->getValue();
}
}
Wooohh! You are DONE!
Now, you are only required to enable the module by running certain commands that are
mentioned below:
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
1. php bin/magento module:enable ShipHawk_Customshipping–clear-static-content
2. php bin/magento setup:upgrade
On the Backend:
Go to System > Configuration > Sales > Shipping Methods > we can see new tab ‘Custom
Shipping’ and its settings as shown below:
Front-End Layout :
Checkout Cart 1:
appcodeShipHawkCustomshippingviewfrontendlayoutcheckout_cart_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configura
tion.xsd">
<body>
<referenceBlock name="checkout.cart.shipping">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="summary-block-config" xsi:type="array">
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
<item name="children" xsi:type="array">
<item name="shipping-rates-validation" xsi:type="array">
<item name="children" xsi:type="array">
<item name="mpcustomshipping-rates-validation" xsi:type="array">
<item name="component" xsi:type="string">ShipHawk_Customshipping/js/view/shipping-
rates-validation</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Checkout Cart Index 2:
appcodeShipHawkCustomshippingviewfrontendlayoutcheckout_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configura
tion.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="step-config" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-rates-validation" xsi:type="array">
<item name="children" xsi:type="array">
<item name="mpcustomshipping-rates-validation" xsi:type="array">
<item name="component" xsi:type="string">ShipHawk_Customshipping/js/view/shipping-
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/
rates-validation</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Thus, successfully a very simple Magento 2 extension is created. If you follow all the steps in
order, you will be able to do it without any hassles.
If you still have any doubts or you stuck up somewhere, please feel free to ask them in the
comments section below. We would help you in the best possible way.
For more information you may reach us or email at contact@brihaspatitech.com.
Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali
contact@brihaspatitech.com http://www.brihaspatitech.com/

More Related Content

What's hot

How to Build a Yahoo! SearchMonkey App
How to Build a Yahoo! SearchMonkey AppHow to Build a Yahoo! SearchMonkey App
How to Build a Yahoo! SearchMonkey App
post.chris
 
Magento 2 theming - knowledge sharing session by suman kc
Magento 2 theming - knowledge sharing session by suman kcMagento 2 theming - knowledge sharing session by suman kc
Magento 2 theming - knowledge sharing session by suman kc
Suman KC
 
Hog user manual v3
Hog user manual v3Hog user manual v3
Hog user manual v3
Simone Stanich
 
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Meet Magento Italy
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentals
Amit Sharma
 
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Meet Magento Italy
 
IBM Notes 9 Social Edition Cheat Sheet
IBM Notes 9 Social Edition Cheat SheetIBM Notes 9 Social Edition Cheat Sheet
IBM Notes 9 Social Edition Cheat Sheet
Maarga Systems
 
Magento 2 Language Translator Extension
Magento 2 Language Translator ExtensionMagento 2 Language Translator Extension
Magento 2 Language Translator Extension
AppJetty
 
How to Install Magento 2 [Latest Version]
How to Install Magento 2 [Latest Version]How to Install Magento 2 [Latest Version]
How to Install Magento 2 [Latest Version]
M-Connect Media
 
hw4_specifications
hw4_specificationshw4_specifications
hw4_specifications
tutorialsruby
 
Ace shop quick_guide
Ace shop quick_guideAce shop quick_guide
Ace shop quick_guide
Andy Burrows
 
Write an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxWrite an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptx
vishal choudhary
 
Facebook Platform
Facebook PlatformFacebook Platform
Facebook Platform
David Nattriss
 
Android Programming.pptx
Android Programming.pptxAndroid Programming.pptx
Android Programming.pptx
vishal choudhary
 
Sales force certification-lab
Sales force certification-labSales force certification-lab
Sales force certification-lab
Amit Sharma
 
Murach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVCMurach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVC
MahmoudOHassouna
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
vishal choudhary
 
Creating messages
Creating messagesCreating messages
Creating messages
Kranthi Kumar
 
Customizing sales force-interface
Customizing sales force-interfaceCustomizing sales force-interface
Customizing sales force-interface
Amit Sharma
 
Rich faces
Rich facesRich faces
Rich faces
BG Java EE Course
 

What's hot (20)

How to Build a Yahoo! SearchMonkey App
How to Build a Yahoo! SearchMonkey AppHow to Build a Yahoo! SearchMonkey App
How to Build a Yahoo! SearchMonkey App
 
Magento 2 theming - knowledge sharing session by suman kc
Magento 2 theming - knowledge sharing session by suman kcMagento 2 theming - knowledge sharing session by suman kc
Magento 2 theming - knowledge sharing session by suman kc
 
Hog user manual v3
Hog user manual v3Hog user manual v3
Hog user manual v3
 
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
 
Apex code-fundamentals
Apex code-fundamentalsApex code-fundamentals
Apex code-fundamentals
 
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
 
IBM Notes 9 Social Edition Cheat Sheet
IBM Notes 9 Social Edition Cheat SheetIBM Notes 9 Social Edition Cheat Sheet
IBM Notes 9 Social Edition Cheat Sheet
 
Magento 2 Language Translator Extension
Magento 2 Language Translator ExtensionMagento 2 Language Translator Extension
Magento 2 Language Translator Extension
 
How to Install Magento 2 [Latest Version]
How to Install Magento 2 [Latest Version]How to Install Magento 2 [Latest Version]
How to Install Magento 2 [Latest Version]
 
hw4_specifications
hw4_specificationshw4_specifications
hw4_specifications
 
Ace shop quick_guide
Ace shop quick_guideAce shop quick_guide
Ace shop quick_guide
 
Write an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxWrite an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptx
 
Facebook Platform
Facebook PlatformFacebook Platform
Facebook Platform
 
Android Programming.pptx
Android Programming.pptxAndroid Programming.pptx
Android Programming.pptx
 
Sales force certification-lab
Sales force certification-labSales force certification-lab
Sales force certification-lab
 
Murach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVCMurach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVC
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
 
Creating messages
Creating messagesCreating messages
Creating messages
 
Customizing sales force-interface
Customizing sales force-interfaceCustomizing sales force-interface
Customizing sales force-interface
 
Rich faces
Rich facesRich faces
Rich faces
 

Viewers also liked

ProSET Brochure
ProSET BrochureProSET Brochure
ProSET Brochure
Simon Burwood
 
Capturas, App Educativa De Las Planeaciones.
Capturas, App Educativa De Las Planeaciones. Capturas, App Educativa De Las Planeaciones.
Capturas, App Educativa De Las Planeaciones.
Yessica Garcia
 
Snapsis
SnapsisSnapsis
Snapsis
Luis Apablaza
 
Innovation Blueprints Magazine issue #102
Innovation Blueprints Magazine issue #102Innovation Blueprints Magazine issue #102
Innovation Blueprints Magazine issue #102
Nils vesk
 
referencia absoluta relativa_mixta_
 referencia absoluta relativa_mixta_ referencia absoluta relativa_mixta_
referencia absoluta relativa_mixta_
Diego bejarano
 
O poder de delegar wilas queiroz de carvalho
O poder de delegar wilas queiroz de carvalhoO poder de delegar wilas queiroz de carvalho
O poder de delegar wilas queiroz de carvalho
Jp Prof
 
The Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth Payne
The Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth PayneThe Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth Payne
The Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth Payne
Leith Greenslade
 
Las apps
Las appsLas apps
Las apps
David OG
 
CV Bontu
CV BontuCV Bontu
CV Bontu
Bontu Elmo
 
Autor delia y daniel
Autor delia y danielAutor delia y daniel
Autor delia y daniel
sacra_bachoco
 
Trabalho fábula 2012 guilherme
Trabalho fábula 2012   guilhermeTrabalho fábula 2012   guilherme
Trabalho fábula 2012 guilherme
Maria Rita Toffoli de Almeida
 

Viewers also liked (11)

ProSET Brochure
ProSET BrochureProSET Brochure
ProSET Brochure
 
Capturas, App Educativa De Las Planeaciones.
Capturas, App Educativa De Las Planeaciones. Capturas, App Educativa De Las Planeaciones.
Capturas, App Educativa De Las Planeaciones.
 
Snapsis
SnapsisSnapsis
Snapsis
 
Innovation Blueprints Magazine issue #102
Innovation Blueprints Magazine issue #102Innovation Blueprints Magazine issue #102
Innovation Blueprints Magazine issue #102
 
referencia absoluta relativa_mixta_
 referencia absoluta relativa_mixta_ referencia absoluta relativa_mixta_
referencia absoluta relativa_mixta_
 
O poder de delegar wilas queiroz de carvalho
O poder de delegar wilas queiroz de carvalhoO poder de delegar wilas queiroz de carvalho
O poder de delegar wilas queiroz de carvalho
 
The Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth Payne
The Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth PayneThe Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth Payne
The Power of Pulse Oximetry to Identify Risk of Pre-Eclampsia: Beth Payne
 
Las apps
Las appsLas apps
Las apps
 
CV Bontu
CV BontuCV Bontu
CV Bontu
 
Autor delia y daniel
Autor delia y danielAutor delia y daniel
Autor delia y daniel
 
Trabalho fábula 2012 guilherme
Trabalho fábula 2012   guilhermeTrabalho fábula 2012   guilherme
Trabalho fábula 2012 guilherme
 

Similar to Develop magento 2 custom shipping module

How to-create-a-simple-module-in-magento-2.0
How to-create-a-simple-module-in-magento-2.0How to-create-a-simple-module-in-magento-2.0
How to-create-a-simple-module-in-magento-2.0
Daniele Crupi
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
Trọng Huỳnh
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
Mage Guru
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
Ravi Mehrotra
 
Mangento
MangentoMangento
Mangento
Ravi Mehrotra
 
Magento++
Magento++Magento++
Creating Yahoo Mobile Widgets
Creating Yahoo Mobile WidgetsCreating Yahoo Mobile Widgets
Creating Yahoo Mobile Widgets
Ricardo Varela
 
manifest file on SCORM 1.2
manifest file on SCORM 1.2manifest file on SCORM 1.2
manifest file on SCORM 1.2
aureliomld
 
Web Slices
Web SlicesWeb Slices
Web Slices
klcintw
 
Xxx
XxxXxx
Xxx
syfwan
 
Magento 2 Layered Navigation Extension by ITORIS INC
Magento 2 Layered Navigation Extension by ITORIS INCMagento 2 Layered Navigation Extension by ITORIS INC
Magento 2 Layered Navigation Extension by ITORIS INC
Itexus LLC
 
Ibm
IbmIbm
Ibm
techbed
 
Spring Surf 101
Spring Surf 101Spring Surf 101
Spring Surf 101
Alfresco Software
 
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULESBEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
Kuldeep Sharma
 
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Joke Puts
 
How to create multi language store in magento 2
How to create multi language store in magento 2How to create multi language store in magento 2
How to create multi language store in magento 2
AppJetty
 
How to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionHow to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtension
LitExtension
 
Tsvetan stoychev m_mspeakers-edited-final
Tsvetan stoychev m_mspeakers-edited-finalTsvetan stoychev m_mspeakers-edited-final
Tsvetan stoychev m_mspeakers-edited-final
ceckoslab
 
Magento 20110406
Magento   20110406Magento   20110406
Magento 20110406
AiTi Education
 
Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?
Mage Titans ES
 

Similar to Develop magento 2 custom shipping module (20)

How to-create-a-simple-module-in-magento-2.0
How to-create-a-simple-module-in-magento-2.0How to-create-a-simple-module-in-magento-2.0
How to-create-a-simple-module-in-magento-2.0
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
 
Mangento
MangentoMangento
Mangento
 
Magento++
Magento++Magento++
Magento++
 
Creating Yahoo Mobile Widgets
Creating Yahoo Mobile WidgetsCreating Yahoo Mobile Widgets
Creating Yahoo Mobile Widgets
 
manifest file on SCORM 1.2
manifest file on SCORM 1.2manifest file on SCORM 1.2
manifest file on SCORM 1.2
 
Web Slices
Web SlicesWeb Slices
Web Slices
 
Xxx
XxxXxx
Xxx
 
Magento 2 Layered Navigation Extension by ITORIS INC
Magento 2 Layered Navigation Extension by ITORIS INCMagento 2 Layered Navigation Extension by ITORIS INC
Magento 2 Layered Navigation Extension by ITORIS INC
 
Ibm
IbmIbm
Ibm
 
Spring Surf 101
Spring Surf 101Spring Surf 101
Spring Surf 101
 
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULESBEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
 
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
 
How to create multi language store in magento 2
How to create multi language store in magento 2How to create multi language store in magento 2
How to create multi language store in magento 2
 
How to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionHow to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtension
 
Tsvetan stoychev m_mspeakers-edited-final
Tsvetan stoychev m_mspeakers-edited-finalTsvetan stoychev m_mspeakers-edited-final
Tsvetan stoychev m_mspeakers-edited-final
 
Magento 20110406
Magento   20110406Magento   20110406
Magento 20110406
 
Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?
 

Recently uploaded

办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
thezot
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
Paul Walk
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
APNIC
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
APNIC
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
rtunex8r
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
Donato Onofri
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
3a0sd7z3
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
k4ncd0z
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
Tarandeep Singh
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
3a0sd7z3
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 

Recently uploaded (12)

办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 

Develop magento 2 custom shipping module

  • 1. Develop Magento 2 Custom Shipping Module Officially Magento 2 is out. Amazing news for all the techies! Since the release of Magento 2, in the middle of November 2015, it has taken the tech world by a surprise because of its powerful features. Developers have been keeping busy in migrating their Magento 1 extension to Magento 2. Have you done that yet? Are you aware of the new concepts of Magento 2? If not, then it will be worthwhile for you to go through our first blog on ‘What-is-new-and-how- to-migrate-for-magento-2-upgrade’ After you are well aware of the features of Magento 2, I am sure you would want to get some hands-on experience on the latest bling in technology. Thus, for all my readers I am going to explain it in easy steps how to develop a ‘Magento 2 Custom Shipping module’ that includes some basic functionality and also covers most of the developmental aspects. Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 2. So, read on and learn how to develop Magento 2 custom shipping module in the easiest manner! For this, let us begin by building a simple HelloWorld shipping Module. This extension would have undefined data that shall be stored in the database. On the product page, later the values will be displayed on it. If you are looking for more excitement, then we would also create myriad settings for changing the behavior of the extension. Excited? Let’s Begin! 1. Configuration Creation We would begin by installing Magento 2 and then catalog will be created where the extension files are stored. Please Note, that in Magento 2, files do not get distributed in the folders and they follow a modular structure. The catalog containing the newly created files of the extension will be said as: appcodeShipHawkCustomshipping Here ‘ShipHawk‘ being the name of the company that has developed the extension and ‘Customshipping‘, the name of the Magento 2 extension that we are developing. Now let’s begin with coding our extension. The purposes have changed slightly when we compare with the first version of Magento. As before, Extension configuration is placed in the folder named “etc”. Now, we create appcodeShipHawkCustomshippingetc catalog and place module.xml. Here in this file, we will set the name of the extension and its different version. The file shall appear like this: ShipHawkCustomshippingetcmodule.xml <?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="ShipHawk_Customshipping" setup_version="1.0.1"> </module> </config></pre> <pre> Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 3. 2. Creation of system.xml file. appcodeShipHawkCustomshippingetcadminhtmlsystem.xml All the shipping methods require a ‘config’ option. This enables all the system configuration fields in the admin. Also, with the help of system.xml file, shipping method options can be added. For the creation of new configuration in the admin section following code should be written: Store -> Settings -> Configuration -> Sales -> Shipping Methods -> Custom Shipping. Take a glance at the contents of the ‘config’ file: <?xml version="1.0"?> <!-- /** * @category MagePsycho * @package MagePsycho_Customshipping * @author magepsycho@gmail.com * @websit http://www.magepsycho.com * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd"> - <system> - <section id="carriers" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> - <group id="mpcustomshipping" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Custom Shipping</label> - <field id="version" translate="label" type="label" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0"> <label>Version</label> <frontend_model>ShipHawkCustomshippingBlockSystemConfigFormFieldVersion</front end_model> Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 4. </field> - <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Enabled</label> <source_model>MagentoConfigModelConfigSourceYesno</source_model> </field> - <field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Title</label> </field> - <field id="api_key" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1"> <label>API Key</label> </field> - <field id="name" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Method Name</label> </field> - <field id="shipping_price" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Price</label> </field> - <field id="origin" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="0"> Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 5. <label>Default Origin Zipcode</label> </field> - <field id="sallowspecific" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Ship to Applicable Countries</label> <frontend_class>shipping-applicable-country</frontend_class> <source_model>MagentoShippingModelConfigSourceAllspecificcountries</source_model > </field> - <field id="specificcountry" translate="label" type="multiselect" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Ship to Specific Countries</label> <source_model>MagentoDirectoryModelConfigSourceCountry</source_model> <can_be_empty>1</can_be_empty> </field> - <field id="specificerrmsg" translate="label" type="textarea" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Displayed Error Message</label> </field> - <field id="showmethod" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Show Method if Not Applicable</label> <frontend_class>shipping-skip-hide</frontend_class> <source_model>MagentoConfigModelConfigSourceYesno</source_model> Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 6. </field> - <field id="sort_order" translate="label" type="text" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Sort Order</label> </field> </group> </section> </system> </config> 3. Create Module Configuration config.xml: Create Module Configuration config.xml file under path appcodeShipHawkCustomshippingetcconfig.xml: <?xml version="1.0"?> <!-- /** * @category MagePsycho * @package MagePsycho_Customshipping * @author magepsycho@gmail.com * @website http://www.magepsycho.com * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd"> - <system> - <section id="carriers" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> - <group id="mpcustomshipping" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1"> Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 7. <label>Custom Shipping</label> - <field id="version" translate="label" type="label" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0"> <label>Version</label> <frontend_model>ShipHawkCustomshippingBlockSystemConfigFormFieldVersion</front end_model> </field> - <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Enabled</label> <source_model>MagentoConfigModelConfigSourceYesno</source_model> </field> - <field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Title</label> </field> - <field id="api_key" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1"> <label>API Key</label> </field> - <field id="name" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Method Name</label> </field> - <field id="shipping_price" translate="label" type="text" sortOrder="5" showInDefault="1" Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 8. showInWebsite="1" showInStore="1"> <label>Price</label> </field> - <field id="origin" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Default Origin Zipcode</label> </field> - <field id="sallowspecific" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Ship to Applicable Countries</label> <frontend_class>shipping-applicable-country</frontend_class> <source_model>MagentoShippingModelConfigSourceAllspecificcountries</source_model > </field> - <field id="specificcountry" translate="label" type="multiselect" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Ship to Specific Countries</label> <source_model>MagentoDirectoryModelConfigSourceCountry</source_model> <can_be_empty>1</can_be_empty> </field> - <field id="specificerrmsg" translate="label" type="textarea" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Displayed Error Message</label> </field> Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 9. - <field id="showmethod" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Show Method if Not Applicable</label> <frontend_class>shipping-skip-hide</frontend_class> <source_model>MagentoConfigModelConfigSourceYesno</source_model> </field> - <field id="sort_order" translate="label" type="text" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Sort Order</label> </field> </group> </section> </system> </config> 4. Create a model class for the shipping carrier. For this, you would require creating a file on the path for instance: app/code/ShipHawk/Customshipping/Model/Carrier/Custom.php After the creation of this file, coding is done. For this, you need to follow some significant Magento 2 rules that are required for the shipping method. Also, you will be required to properly code the php class. All shipping class required for Magento 2 must extend as follows: “MagentoShippingModelCarrierAbstractCarrier” and then you are required to apply “MagentoShippingModelCarrierCarrierInterface“. Also, you are required to create two php methods in the shipping model that are Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 10. “getAllowedMethods” and “collectRates“. These two methods are required by the abstract and interface class. Based on a configuration setting done for a shipping method, “collectRates” accepts parameter “$request” as a class instance “MagentoQuoteModelQuoteAddressRateRequest”. This calculates and returns the shipping charges. 5. Model Shipping Carrier: Finally, add custom shipping class. <?php namespace ShipHawkCustomshippingModelCarrier; use MagentoFrameworkAppConfigScopeConfigInterface; use MagentoFrameworkDataObject; use MagentoShippingModelCarrierAbstractCarrier; use MagentoShippingModelCarrierCarrierInterface; use MagentoShippingModelConfig; use MagentoShippingModelRateResultFactory; use MagentoStoreModelScopeInterface; use MagentoQuoteModelQuoteAddressRateResultErrorFactory; use MagentoQuoteModelQuoteAddressRateResultMethod; use MagentoQuoteModelQuoteAddressRateResultMethodFactory; use MagentoQuoteModelQuoteAddressRateRequest; use PsrLogLoggerInterface; use MagentoCustomerModelSession; use MagentoFrameworkAppRequestInterface; class Customshipping extends AbstractCarrier implements CarrierInterface { /** * Carrier's code * * @var string */ protected $_code = 'mpcustomshipping'; /** * Whether this carrier has fixed rates calculation Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 11. * * @var bool */ protected $_isFixed = true; /** * @var ResultFactory */ protected $_rateResultFactory; /** * @var MethodFactory */ protected $_rateMethodFactory; public $_productRepo; protected $checkoutSession; protected $quoteIdMaskFactory; /** * @param ScopeConfigInterface $scopeConfig * @param ErrorFactory $rateErrorFactory * @param LoggerInterface $logger * @param ResultFactory $rateResultFactory * @param MethodFactory $rateMethodFactory * @param array $data */ public function __construct( ScopeConfigInterface $scopeConfig, ErrorFactory $rateErrorFactory, LoggerInterface $logger, MagentoFrameworkAppHelperContext $context, MagentoCheckoutModelSession $checkoutSession, MagentoCustomerModelSession $customerSession, MagentoFrameworkAppHttpContext $httpContext, MagentoQuoteModelQuoteIdMaskFactory $quoteIdMaskFactory, MagentoStoreModelStoreManagerInterface $storeManager, MagentoCatalogModelProductRepository $productRepo, ResultFactory $rateResultFactory, MethodFactory $rateMethodFactory, Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 12. array $data = [] ) { $this->_rateResultFactory = $rateResultFactory; $this->_rateMethodFactory = $rateMethodFactory; $this->_productRepo = $productRepo; $this->checkoutSession = $checkoutSession; $this->customerSession = $customerSession; $this->_storeManager = $storeManager; $this->scopeConfig = $scopeConfig; $this->quoteIdMaskFactory = $quoteIdMaskFactory; parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data, $context); } /** * Generates list of allowed carrier`s shipping methods * Displays on cart price rules page * * @return array * @api */ public function getAllowedMethods() { return [$this->getCarrierCode() => __($this->getConfigData('name'))]; } /** * Collect and get rates for storefront * * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param RateRequest $request * @return DataObject|bool|null * @api */ public function collectRates(RateRequest $request) { /** * Make sure that Shipping method is enabled */ if (!$this->isActive()) { return false; } /** @var MagentoShippingModelRateResult $result */ Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 13. $result = $this->_rateResultFactory->create(); //$shippingPrice = $customPrice; $method = $this->_rateMethodFactory->create(); /** * Set carrier's method data */ $method->setCarrier($this->getCarrierCode()); $method->setCarrierTitle($this->getConfigData('title')); $shippingPrice = $this->getConfigData('shipping_price'); /** * Displayed as shipping method under Carrier */ $method->setMethod($this->getCarrierCode()); $method->setMethodTitle($this->getConfigData('name')); $method->setPrice($shippingPrice); $method->setCost($shippingPrice); $result->append($method); return $result; } } 6. Create Helper class: Create Helper class to receive the data from configuration: ShipHawkCustomshippingHelperData.php namespace ShipHawkCustomshippingHelper; class Data extends MagentoFrameworkAppHelperAbstractHelper { const XML_PATH_ENABLED = 'shiphawk_customshipping/general/enabled'; const XML_PATH_DEBUG = 'shiphawk_customshipping/general/debug'; Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 14. /** * @var PsrLogLoggerInterface */ protected $_logger; /** * @var MagentoFrameworkModuleModuleListInterface */ protected $_moduleList; /** * @param MagentoFrameworkAppHelperContext $context * @param MagentoFrameworkModuleModuleListInterface $moduleList */ public function __construct( MagentoFrameworkAppHelperContext $context, MagentoFrameworkModuleModuleListInterface $moduleList //ShipHawkCustomshippingHelperData $customHelper ) { $this->_logger = $context->getLogger(); $this->_moduleList = $moduleList; //$this->_customHelper = $customHelper; parent::__construct($context); } /** * Check if enabled * * @return string|null */ public function isEnabled() { return $this->scopeConfig->getValue( self::XML_PATH_ENABLED, MagentoStoreModelScopeInterface::SCOPE_STORE ); } public function getDebugStatus() { return $this->scopeConfig->getValue( self::XML_PATH_DEBUG, Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 15. MagentoStoreModelScopeInterface::SCOPE_STORE ); } public function getExtensionVersion() { $moduleCode = 'ShipHawk_Customshipping'; $moduleInfo = $this->_moduleList->getOne($moduleCode); return $moduleInfo['setup_version']; } /** * * @param $message * @param bool|false $useSeparator */ public function log($message, $useSeparator = false) { if ($this->getDebugStatus()) { if ($useSeparator) { $this->_logger->addDebug(str_repeat('=', 100)); } $this->_logger->addDebug($message); } } } 7. Create Shipping Method Version: Create a block file Version.php under path ShipHawkCustomshippingBlockSystemConfigFormFieldVersion.php for shipping method current version: <?php namespace ShipHawkCustomshippingBlockSystemConfigFormField; use MagentoFrameworkDataFormElementAbstractElement; Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 16. class Version extends MagentoConfigBlockSystemConfigFormField { const EXTENSION_URL = 'http://www.brihaspatitech.com/'; protected $_helper; public function __construct( MagentoBackendBlockTemplateContext $context, ShipHawkCustomshippingHelperData $helper ) { $this->_helper = $helper; parent::__construct($context); } protected function _getElementHtml(AbstractElement $element) { $extensionVersion = $this->_helper->getExtensionVersion(); $extensionTitle = 'Custom Shipping'; $versionLabel = sprintf( '<a href="%s" title="%s" target="_blank">%s</a>', self::EXTENSION_URL, $extensionTitle, $extensionVersion ); $element->setValue($versionLabel); return $element->getValue(); } } Wooohh! You are DONE! Now, you are only required to enable the module by running certain commands that are mentioned below: Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 17. 1. php bin/magento module:enable ShipHawk_Customshipping–clear-static-content 2. php bin/magento setup:upgrade On the Backend: Go to System > Configuration > Sales > Shipping Methods > we can see new tab ‘Custom Shipping’ and its settings as shown below: Front-End Layout : Checkout Cart 1: appcodeShipHawkCustomshippingviewfrontendlayoutcheckout_cart_index.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configura tion.xsd"> <body> <referenceBlock name="checkout.cart.shipping"> <arguments> <argument name="jsLayout" xsi:type="array"> <item name="components" xsi:type="array"> <item name="summary-block-config" xsi:type="array"> Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 18. <item name="children" xsi:type="array"> <item name="shipping-rates-validation" xsi:type="array"> <item name="children" xsi:type="array"> <item name="mpcustomshipping-rates-validation" xsi:type="array"> <item name="component" xsi:type="string">ShipHawk_Customshipping/js/view/shipping- rates-validation</item> </item> </item> </item> </item> </item> </item> </argument> </arguments> </referenceBlock> </body> </page> Checkout Cart Index 2: appcodeShipHawkCustomshippingviewfrontendlayoutcheckout_index_index.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configura tion.xsd"> <body> <referenceBlock name="checkout.root"> <arguments> <argument name="jsLayout" xsi:type="array"> <item name="components" xsi:type="array"> <item name="checkout" xsi:type="array"> <item name="children" xsi:type="array"> <item name="steps" xsi:type="array"> <item name="children" xsi:type="array"> <item name="shipping-step" xsi:type="array"> <item name="children" xsi:type="array"> <item name="step-config" xsi:type="array"> <item name="children" xsi:type="array"> <item name="shipping-rates-validation" xsi:type="array"> <item name="children" xsi:type="array"> <item name="mpcustomshipping-rates-validation" xsi:type="array"> <item name="component" xsi:type="string">ShipHawk_Customshipping/js/view/shipping- Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/
  • 19. rates-validation</item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </argument> </arguments> </referenceBlock> </body> </page> Thus, successfully a very simple Magento 2 extension is created. If you follow all the steps in order, you will be able to do it without any hassles. If you still have any doubts or you stuck up somewhere, please feel free to ask them in the comments section below. We would help you in the best possible way. For more information you may reach us or email at contact@brihaspatitech.com. Contact us at: The Brihaspati Infotech Pvt. Ltd. Mohali contact@brihaspatitech.com http://www.brihaspatitech.com/