public ActionResult getLineItem(LineItemsOfOrder productVariantOfOrder) { try { List <LineItem> lineItems = new List <LineItem>(); if (productVariantOfOrder != null) { if (productVariantOfOrder.ProductVariants != null && productVariantOfOrder.ProductVariants.Count > 0) { foreach (var item in productVariantOfOrder.ProductVariants) { if (item.Choice) { LineItem lineItem = new LineItem(); lineItem.ProductID = item.ProductID; lineItem.VariantID = item.VariantID; Variant variant = variantService.GetByPrimaryKey(item.VariantID); if (variant != null) { if (variant.VariantTittle != "Default Title") { lineItem.VariantName = variant.VariantTittle; } Product product = productService.GetByPrimaryKey(variant.ProductID); lineItem.ProductName = product.ProductName; } lineItem.ImageUrl = item.ImageUrl; lineItem.IsDefault = item.IsDefault; lineItem.Quantity = item.Quantity; lineItem.Price = item.Price; lineItem.SKU = item.SKU; lineItems.Add(lineItem); } } } } return(Json(lineItems, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogService.WriteException(ex); return(null); } }
public ActionResult getLineItem(string variantChoiced, string query) { try { LineItemsOfOrder productVariantOfProduct = new LineItemsOfOrder(); List <Product> products = new List <Product>(); if (string.IsNullOrEmpty(query)) { products = productService.GetAll(); } else { string where = string.Format("ProductName like N'%{0}%' or Tags like N'%{1}%' ", query, query); where += string.Format(" or ProductID in (select Product.ProductID from Product left join TblOption on Product.ProductID = TblOption.ProductID " + " where OptionValue like N'%{0}%')", query); products = productService.GetByWhere(where); } List <int> variantIDs = new List <int>(); if (!string.IsNullOrEmpty(variantChoiced)) { variantChoiced = SString.RemoveElementAtBeginEnd(variantChoiced, ","); string[] temp = variantChoiced.Split(','); foreach (var item in temp) { variantIDs.Add(SNumber.ToNumber(item)); } } if (products != null && products.Count > 0) { foreach (var item in products) { List <Variant> variants = variantService.GetByProductID(item.ProductID); if (variants != null && variants.Count > 0) { if (variants.Count == 1 && variants[0].Option1 == "Default Title") { LineItem temp = new LineItem(); temp.VariantID = variants[0].VariantID; temp.SKU = variants[0].VariantSKU; temp.ProductID = item.ProductID; temp.ObjectName = item.ProductName; temp.IsDefault = true; temp.Price = SNumber.ToNumber(variants[0].VariantPrice); temp.Quantity = 1; var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID); temp.ImageUrl = thumb; if (!variantIDs.Contains(temp.VariantID)) { temp.CanChoice = true; } else { temp.CanChoice = false; } productVariantOfProduct.ProductVariants.Add(temp); } else { LineItem product = new LineItem(); product.VariantID = 0; product.ProductID = item.ProductID; product.ObjectName = item.ProductName; product.IsDefault = true; product.Price = -1; product.CanChoice = false; product.Quantity = 1; var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID); product.ImageUrl = thumb; productVariantOfProduct.ProductVariants.Add(product); for (int i = 0; i < variants.Count; i++) { LineItem temp = new LineItem(); temp.ProductID = item.ProductID; temp.VariantID = variants[i].VariantID; temp.ObjectName = variants[i].VariantTittle; temp.SKU = variants[i].VariantSKU; temp.IsDefault = false; temp.Price = SNumber.ToNumber(variants[i].VariantPrice); temp.Quantity = 1; if (!variantIDs.Contains(temp.VariantID)) { temp.CanChoice = true; } else { temp.CanChoice = false; } TblImage image = imageService.GetByPrimaryKey(variants[i].ImageID); if (image != null) { temp.ImageUrl = image.ImageUrl; } productVariantOfProduct.ProductVariants.Add(temp); } } } } } return(View(productVariantOfProduct)); } catch (Exception ex) { LogService.WriteException(ex); return(null); } }