Discover how to configure Magento shipping, how to set up free shipping in Magento and how to manage Magento shipment programmatically.
Is shipping an important aspect of an ecommerce business? Online shopping is many-faceted, and in order to provide customers with the excellent shopping experience, an ecommerce owner should take care of a great many aspects: product images and descriptions, marketing, order management, inventory and warehouses, store design and interface, etc. Shipping is among these crucial aspects; in fact, just as it is impossible to make a first impression twice, you will be unable to regain your reputation after a badly organized or even failed shipping experience.
The level and quality of shipping organization depend, to a great extent, on an ecommerce platform itself. With Magento, one can perform both simple and sophisticated shipping configurations via admin panel and programmatically.
Read on and learn what shipping providers is Magento natively integrated and how to set up Magento shipping rates and free shipping in the back office. Apart from this, you will find out how to configure Magento shipment programmatically
Table of contents:
How to perform Magento shipping settings
How to configure Magento shipping table rates
How to сustomize the list of shipping methods in Magento 2
How to configure free shipping in Magento 2
Magento 2 create shipment programmatically
How to create shipment with tracking information in Magento 2
How to create partial shipment programmatically in Magento 2
How to create Magento 2 shipment via API
Magento international shipping integrations
According to recent research, over 90% of customers mark that the variety of shipping options are vital for a satisfactory shopping experience. Therefore, to be able to attract new customers as well as retail the loyal ones today, a store should provide global shipping and enough shipping options for a customer to choose from.
There is a number of established shipping companies, like DHL, UPS, DPD, Hermes and so on, that cater for international delivery. The majority of online businesses tend to rely on them for good-quality global shipping. However, the process of integrating the shipping solution of your choice into an ecommerce platform can be lengthy and complicated, which can discourage small businesses from shipping their goods internationally.
International shipping is not an issue with Magento. By default, Magento is connected to the major shipping providers, which greatly simplified the organization of shipping workflow.
Magento DHL shipping
DHL (Dalsey, Hillblom and Lynn) International GmbH is an international courier company. Founded 50 years ago in the USA, it used to provide solely offshore delivery, but the popularity of FedEx encouraged it to engage in domestic delivery as well. DHL is the top Magento delivery partner, available in both Open Source and Commerce versions of the platform. Apart from this, DHL offers three native extensions that allow to expand the default functionality.
FedEx Magento shipping
FedEx, abbreviated from Federal Express, is a multinational courier company from Tennessee, US. FedEx provides ground, air and freight delivery all over the world. The company pioneered a package tracking system and location updates and is known for the fast delivery terms.
Magento UPS shipping
UPS (United Parcel Service) is a multinational package delivery company from Seattle, US. Founded back in 1911, it used to be a domestic delivery service, but with the development of transportation technologies, it entered the market of international delivery. UPS has 100.000+ delivery vehicles worldwide, with delivery vans, tractor trailers, bicycles, trains and airships among them. UPS is integrated into Magento as a default delivery method, but in case you need to expand the in-built functionalities, you can always find a selection of UPS extensions at the official Magento marketplace.
Magento USPS shipping
USPS, or United States Postal Service, is an independent branch of the US postal service, formed in 1971. USPS offers both domestic and international delivery by land and air and is famous for flat rate shipping for smaller size and lightweight items. Currently, it employs over 600.000 staff members and delivers 47% of all the mail worldwide. USPS is natively integrated into Magento ecommerce platform, which allows the retailer to launch US-wide and international delivery in no time.
As you can see, Magento natively integrates the core global shipping providers. In addition to this, Magento’s flexible open source architecture allows to carry out integrations with other third-party shipping providers, like Australia Post, UK Mail and so on. Therefore, when you choose Magento, there is no need to limit your business to the default options.
Magento Integration
Take your online store to the new level with Magento integration service
Visit the pageHow to perform Magento shipping settings
The first step in back office Magento shipping configuration is to set up the point of origin, which stands for the business or warehouse location from which the shipment is made.
Step #1: navigate to Stores -> Settings -> Configurations in Magento admin panel.
Step #2: expand the Sales tab on the left and select Shipping Settings.
Step #3: enter the info about your point of origin into the Origin section.
Another Magento shipping configuration that is better to perform beforehand is establishing Shipping Policy Parameters. There, a store owner can identify his company shipment rules and guidelines, and this policy will be displayed during the checkout to every customer.
Step #1: expand the Shipping Policy Parameters section, located below the Origin.
Step #2: set up the Apply custom Shipping Policy at Yes.
Step #3: paste your shipping policy into the appeared field.
Step #4: press Save Config in the upper right corner.
Having completed these basic settings, a store admin can proceed with configuring shipping in Magento 2 further.
How to configure Magento shipping table rates
In Magento, shipping rates are calculated from the combination of the following conditions:
- Price v. Destination
- Weight v. Destination
- Number of items v. Destination
For each Magento store, a table with the rates should be prepared in CSV format and imported into the back office.
Step #0: make the shipping rates table.
For the demonstration’s sake, I will demonstrate what columns should shipping rates table for Weight vs. Destination consist of.
When done, save the document as tablerates.csv.
Step #1: go to Stores -> Settings -> Configuration.
Step #2: expand the Sales tab and select Shipping Methods.
Step #3: expand the Table Rates section and configure the following fields:
- Enabled at Yes
- Title – the name of the table rates section
- Method Name – the title that will be displayed to a customer at the checkout
- Condition – select one of the three alternatives
- Include Virtual Products in Price Calculation – set at Yes to include, No to exclude
- Calculate Handling Fee – if your store charges handling fee, select how it will be charged – Fixed or Percentage
- Displayed Error Message – enter the text displayed in case of an error
- Ship to Applicable Countries – either All Allowed or Specific Countries
- Sort Order – determine the position of the table rates at the checkout
Step #4: press Save Config button.
Step #5: select Main Website store view in the upper left corner.
Step #6: press the newly appeared Export CSV button to import the shipping rates spreadsheet created beforehand.
Step #7: press Save Config button.
Repeat this course of action to set up two remaining shipping rate tables.
Magento 2 Extensions
Take your online store to the next level with BelVG Magento extensions
Visit the storeHow to сustomize the list of shipping methods in Magento 2
There is no in-built functionality for customizing the list of shipping methods in Magento back office. Instead, these configurations can be performed programmatically by a skilled frontend developer. Below, you will find three-step instructions on how to customize a shopping methods list programmatically.
Step #1: create a template for the shipping method item.
Create the following file:
<root_dir>app/code/BelVG/Shipping/view/frontend/web/template/custom-method-item-template.html
Insert there the text from the default template
<Magento_Checkout_module_dir>/view/frontend/web/template/shipping-address/shipping-method-item.html with a couple of modifications:
- Add <tr> element that contains the delivery method description
- A column to expand \ hide the description
- Wrap you code in the <tbody> to give context to the collapsing lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<!-- Initialize collapsible binding --> <tbody collapsible="as: '$collapsible_' + method.method_code"> <tr class="row"> <td class="col col-method"> <input type="radio" class="radio" click="element.selectShippingMethod" ifnot="method.error_message" ko-checked="element.isSelected" ko-value="method.carrier_code + '_' + method.method_code" attr="'aria-labelledby': 'label_method_' + method.method_code + '_' + method.carrier_code + ' ' + 'label_carrier_' + method.method_code + '_' + method.carrier_code, 'checked': element.rates().length == 1 || element.isSelected" /> </td> <td class="col col-price"> <each args="element.getRegion('price')" render="" /> </td> <td class="col col-method" attr="'id': 'label_method_' + method.method_code + '_' + method.carrier_code" text="method.method_title" /> <td class="col col-carrier" attr="'id': 'label_carrier_' + method.method_code + '_' + method.carrier_code" text="method.carrier_title" /> <!-- Column with collapsible trigger --> <td class="col"> <a toggleCollapsible="'$collapsible_' + method.method_code"> <span data-bind="i18n: 'Info'"></span> </a> </td> </tr> <!-- Row for shipping method description --> <tr class="row" visible="$context['$collapsible_' + method.method_code].opened"> <td class="col" colspan="5" i18n="'Some description.'"/> </tr> <tr class="row row-error" if="method.error_message"> <td class="col col-error" colspan="5"> <div role="alert" class="message error"> <div text="method.error_message"></div> </div> <span class="no-display"> <input type="radio" attr="'value' : method.method_code, 'id': 's_method_' + method.method_code" /> </span> </td> </tr> </tbody> |
Step #2: Create a template for shipping methods list
Create the following file <root_dir>app/code/BelVG/Shipping/view/frontend/web/template/custom-method-list-template.html
by copying the text of the template from Magento 2 <Magento_Checkout_module_dir>/view/frontend/web/template/shipping-address/shipping-method-list.htm. Introduce the following modifications:
- Add your column into <thead>
- Delete <tbody> because we already put it in the previous template
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<div id="checkout-shipping-method-load"> <table class="table-checkout-shipping-method" markdown="1"> <thead> <tr class="row" markdown="1"> <th class="col col-method" translate="'Select Method'" /> <th class="col col-price" translate="'Price'" /> <th class="col col-method" translate="'Method Title'" /> <th class="col col-carrier" translate="'Carrier Title'" /> <!-- Column for triggers --> <th class="col" /> </tr> </thead> <!-- tbody was moved inside item template --> <!-- ko foreach: { data: rates(), as: 'method'} --> <!--ko template: { name: element.shippingMethodItemTemplate} --><!-- /ko --> <!-- /ko --> </table> </div> |
Step #3: Override the configuration of the shipping step
Create the layout in your module
<root_dir>app/code/BelVG/Shipping/view/frontend/layout/checkout_index_index.xml
There we override the default templates into the new ones we created in step 1 and 2. Now apply them as features of the shippingMethodListTemplate and shippingMethodItemTemplate methods in Magento_Checkout_module_dir>/view/frontend/web/js/view/shipping.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.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="shippingAddress" xsi:type="array"> <item name="config" xsi:type="array"> <item name="shippingMethodItemTemplate" xsi:type="string">BelVG_Shipping/custom-method-item-template</item> <item name="shippingMethodListTemplate" xsi:type="string">BelVG_Shipping/custom-method-list-template</item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </argument> </arguments> </referenceBlock> </body> </page> |
Partner With Us
Let's discuss how to grow your business. Get a Free Quote.How to configure free shipping in Magento 2
Free shipping as a delivery method has been gaining popularity among large and small ecommerce retailers, and the majority of customers expect to see this option at the checkout. At the moment, you will be default find free shipping option at every global marketplace like AliExpress, iHerb or Asos; the local online stores also more often than not grant free shipping, depending on the order volume.
Free shipping plays a crucial role in the customers’ purchase decision; a client is encouraged and pleased by the fact that they do not have to run into additional costs with delivery. Whether to grant your customers a free delivery option or not is up to you, yet it is important to be aware of how to enable free shipping in your Magento store.
Follow this step-by-step instruction to enable Magento free shipping via back office.
Step #1: navigate to Stores -> Setting -> Configuration.
Step #2: expand the Sales tab and select Shipping Methods
Step #3: expand the Free Shipping section and configure the following fields:
- Enabled at Yes
- Title – set the name for the free shipping method
- Method Name – enter the method description (Free by default)
- Minimum Order Amount – the order sum to qualify for free shipping
- Displayed Error Message – enter the message to display in case an error occurs
- Ship to Applicable Countries – select either All Allowed Countries or Specific Countries to select a certain destination state
- Show Method if Not Applicable – if Yes, the free shipping method will show even if it is not available, if No, then free shipping will show only then available
- Sort Order – set up the position of free shipping method among other shipping methods during the checkout.
It is not enough to make the Free shipping configuration – you must also accord these provisions with the shipping provider. In the Shipping Methods section, there are five tabs with the configurations for shipping methods Magento supports – Magento Shipping, UPS, USPS, FedEx and DHL. Expand the corresponding shipping method tab and set up the following:
Step #4: set Free Method at Ground, Free Shipping with Minimum Order Amount at Enable and define the Minimum Order Amount for Free Shipping (it should equal the one you set in the Minimum order Amount in the Free Shipping section).
Step #5: press Save Config in the upper right corner.
Done! You have created Magento free shipping option.
Magento 2 create shipment programmatically
In Magento, there is a difference between shipping and shipment. While shipping relates to the organization of delivery, shipment stands for the whole process of dispatching the ordered item. Since it is a store admin who processes the orders and makes the decision about the shipment, there is a wide capability for creating, managing and cancelling Magento shipment in the back office.
There is an alternative to creating a new shipment in the Magento back office. If you possess enough Magento development knowledge or have developers on the team, then creating shipment programmatically may turn out to be a more convenient method for you.
Below you will find our example of a test controller that creates shipment programmatically from the order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
<?php namespace BelVG\Shipping\Controller\Shipment; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Sales\Model\Order\ShipmentFactory; use Magento\Sales\Api\ShipmentRepositoryInterface; use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Shipping\Model\ShipmentNotifierFactory; use Magento\Shipping\Model\ShipmentNotifier; class Create extends Action { /** * @var OrderRepositoryInterface */ protected $orderRepository; /** * @var ShipmentRepositoryInterface */ protected $shipmentRepository; /** * @var ShipmentNotifier */ protected $shipmentNotifier; /** * @var ShipmentFactory */ protected $shipmentFactory; /** * Create constructor. * @param Context $context * @param OrderRepositoryInterface $orderRepository * @param ShipmentFactory $shipmentFactory * @param ShipmentRepositoryInterface $shipmentRepository * @param ShipmentNotifierFactory $shipmentNotifierFactory */ public function __construct( Context $context, OrderRepositoryInterface $orderRepository, ShipmentFactory $shipmentFactory, ShipmentRepositoryInterface $shipmentRepository, ShipmentNotifierFactory $shipmentNotifierFactory ) { $this->orderRepository = $orderRepository; $this->shipmentFactory = $shipmentFactory; $this->shipmentRepository = $shipmentRepository; $this->shipmentNotifier = $shipmentNotifierFactory->create(); parent::__construct($context); } public function execute() { $orderId = $this->getRequest()->getParam('order_id'); $order = $this->orderRepository->get($orderId); // to check order can ship or not if (!$order->canShip()) { throw new \Magento\Framework\Exception\LocalizedException( __('You can`t create the Shipment of this order.') ); } $shipment = $this->shipmentFactory->create($order); $shipment->register(); $shipment->getOrder()->setIsInProcess(true); try { // Save created Order Shipment $this->shipmentRepository->save($shipment); $this->orderRepository->save($shipment->getOrder()); // Send Shipment Email $this->shipmentNotifier->notify($shipment); $this->shipmentRepository->save($shipment); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException( __($e->getMessage()) ); } } } |
How to create shipment with tracking information programmatically in Magento 2
Magento also allows to add tracking information to a shipment. Now, we will demonstrate the developer method – how to add a tracking number and tracking information programmatically in Magento 2. In order to add tracking information for several shipping providers, we will modify the controller we already created during the $shipment shipment object creation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
... $trackingData = array( '0' => array( 'carrier_code' => 'fedex', 'title' => 'Federal Express', 'number' => '3131331230' ), '1' => array( 'carrier_code' => 'ups', 'title' => 'United Parcel Service', 'number' => '1Y-9876543210' ) ); $shipment = $this->shipmentFactory->create($order, [], $trackingData); ... |
How to create partial shipment programmatically in Magento 2
In order to create Magento partial shipment programmatically, follow these two steps:
Step #1: when you create $shipment object, pass into create() the array of the products that need to be delivered now [$orderItemId => $qty].
Step #2: modify the controller:
1 2 3 4 5 6 |
$items = array( '29' => 2, '30' => 3, '37' => 1 ); $shipment = $this->shipmentFactory->create($order, $items, $trackingData); |
How to create Magento 2 shipment via API
To create Magento shipment via API, you need order_item_id of the items you want to send. In case you need to send a bundle product, then specify only the amount of the main product.
When you need to create Magento partial shipment, then specify the number of items you need to deliver now. As the product is successfully delivered, the whole order status is changed at Complete Endpoint.
1 |
POST <host>/rest/<store_code>/V1/order/<orderId>/ship |
Headers
1 2 |
Content-Type application/json Authorization Bearer <administrator token> |
Payload
If needed, you can add the tracking info into the tracks array.
Show code sample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "items": [ { "order_item_id": 29, "qty": 2 }, { "order_item_id": 30, "qty": 3 }, { "order_item_id": 37, "qty": 1 } ], "tracks": [ { "track_number": "1Y-9876543210", "title": "United Parcel Service", "carrier_code": "ups" } ] } |
Wrapping it up
We hope that this article will prove to be a useful guide into Magento shipping and Magento shipment programmatically configurations. The step-by-step instructions on how to set up basic and free Magento shipping will undoubtedly be useful to admins of large, middle and small online stores. We also believe that for both beginning and experienced Magento developers will find in our instructions useful tips and tricks for creating shipping and customizing shipping operations in their store.
If you have any questions or comments, feel free to leave them down below.
Magento Development Services
Take your online store to the next level with BelVG Magento development
Visit the page