Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
A Shipping Method manages a set of information and rules that determine the shipping cost and displays it on the front-end site during the checkout procedure. The shipping fee is added to the total price of the purchase. A Shipping Method is mapped to a Shipping Provider, visible to a back-end administrator in Commerce Manager. This allows the public site to display friendly names such as "Ground Shipping" to the customer and this is mapped to a provider such as UPS. Therefore, when a customer picks "Ground Shipping," UPS will be used.
Refer to Shipping Gateways and Providers for information on how to create gateways and providers.
Classes referred to here are available in the Mediachase.Commerce.Orders.Dto namespace.
Information can be stored an retrieved in two ways described below.
Using the ShippingMethodParameter table
This allows you to store name/value pairs for settings related to that shipping method.
Example: accessing ShippingMethodParameter table
if (_ShippingMethodDto != null && _ShippingMethodDto.ShippingMethodParameter != null &&
_ShippingMethodDto.ShippingMethodParameter.Rows.Count > 0)
{
ShippingMethodDto.ShippingMethodParameterRow row = (ShippingMethodDto.ShippingMethodParameterRow)_ShippingMethodDto.ShippingMethodParameter.Rows[0];
txtTypeOfService.Text = row.Value;
lblTypeOfService.Text = row.Parameter;
}
Using the WeightJurisdiction provider
You can also store information in the format you see with in the WeightJurisdiction provider. Here, each row of data represents: Total (representing the count or weight value), Charge, JurisdictionGroupId, StartDate, EndDate for different shipping scenarios. This information is stored in the ShippingMethodCase table.
Example: using WeightJurisidiction
if (_ShippingMethodDto != null && _ShippingMethodDto.ShippingMethodCase != null && _ShippingMethodDto. ShippingMethodCase.Rows.Count > 0)
{
ShippingMethodDto.ShippingMethodCaseRow row = (ShippingMethodDto.ShippingMethodCaseRow)_ShippingMethodDto.ShippingMethodCase.Rows[0];
txtTotalWeight.Text = row.Total;
txtCharge.Text = row.Charge;
txtStartDate.Text = row.StartDate.ToString();
}
In the following is an example of how you display the shipping methods to users and the respective rates for each, based on the current cart.
Example: accessing shipping information
//Get the list of all shipping methods to be filtered
ShippingMethodDto methods = ShippingManager.GetShippingMethods(SiteContext.Current.LanguageName);
// filter the list for only methods that apply to this particular cart's shipping address
List<ShippingMethodDto.ShippingMethodRow> shippingRows = new List<ShippingMethodDto.ShippingMethodRow>();
foreach (ShippingMethodDto.ShippingMethodRow method in methods.ShippingMethod.Rows)
shippingRows.Add(method);
List<ShippingRate> list = new List<ShippingRate>();
foreach (ShippingMethodDto.ShippingMethodRow row in shippingRows)
{
Type type = Type.GetType(row.ShippingOptionRow.ClassName);
string message = String.Empty;
IShippingGateway provider = (IShippingGateway)Activator.CreateInstance(type);
List<LineItem> items = new List<LineItem>();
foreach(LineItem lineItem in CartHelper.LineItems)
items.Add(lineItem);
if (items.Count > 0)
list.Add(provider.GetRate(row.ShippingMethodId, items.ToArray(), ref message));
}
Storing of information for a selected shipping method is done using the lineitem properties. You do not need to create a shipment object, since the Cart Prepare workflow will handle this.
Example: storing shipping method information
ShippingMethodDto methods = ShippingManager.GetShippingMethods(SiteContext.Current.LanguageName);
ShippingMethodDto.ShippingMethodRow row = methods.ShippingMethod.FindByShippingMethodId(new Guid(ShippingRatesList.SelectedValue));
foreach (LineItem lineItem in CartHelper.LineItems)
{
lineItem.ShippingMethodName = row.DisplayName;
lineItem.ShippingMethodId = row.ShippingMethodId;
}
Last updated: Oct 21, 2014