The shipment module, alongside the payment module, provides a basis for further sales functionality in our web shop. It will enable us to choose the shipment method when we reach the checkout process of the upcoming sales module. Similar to payment, shipment can be sort of static and dynamic. Whereas static might imply a fixed pricing value, or even a calculated one by some simple conditions, dynamic usually implies a connection to external API services.
Throughout this chapter, we will touch base with both types and see how we can set up a basic structure for implementing the shipment module.
In this chapter, we will be covering the following topics of the shipment module:
Application requirements, defined under Chapter 4, Requirement Specification for Modular Web Shop App, do not give us any specifics as to what type of shipment we need to implement. Thus, for the purpose of this chapter, we will develop two shipment methods: dynamic rate shipment and flat rate shipment. Dynamic rate shipment is used as a way of connecting the shipment method to a real shipment processor, such as UPS, FedEx, and so on. It will not, however, actually connect to any of the external APIs.
Ideally, we want this done by an interface similar to the following:
namespace Foggyline\SalesBundle\Interface;
interface Shipment
{
function getInfo($street, $city, $country, $postcode, $amount, $qty);
function process($street, $city, $country, $postcode, $amount, $qty);
}The getInfo method can then be used to fetch the available delivery options for the given order information, while the process method would then process the selected delivery option. For example, we might have an API return "same day delivery ($9.99)",= and "standard delivery ($4.99)" as delivery options under the dynamic rate shipment method.
Having such a shipment interface would then impose the requirement of having the SalesBundle module, which we still haven't developed. We will therefore proceed with our shipment methods, using a Symfony controller for handling the process method and a service for handling the getInfo method.
Similarly, as we did with the payment method in the previous chapter, we will expose our getInfo method through tagged Symfony services. The tag we will be using for shipment methods is shipment_method. Later on, during the checkout process, the SalesBundle module will fetch all of the services tagged with shipment_method and use them internally for a list of available shipment methods to work with.