Add order rows
This article describes how to add order rows to the order carrier in the shopping cart by using the Litium API methods.
Order rows are added to the shopping cart order carrier when the buy button is clicked. Also, order rows might be automatically added from the campaigns engine, when a free gift campaign is running.
Programatically add an order row
To add an item to the order, call the CurrentState.Current.ShoppingCart.Add() method. The following example is from the accelerators. The source can be found in Src\Litium.Studio.Accelerator\WebServices\ShoppingCartService.cs.
public bool AddArticleToCart(string articleId, string productId, string languageId, decimal quantity)
{
// Article can not be added to the shoping cart if the cart has no order.
if (!HasOrder)
{
return false;
}
try
{
// Convert the input parameters
var productIdGuid = new Guid(productId);
var articleIdGuid = new Guid(articleId);
var languageIdGuid = new Guid(languageId);
Article article;
// Add the article to the shoping cart if the article exists
if (Article.TryGet(articleIdGuid, out article, ModuleProductCatalog.Instance.AdminToken))
{
if (quantity > 0)
{
CurrentState.Current.ShoppingCart.Add(
productIdGuid,
article.ArticleNumber,
quantity,
string.Empty,
languageIdGuid, !CurrentState.Current.ShoppingCart.OrderCarrier.IsB2B());
return true;
}
}
}
catch (Exception ex)
{
Solution.Instance.Log.CreateLogEntry("AddArticleToCart", ex, LogLevels.ERROR);
return false;
}
return false;
}
When the CurrentState.ShoppingCart.Add() method is called, the shopping cart will internally call the ICheckoutFlow.AddOrderRow method (or, if you already have the same item in the cart, the ICheckoutFlow.EditOrderRow method depending on the tryAddToExistingOrderRow parameter). Then it will call the ICheckoutFlow.AddDeliveryRow method which will add the article just added to a delivery.
The default implementation of the ICheckoutFlow methods can be customised, see the Customising checkout flow - overview article.