/// <summary> /// Convert the purchased prod into a string of params for paypal description /// </summary> /// <returns></returns> public string CreatePayPalItemDescriptions(int index) { string ReturnString = string.Empty; string Description = string.Empty; ReturnString += String.Format("&L_PAYMENTREQUEST_0_NAME{0}={1}", index, Uri.EscapeDataString(Name)); if (SelectedCheckoutProperties != null && SelectedCheckoutProperties.Count > 0) { for (int myIndex = 0; myIndex < SelectedCheckoutProperties.Count; myIndex++) { CheckoutPropertySettingKey SelectedProp = SelectedCheckoutProperties[myIndex]; Description += SelectedProp.Key + ": " + SelectedProp.Value; if (myIndex != SelectedCheckoutProperties.Count - 1) { Description += ", "; } } } ReturnString += String.Format("&L_PAYMENTREQUEST_0_DESC{0}={1}", index, Description); ReturnString += String.Format("&L_PAYMENTREQUEST_0_AMT{0}={1}", index, Uri.EscapeDataString(PurchasePrice.ToString("0.00"))); ReturnString += String.Format("&L_PAYMENTREQUEST_0_QTY{0}={1}", index, Uri.EscapeDataString(Quantity.ToString())); return(ReturnString); }
/// <summary> /// Called whenever the user wishes to add a new item to their shopping cart. /// </summary> /// <returns></returns> public ActionResult AddItemToCart(string id) { try { SiteContext.RecordPageView("Ecommerce_ViewShoppingCart"); Product Prod = ProductDAO.LoadByBsonId(id); if (Prod != null && !Prod.Id.Equals(string.Empty)) { ShoppingCartProduct ShopCartProd = new ShoppingCartProduct(Prod); //first build the key/value pairs that the user selected in the view product form List <CheckoutPropertySettingKey> CheckoutPropertySettingKeys = new List <CheckoutPropertySettingKey>(); if (Prod.CheckoutPropertyList != null && Prod.CheckoutPropertyList.Count > 0) { foreach (var CheckProp in Prod.CheckoutPropertyList) { if (!string.IsNullOrWhiteSpace(Request["checkProd_" + CheckProp.Name])) { CheckoutPropertySettingKeys.Add(new CheckoutPropertySettingKey(CheckProp.Name, Request["checkProd_" + CheckProp.Name])); } } } //if there are even custom settings if (Prod.CheckoutPropertySettingsList != null && Prod.CheckoutPropertySettingsList.Count > 0) { //now find the custom setting with the customers selected key/values foreach (var CheckPropSetting in Prod.CheckoutPropertySettingsList) { int NumberOfMatches = 0; if (CheckPropSetting.CheckoutPropertySettingKeys != null && CheckPropSetting.CheckoutPropertySettingKeys.Count > 0) { foreach (var CheckPropSettingKey in CheckPropSetting.CheckoutPropertySettingKeys) { CheckoutPropertySettingKey MatchedCheckPropSetKey = CheckoutPropertySettingKeys.Where(e => e.Key.Equals(CheckPropSettingKey.Key) && e.Value.Equals(CheckPropSettingKey.Value)).FirstOrDefault(); if (MatchedCheckPropSetKey != null && !string.IsNullOrWhiteSpace(MatchedCheckPropSetKey.Key) && !string.IsNullOrWhiteSpace(MatchedCheckPropSetKey.Value)) { NumberOfMatches++; } } } //if this checkout property setting matched the same key/value pairs the user selected if (NumberOfMatches > 0 && NumberOfMatches == CheckoutPropertySettingKeys.Count) { ShopCartProd.CheckoutPropertySetting = CheckPropSetting; break; } } } ShopCartProd.SelectedCheckoutProperties = CheckoutPropertySettingKeys; ShoppingCartProduct AlreadyExistsShopCartProd = SiteContext.ShoppingCartProductList.Where(e => e.CartUniqueId.Equals(ShopCartProd.CartUniqueId)).FirstOrDefault(); //if not null then this user already has this exact prod/setting match, just increase quantity if (AlreadyExistsShopCartProd != null) { if (AlreadyExistsShopCartProd.CanAddToCartOrIncreaseQuantity(AlreadyExistsShopCartProd.Quantity + 1)) { AlreadyExistsShopCartProd.Quantity++; SiteContext.RemoveShoppingCartProduct(AlreadyExistsShopCartProd.CartUniqueId); SiteContext.AddShoppingCartProduct(AlreadyExistsShopCartProd); } else { //add user message AddWebUserMessageToSession(Request, AlreadyExistsShopCartProd.CreateOutOfStockMessage(), NEUTRAL_MESSAGE_TYPE); } } //else add a brand new product to the shopping cart else { if (ShopCartProd.CanAddToCartOrIncreaseQuantity(1)) { SiteContext.AddShoppingCartProduct(ShopCartProd); } else { //add user message AddWebUserMessageToSession(Request, ShopCartProd.CreateOutOfStockMessage(), NEUTRAL_MESSAGE_TYPE); } } ViewBag.ShoppingCartModel = GetModel(); return(View("ViewCart", String.Format("~/Templates/{0}/Views/Shared/Template.Master", Models.ChimeraTemplate.TemplateName))); } } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Controllers.ShoppingCartController.AddItemToCart() " + e.Message); } //TODO: return 404 page instead? return(RedirectToAction("Index", "Home")); }