private void AddItemToShoppingCart() { OptionItemValueCollection selectedOptions = uxOptionGroupDetails.GetSelectedOptions(); ProductKitItemValueCollection selectedKits = uxProductKitGroupDetails.GetSelectedProductKitItems(); CartItemGiftDetails giftDetails = CreateGiftDetails(); decimal customPrice = decimal.Parse(uxEnterAmountText.Text); customPrice = decimal.Divide(customPrice, Convert.ToDecimal(StoreContext.Currency.ConversionRate)); CartAddItemService addToCartService = new CartAddItemService( StoreContext.Culture, StoreContext.ShoppingCart); int currentStock; string errorOptionName; bool stockOK = addToCartService.AddToCart( CurrentProduct, selectedOptions, selectedKits, ConvertUtilities.ToInt32(uxQuantityText.Text), giftDetails, customPrice, out errorOptionName, out currentStock); if (stockOK) { Response.Redirect("ShoppingCart.aspx"); } else { DisplayOutOfStockError(currentStock, errorOptionName); } }
private void AddItemToShoppingCart() { OptionItemValueCollection selectedOptions = uxOptionGroupDetails.GetSelectedOptions(); ProductKitItemValueCollection selectedKits = uxProductKitGroupDetails.GetSelectedProductKitItems(); CartItemGiftDetails giftDetails = CreateGiftDetails(); decimal customPrice = decimal.Parse(uxEnterAmountText.Text); customPrice = decimal.Divide(customPrice, Convert.ToDecimal(StoreContext.Currency.ConversionRate)); CartAddItemService addToCartService = new CartAddItemService( StoreContext.Culture, StoreContext.ShoppingCart); int currentStock; string errorOptionName; bool stockOK = addToCartService.AddToCart( CurrentProduct, selectedOptions, selectedKits, ConvertUtilities.ToInt32(uxQuantityText.Text), giftDetails, customPrice, out errorOptionName, out currentStock); if (stockOK) { bool enableNotification = ConvertUtilities.ToBoolean(DataAccessContext.Configurations.GetValue("EnableAddToCartNotification", StoreContext.CurrentStore)); if (UrlManager.IsMobileDevice(Request)) { enableNotification = false; } if (enableNotification) { uxAddToCartNotification.Show(CurrentProduct, ConvertUtilities.ToInt32(uxQuantityText.Text), customPrice, giftDetails, selectedOptions, selectedKits); } else { Response.Redirect("ShoppingCart.aspx"); } } else { DisplayOutOfStockError(currentStock, errorOptionName); } }
public bool UpdateCartItem(bool isSubscriptionable, out string errMsg) { errMsg = String.Empty; if (!VerifyValidInput(out errMsg)) { if (!String.IsNullOrEmpty(errMsg)) { DisplayErrorMessage(errMsg); return(false); } } //string errMsg; if (!VerifyQuantity(out errMsg)) { DisplayErrorMessage(errMsg); return(false); } if (!IsMatchQuantity()) { return(false); } ICartItem item = StoreContext.ShoppingCart.FindCartItemByID(CartItemID); OptionItemValueCollection selectedOptions = uxProductOptionGroupDetails.GetSelectedOptions(); CartItemGiftDetails giftDetails = CreateGiftDetails(); Currency currency = DataAccessContext.CurrencyRepository.GetOne(CurrencyCode); decimal enterPrice = ConvertUtilities.ToDecimal(currency.FormatPriceWithOutSymbolInvert(ConvertUtilities.ToDecimal(uxEnterAmountText.Text))); if (enterPrice == item.Product.GetProductPrice(StoreID).Price) { enterPrice = 0; } decimal customPrice = 0; if (item.Product.IsCustomPrice) { customPrice = ConvertUtilities.ToDecimal(currency.FormatPriceWithOutSymbolInvert(ConvertUtilities.ToDecimal(uxEnterAmountText.Text))); } int currentStock; string errorOptionName; StoreContext.ShoppingCart.DeleteItem(CartItemID); CartAddItemService addToCartService = new CartAddItemService( StoreContext.Culture, StoreContext.ShoppingCart); bool stockOK = addToCartService.AddToCartByAdmin( item.Product, selectedOptions, ConvertUtilities.ToInt32(uxQuantityText.Text), giftDetails, customPrice, enterPrice, StoreID, out errorOptionName, out currentStock, isSubscriptionable); if (stockOK) { return(true); } else { errMsg = DisplayOutOfStockError(currentStock, errorOptionName); return(false); } }
public void Show(Product product, int quantity, decimal customPrice, CartItemGiftDetails giftDetails, OptionItemValueCollection selectedOptions, ProductKitItemValueCollection productKitItemCollection) { ProductImage image = product.GetPrimaryProductImage(); uxProductImage.ImageUrl = "~/" + image.RegularImage; uxProductNameLink.NavigateUrl = UrlManager.GetProductUrl(product.ProductID, product.Locales[StoreContext.Culture].UrlName); uxProductNameLink.Text = "<div class='ProductName'>" + product.Name + "</div>"; uxQuantityLabel.Text = quantity.ToString(); decimal productPrice = product.GetDisplayedPrice(StoreContext.WholesaleStatus); if (product.IsCustomPrice) { productPrice = customPrice; } if (product.IsGiftCertificate && !product.IsFixedPrice) { productPrice = giftDetails.GiftValue; } if (productKitItemCollection.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (OptionItemValue optionItemValue in selectedOptions) { sb.Append("<div class='OptionName'>"); sb.Append(optionItemValue.GetDisplayedName(StoreContext.Culture, StoreContext.Currency)); sb.Append("</div>"); } if ((!productKitItemCollection.IsNull) && (productKitItemCollection.Count > 0)) { sb.Append("<div class='OptionName'>"); sb.Append("Items:"); sb.Append("</div>"); } foreach (ProductKitItemValue value in productKitItemCollection) { sb.Append("<div class='OptionName'>"); sb.Append("- " + value.GetGroupName(StoreContext.Culture, StoreContext.CurrentStore.StoreID) + ":" + value.GetDisplayedName(StoreContext.Culture, StoreContext.CurrentStore.StoreID)); sb.Append("</div>"); } uxProductNameLink.Text = uxProductNameLink.Text + sb.ToString(); } else { if (selectedOptions.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (OptionItemValue optionItemValue in selectedOptions) { sb.Append("<div class='OptionName'>"); sb.Append(optionItemValue.GetDisplayedName(StoreContext.Culture, StoreContext.Currency)); sb.Append("</div>"); productPrice += optionItemValue.OptionItem.PriceToAdd; } uxProductNameLink.Text = uxProductNameLink.Text + sb.ToString(); } } uxPriceLabel.Text = StoreContext.Currency.FormatPrice(productPrice); uxMessage.Text = product.Name + "[$AddSuccess]"; uxAddToCartPopup.Show(); }
private bool ReOrderToCart(Product product, OrderItem orderItem, string optionItemIDs, ProductKitItemValueCollection itemCollection) { string errorCurrentStock = string.Empty; int currentStock = 0; bool isAddToCartSuccess = false; OptionItemValueCollection optionCollection = new OptionItemValueCollection(StoreContext.Culture, optionItemIDs, product.ProductID); CartItemGiftDetails giftDetails = new CartItemGiftDetails(); if (product.IsGiftCertificate) { GiftCertificateProduct giftProduct = (GiftCertificateProduct)product; IList <GiftCertificate> giftCertificateList = DataAccessContext.GiftCertificateRepository.GetAllByOrderID(orderItem.OrderID); foreach (GiftCertificate giftCertificate in giftCertificateList) { if (orderItem.OrderItemID == giftCertificate.OrderItemID) { giftDetails = new CartItemGiftDetails( giftCertificate.Recipient, giftCertificate.PersonalNote, giftCertificate.NeedPhysical, giftCertificate.GiftValue); } } if (giftProduct.GiftAmount == 0) { giftProduct.GiftAmount = orderItem.UnitPrice; } product = (Product)giftProduct; CartAddItemService addToCartService = new CartAddItemService( StoreContext.Culture, StoreContext.ShoppingCart); isAddToCartSuccess = addToCartService.AddToCart( product, optionCollection, itemCollection, orderItem.Quantity, giftDetails, 0, out errorCurrentStock, out currentStock); } else if (product.IsCustomPrice) { CartAddItemService addToCartService = new CartAddItemService( StoreContext.Culture, StoreContext.ShoppingCart); isAddToCartSuccess = addToCartService.AddToCart( product, optionCollection, itemCollection, GetProductQuantity(product, orderItem), giftDetails, orderItem.UnitPrice, out errorCurrentStock, out currentStock); } else { CartAddItemService addToCartService = new CartAddItemService( StoreContext.Culture, StoreContext.ShoppingCart); isAddToCartSuccess = addToCartService.AddToCart( product, optionCollection, itemCollection, GetProductQuantity(product, orderItem), giftDetails, 0, out errorCurrentStock, out currentStock); } if (!isAddToCartSuccess) { StoreContext.ClearCheckoutSession(); string message = "<p class=\"ErrorHeader\">[$StockError]</p>"; ErrorMessage(message); return(false); } return(true); }