protected virtual void WriteOrderItemsToXml(XmlTextWriter writer, ICollection<OrderItem> orderItems)
{
writer.WriteStartElement("Items");
var productAttributeParser = EngineContext.Current.Resolve<ProductAttributeParser>();
foreach (var orderItem in orderItems)
{
var product = _productService.GetProductById(orderItem.ProductId);
var order = _orderService.GetOrderById(orderItem.OrderId);
//is shippable
if (!product.IsShipEnabled)
continue;
writer.WriteStartElement("Item");
var sku = product.Sku;
var attributesXml = orderItem.AttributesXml;
if (!string.IsNullOrEmpty(attributesXml) && product.ManageInventoryMethod == ManageInventoryMethod.ManageStockByAttributes)
{
var combination = productAttributeParser.FindProductAttributeCombination(product, attributesXml);
if (combination != null)
{
sku = combination.Sku;
}
}
writer.WriteElementString("SKU", string.IsNullOrEmpty(sku) ? product.Id.ToString() : sku);
writer.WriteElementString("Name", product.Name);
writer.WriteElementString("Quantity", orderItem.Quantity.ToString());
writer.WriteElementString("UnitPrice", (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax ? orderItem.UnitPriceInclTax : orderItem.UnitPriceExclTax).ToString(CultureInfo.InvariantCulture));
writer.WriteEndElement();
writer.Flush();
}
writer.WriteEndElement();
writer.Flush();
}