/// <summary> /// Builds the basket. /// </summary> /// <param name="connector">The connector.</param> /// <param name="order">The order.</param> /// <returns> /// A string containing the contents of the order /// </returns> private static string BuildBasket(CrmConnector connector, OrderProvider orderProvider, SalesOrder order) { StringBuilder basket = new StringBuilder(); // A basket item comprises of Product Name, Quantity, Unit Cost, Tax, Cost inc. Tax, and Total Cost (Cost*Quantity). These are all seperated with colons (i.e. %3A). string basketItem = String.Empty; string seperator = "%3A"; // Get a list of the names for the level Option Set. MetaDataProvider metaDataProvider = new MetaDataProvider(connector); OptionMetadataCollection levelOptionSetLabels = metaDataProvider.RetrieveOptionSetMetaDataCollection(SalesOrderDetail.EntityLogicalName, "lss_level"); int basketCount = 0; List <SalesOrderDetail> productExtras; List <SalesOrderDetail> orderDetails = orderProvider.GetOrderDetail(order.Id, ProductType.Course); foreach (SalesOrderDetail detail in orderDetails) { string basketItemName = GetBasketNameOfProduct(detail, levelOptionSetLabels); // Add name of basket item with a hard-coded Quantity of 1 basketItem = seperator + basketItemName + seperator + "1" + seperator; // For each product check if it has any related products productExtras = orderProvider.GetProductExtras(detail.Id); decimal extraUnitCost = 0; decimal extraTax = 0; decimal extraTotal = 0; foreach (SalesOrderDetail extra in productExtras) { extraUnitCost += extra.BaseAmount == null ? 0 : extra.BaseAmount.Value; extraTax += extra.Tax == null ? 0 : extra.Tax.Value; extraTotal += extra.ExtendedAmount == null ? 0 : extra.ExtendedAmount.Value; } // Add unit cost basketItem += (detail.BaseAmount.Value + extraUnitCost).ToString("#.##") + seperator; // Add Tax basketItem += detail.Tax == null ? "0" : (detail.Tax.Value + extraTax).ToString("#.##") + seperator; // Add Cost inc. Tax basketItem += (detail.ExtendedAmount.Value + extraTotal).ToString("#.##") + seperator; // Add Total Cost basketItem += (detail.ExtendedAmount.Value + extraTotal).ToString("#.##"); basket.Append(basketItem); basketCount++; } basket.Insert(0, "&Basket=" + basketCount.ToString()); return(basket.ToString()); }