protected void pTreeProduct_NodeSelected(object sender, PopupTreeView.TreeNodeSelectedArgs args) { var items = new List <OrderItem>(); foreach (var val in args.SelectedValues) { int treeSelectedValue; int.TryParse(val, out treeSelectedValue); var product = ProductService.GetProduct(SQLDataHelper.GetInt(treeSelectedValue)); items.Add(new OrderItem { Name = product.Name, Price = product.Offers[0].Price * (100 - Math.Max(product.Discount, GroupDiscount)) / 100, SupplyPrice = product.Offers[0].SupplyPrice, ProductID = product.ProductId, Amount = 1, ArtNo = product.ArtNo, IsCouponApplied = CouponCode.IsNotEmpty() && CouponService.GetCouponByCode(CouponCode) != null && CouponService.IsCouponAppliedToProduct(CouponService.GetCouponByCode(CouponCode).CouponID, product.ProductId), Weight = product.Weight, PhotoID = product.ProductPhotos.OrderByDescending(p => p.Main).FirstOrDefault() != null ? product.ProductPhotos.OrderByDescending(p => p.Main).FirstOrDefault().PhotoId : (int?)null }); } if (OrderItems == null) { OrderItems = new List <OrderItem>(); } foreach (var item in items) { item.OrderItemID = GenItemId(); item.SelectedOptions = new List <EvaluatedCustomOptions>(); if (OrderItems.Contains(item)) { OrderItems[OrderItems.IndexOf(item)].Amount += 1; } else { OrderItems.Add(item); } } LoadProducts(); ItemsUpdated(this, new EventArgs()); pTreeProduct.UnSelectAll(); pTreeProduct.Hide(); }
protected void btnAddProductByArtNo_Click(object sender, EventArgs e) { Product product = null; Offer offer = null; if (hfOffer.Value.IsNotEmpty()) { int offerId = hfOffer.Value.Trim().TryParseInt(); if (offerId != 0) { offer = OfferService.GetOffer(offerId); product = ProductService.GetProduct(offer.ProductId); } } else if (txtArtNo.Text.IsNotEmpty()) { string searchTerm = txtArtNo.Text.Trim(); product = ProductService.GetProduct(searchTerm, true); if (product == null) { product = ProductService.GetProductByName(searchTerm); if (product == null) { return; } } else { offer = product.Offers.Find(o => o.ArtNo == searchTerm); } } if (product == null) { return; } if (offer == null) { offer = product.Offers[0]; } var item = new OrderItem { OrderItemID = GenItemId(), Name = product.Name, Price = offer.Price * (100 - Math.Max(product.Discount, GroupDiscount)) / 100, SupplyPrice = offer.SupplyPrice, ProductID = product.ProductId, Amount = 1, ArtNo = offer.ArtNo, Color = offer.Color != null ? offer.Color.ColorName : null, Size = offer.Size != null ? offer.Size.SizeName : null, PhotoID = offer.Photo != null ? offer.Photo.PhotoId : default(int), SelectedOptions = new List <EvaluatedCustomOptions>(), IsCouponApplied = CouponCode.IsNotEmpty() && CouponService.GetCouponByCode(CouponCode) != null && CouponService.IsCouponAppliedToProduct(CouponService.GetCouponByCode(CouponCode).CouponID, product.ProductId), Weight = product.Weight }; if (OrderItems == null) { OrderItems = new List <OrderItem>(); } if (OrderItems.Contains(item)) { OrderItems[OrderItems.IndexOf(item)].Amount += 1; } else { OrderItems.Add(item); } txtArtNo.Text = ""; hfOffer.Value = ""; LoadProducts(); ItemsUpdated(this, new EventArgs()); }