public OrderRecord CreateOrder(int customerId, IEnumerable<ShoppingCartItem> items) { if (items == null) throw new ArgumentNullException("items"); // Convert to an array to avoid re-running the enumerable var itemsArray = items.ToArray(); if (!itemsArray.Any()) throw new ArgumentException("Creating an order with 0 items is not supported", "items"); var order = new OrderRecord { //CreatedAt = _dateTimeService.Now, CreatedAt = DateTime.Now, CustomerId = customerId, Status = OrderStatus.New }; _orderRepository.Create(order); // add the shipping charges (if any) //var shippingProductPart = _contentManager.Get<ShippingProductPart>(_webShopSettings.ShippingProductRecord.Id); //if (shippingProductPart != null) //{ // var shippingProduct = shippingProductPart.As<ProductPart>(); // if (shippingProductPart != null) // { // var detail = new OrderDetailRecord // { // OrderRecord_Id = order.Id, // ProductPartRecord_Id = shippingProduct.Record.Id, // Quantity = 1, // UnitPrice = shippingProduct.UnitPrice, // GSTRate = .1m // }; // _orderDetailRepository.Create(detail); // order.Details.Add(detail); // } //} // Get all products in one shot, so we can add the product reference to each order detail //var productIds = itemsArray.Select(x => x.ProductId).ToArray(); //var products = _productRepository.Fetch(x => productIds.Contains(x.Id)).ToArray(); // Create an order detail for each item foreach (var item in itemsArray) { // This is not very fast but it is flexible and gathers the info we need // NOTE the use of a dynamic type below so we don't have to take a dependency on the // external Cascade.ArtStock module for the ArtworkPart. var product = _contentManager.Get<ProductPart>(item.ProductId); var description = _contentManager.GetItemMetadata(product).DisplayText; if (product.ContentItem.Parts.Any(p => p.TypeDefinition.Name == "Artwork")) { dynamic part = product ; description += " (" + part.ArtworkPart.ArtistRecord.Name + ")"; } else description += " (" + product.ContentItem.TypeDefinition.Name + ")"; var detail = new OrderDetailRecord { OrderRecord_Id = order.Id, ProductPartRecord_Id = product.Id, Quantity = item.Quantity, UnitPrice = product.UnitPrice, GSTRate = .1m, Sku = product.Sku, Description = description }; _orderDetailRepository.Create(detail); order.Details.Add(detail); } order.UpdateTotals(); return order; }
private void AddItem(PaypalRequest pr, int lineNumber, OrderDetailRecord detail) { //var productPart = _services.ContentManager.Get<ProductPart>(detail.ProductPartRecord_Id); pr.Add("L_PAYMENTREQUEST_0_NAME" + lineNumber, detail.Sku); pr.Add("L_PAYMENTREQUEST_0_DESC" + lineNumber, detail.Description); pr.Add("L_PAYMENTREQUEST_0_QTY" + lineNumber, detail.Quantity.ToString("f2")); pr.Add("L_PAYMENTREQUEST_0_AMT" + lineNumber, detail.UnitPrice.ToString("f2")); }