Delivery cost based on item weight
Sometimes it is necessary to calculate the delivery cost based on several parameters. The main parameter on sending via post is the item weight. This article shows a specific example on how to implement the delivery cost based on total weight of the items purchased.
The calculation is normally made by the delivery management system or the ERP system. But in some cases, the delivery cost functions are not present.
The default Litium implementation allows setting a single fixed cost for each delivery method. Go to back office Settings > Sales > Delivery methods, select a delivery method and click Edit. You can find more info on delivery providers and delivery methods here.
If we define a maximum weight for each delivery method, it's a matter of adding delivery methods for each weight band.
For example, take the following scenario:
Delivery Method |
Maximum Weight (grams) |
Cost with VAT |
Small package |
200 |
29 SEK |
Medium package |
1000 |
69 SEK |
Large package |
5000 |
169 SEK |
When the delivery cost and weights are defined as above, it is not possible to allow the end customer to choose the delivery method, but it should be automatically selected based on the total weight of the delivery.
Litium does not allow to save the maximum weight for each delivery method by default, so we need to build it using a custom admin panel. Then we need to select the correct delivery method based on the weight of the delivery, and then use the default delivery cost calculator to calculate the delivery cost based on the cost set in back office for each delivery (as shown above).
For example, if the total item weight of a delivery is 400 g, then we select the medium package, and the delivery cost will be 69 SEK.
This example can easily be extended when delivery options such as "Standard delivery" and "Express delivery" is needed on the checkout page, but to keep the code sample simple, we only present the above basic implementation.
This section explains how to set the weight of an article.
This section explains how to override the DeliveryCostCalculator to change the delivery method based on the delivery weight.
This section shows a class that implement methods to select the delivery method based on the weight.
This article shows how to save the delivery method weights into an e-commerce settings table.
This article shows how to create an admin panel to edit the maximum weight of each delivery method.
This article explains the content panel which shows the summary of the weight limits.