/// <summary> /// Updates the shopping cart item /// </summary> /// <param name="ShoppingCartItemID">The shopping cart item identifier</param> /// <param name="ShoppingCartType">The shopping cart type</param> /// <param name="CustomerSessionGUID">The customer session identifier</param> /// <param name="ProductVariantID">The product variant identifier</param> /// <param name="AttributesXML">The product variant attributes</param> /// <param name="Quantity">The quantity</param> /// <param name="CreatedOn">The date and time of instance creation</param> /// <param name="UpdatedOn">The date and time of instance update</param> /// <returns>Shopping cart item</returns> internal static ShoppingCartItem UpdateShoppingCartItem(int ShoppingCartItemID, ShoppingCartTypeEnum ShoppingCartType, Guid CustomerSessionGUID, int ProductVariantID, string AttributesXML, int Quantity, DateTime CreatedOn, DateTime UpdatedOn) { if (ShoppingCartItemID == 0) { return(null); } if (AttributesXML == null) { AttributesXML = string.Empty; } CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn); UpdatedOn = DateTimeHelper.ConvertToUtcTime(UpdatedOn); DBShoppingCartItem dbItem = DBProviderManager <DBShoppingCartProvider> .Provider.UpdateShoppingCartItem(ShoppingCartItemID, (int)ShoppingCartType, CustomerSessionGUID, ProductVariantID, AttributesXML, Quantity, CreatedOn, UpdatedOn); ShoppingCartItem shoppingCartItem = DBMapping(dbItem); return(shoppingCartItem); }
/// <summary> /// Gets a shopping cart by customer session GUID /// </summary> /// <param name="ShoppingCartType">Shopping cart type</param> /// <param name="CustomerSessionGUID">The customer session identifier</param> /// <returns>Cart</returns> public static ShoppingCart GetShoppingCartByCustomerSessionGUID(ShoppingCartTypeEnum ShoppingCartType, Guid CustomerSessionGUID) { DBShoppingCart dbCollection = DBProviderManager <DBShoppingCartProvider> .Provider.GetShoppingCartByCustomerSessionGUID((int)ShoppingCartType, CustomerSessionGUID); ShoppingCart shoppingCart = DBMapping(dbCollection); return(shoppingCart); }
public ShoppingCart GetCurrentShoppingCart(ShoppingCartTypeEnum shoppingCartType) { if (ShopContext.Current.Session == null) { return(new ShoppingCart()); } var customerSessionGuid = ShopContext.Current.Session.CustomerSessionGuid; return(GetShoppingCartByCustomerSessionGuid(shoppingCartType, customerSessionGuid)); }
/// <summary> /// Gets current user shopping cart /// </summary> /// <param name="ShoppingCartType">Shopping cart type</param> /// <returns>Cart</returns> public static ShoppingCart GetCurrentShoppingCart(ShoppingCartTypeEnum ShoppingCartType) { if (NopContext.Current.Session == null) { return(new ShoppingCart()); } Guid CustomerSessionGUID = NopContext.Current.Session.CustomerSessionGUID; return(GetShoppingCartByCustomerSessionGUID(ShoppingCartType, CustomerSessionGUID)); }
/// <summary> /// Gets shopping cart /// </summary> /// <param name="CustomerID">Customer identifier</param> /// <param name="ShoppingCartType">Shopping cart type</param> /// <returns>Cart</returns> public static ShoppingCart GetCustomerShoppingCart(int CustomerID, ShoppingCartTypeEnum ShoppingCartType) { CustomerSession customerSession = CustomerManager.GetCustomerSessionByCustomerID(CustomerID); if (customerSession == null) { return(new ShoppingCart()); } Guid CustomerSessionGUID = customerSession.CustomerSessionGUID; return(GetShoppingCartByCustomerSessionGUID(ShoppingCartType, CustomerSessionGUID)); }
/// <summary> /// Add a product variant to shopping cart /// </summary> /// <param name="shoppingCartType">Shopping cart type</param> /// <param name="productVariantId">Product variant identifier</param> /// <param name="selectedAttributes">Selected attributes</param> /// <param name="customerEnteredPrice">The price enter by a customer</param> /// <param name="quantity">Quantity</param> /// <returns>Warnings</returns> public List<string> AddToCart(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, decimal customerEnteredPrice, int quantity) { var warnings = new List<string>(); if (shoppingCartType == ShoppingCartTypeEnum.Wishlist && !IoC.Resolve<ISettingManager>().GetSettingValueBoolean("Common.EnableWishlist")) return warnings; if (NopContext.Current.Session == null) NopContext.Current.Session = NopContext.Current.GetSession(true); var customerSessionGuid = NopContext.Current.Session.CustomerSessionGuid; IoC.Resolve<ICustomerService>().ResetCheckoutData(NopContext.Current.Session.CustomerId, false); var cart = GetShoppingCartByCustomerSessionGuid(shoppingCartType, customerSessionGuid); ShoppingCartItem shoppingCartItem = null; foreach (var _shoppingCartItem in cart) { if (_shoppingCartItem.ProductVariantId == productVariantId) { //attributes bool attributesEqual = ProductAttributeHelper.AreProductAttributesEqual(_shoppingCartItem.AttributesXml, selectedAttributes); //gift cards bool giftCardInfoSame = true; if (_shoppingCartItem.ProductVariant.IsGiftCard) { string giftCardRecipientName1 = string.Empty; string giftCardRecipientEmail1 = string.Empty; string giftCardSenderName1 = string.Empty; string giftCardSenderEmail1 = string.Empty; string giftCardMessage1 = string.Empty; ProductAttributeHelper.GetGiftCardAttribute(selectedAttributes, out giftCardRecipientName1, out giftCardRecipientEmail1, out giftCardSenderName1, out giftCardSenderEmail1, out giftCardMessage1); string giftCardRecipientName2 = string.Empty; string giftCardRecipientEmail2 = string.Empty; string giftCardSenderName2 = string.Empty; string giftCardSenderEmail2 = string.Empty; string giftCardMessage2 = string.Empty; ProductAttributeHelper.GetGiftCardAttribute(_shoppingCartItem.AttributesXml, out giftCardRecipientName2, out giftCardRecipientEmail2, out giftCardSenderName2, out giftCardSenderEmail2, out giftCardMessage2); if (giftCardRecipientName1.ToLowerInvariant() != giftCardRecipientName2.ToLowerInvariant() || giftCardSenderName1.ToLowerInvariant() != giftCardSenderName2.ToLowerInvariant()) giftCardInfoSame = false; } //price is the same (for products which requires customers to enter a price) bool customerEnteredPricesEqual = true; if (_shoppingCartItem.ProductVariant.CustomerEntersPrice) { customerEnteredPricesEqual = Math.Round(_shoppingCartItem.CustomerEnteredPrice, 2) == Math.Round(customerEnteredPrice, 2); } if (attributesEqual && giftCardInfoSame && customerEnteredPricesEqual) shoppingCartItem = _shoppingCartItem; } } DateTime now = DateTime.UtcNow; if (shoppingCartItem != null) { int newQuantity = shoppingCartItem.Quantity + quantity; warnings.AddRange(GetShoppingCartItemWarnings(shoppingCartType, productVariantId, selectedAttributes, customerEnteredPrice, newQuantity)); if (warnings.Count == 0) { shoppingCartItem.ShoppingCartTypeId = (int)shoppingCartType; shoppingCartItem.CustomerSessionGuid = customerSessionGuid; shoppingCartItem.ProductVariantId = productVariantId; shoppingCartItem.AttributesXml = selectedAttributes; shoppingCartItem.Quantity = newQuantity; shoppingCartItem.UpdatedOn = now; UpdateShoppingCartItem(shoppingCartItem); } } else { warnings.AddRange(GetShoppingCartItemWarnings(shoppingCartType, productVariantId, selectedAttributes, customerEnteredPrice, quantity)); if (warnings.Count == 0) { //maximum items validation if (shoppingCartType == ShoppingCartTypeEnum.ShoppingCart) { if (cart.Count >= IoC.Resolve<ISettingManager>().GetSettingValueInteger("Common.MaximumShoppingCartItems", 1000)) { return warnings; } } else if (shoppingCartType == ShoppingCartTypeEnum.Wishlist) { if (cart.Count >= IoC.Resolve<ISettingManager>().GetSettingValueInteger("Common.MaximumWishlistItems", 1000)) { return warnings; } } //insert item shoppingCartItem = new ShoppingCartItem() { ShoppingCartTypeId = (int)shoppingCartType, CustomerSessionGuid = customerSessionGuid, ProductVariantId = productVariantId, AttributesXml = selectedAttributes, CustomerEnteredPrice = customerEnteredPrice, Quantity = quantity, CreatedOn = now, UpdatedOn = now }; InsertShoppingCartItem(shoppingCartItem); } } return warnings; }
/// <summary> /// Validates shopping cart item (gift card) /// </summary> /// <param name="shoppingCartType">Shopping cart type</param> /// <param name="productVariantId">Product variant identifier</param> /// <param name="selectedAttributes">Selected attributes</param> /// <returns>Warnings</returns> public List<string> GetShoppingCartItemGiftCardWarnings(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes) { var warnings = new List<string>(); var productVariant = IoC.Resolve<IProductService>().GetProductVariantById(productVariantId); if (productVariant == null) { warnings.Add(string.Format("Product variant (Id={0}) can not be loaded", productVariantId)); return warnings; } //gift cards if (productVariant.IsGiftCard) { string giftCardRecipientName = string.Empty; string giftCardRecipientEmail = string.Empty; string giftCardSenderName = string.Empty; string giftCardSenderEmail = string.Empty; string giftCardMessage = string.Empty; ProductAttributeHelper.GetGiftCardAttribute(selectedAttributes, out giftCardRecipientName, out giftCardRecipientEmail, out giftCardSenderName, out giftCardSenderEmail, out giftCardMessage); if (String.IsNullOrEmpty(giftCardRecipientName)) warnings.Add(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCartWarning.RecipientNameError")); if ((GiftCardTypeEnum)productVariant.GiftCardType == GiftCardTypeEnum.Virtual) { //validate for virtual gift cards only if (String.IsNullOrEmpty(giftCardRecipientEmail) || !CommonHelper.IsValidEmail(giftCardRecipientEmail)) warnings.Add(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCartWarning.RecipientEmailError")); } if (String.IsNullOrEmpty(giftCardSenderName)) warnings.Add(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCartWarning.SenderNameError")); if ((GiftCardTypeEnum)productVariant.GiftCardType == GiftCardTypeEnum.Virtual) { //validate for virtual gift cards only if (String.IsNullOrEmpty(giftCardSenderEmail) || !CommonHelper.IsValidEmail(giftCardSenderEmail)) warnings.Add(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCartWarning.SenderEmailError")); } } return warnings; }
/// <summary> /// Validates shopping cart item /// </summary> /// <param name="shoppingCartType">Shopping cart type</param> /// <param name="productVariantId">Product variant identifier</param> /// <param name="selectedAttributes">Selected attributes</param> /// <param name="customerEnteredPrice">Customer entered price</param> /// <param name="quantity">Quantity</param> /// <returns>Warnings</returns> public List<string> GetShoppingCartItemWarnings(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, decimal customerEnteredPrice, int quantity) { var warnings = new List<string>(); var productVariant = IoC.Resolve<IProductService>().GetProductVariantById(productVariantId); if (productVariant == null) { warnings.Add(string.Format("Product variant (Id={0}) can not be loaded", productVariantId)); return warnings; } var product = productVariant.Product; if (product == null) { warnings.Add(string.Format("Product (Id={0}) can not be loaded", productVariant.ProductId)); return warnings; } if (product.Deleted || productVariant.Deleted) { warnings.Add("Product is deleted"); return warnings; } if (!product.Published || !productVariant.Published) { warnings.Add("Product is not published"); } if (productVariant.DisableBuyButton) { warnings.Add("Buying is disabled"); } if (shoppingCartType == ShoppingCartTypeEnum.ShoppingCart && productVariant.CallForPrice) { warnings.Add(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("Products.CallForPrice")); } if (productVariant.CustomerEntersPrice) { if (customerEnteredPrice < productVariant.MinimumCustomerEnteredPrice || customerEnteredPrice > productVariant.MaximumCustomerEnteredPrice) { decimal minimumCustomerEnteredPrice = IoC.Resolve<ICurrencyService>().ConvertCurrency(productVariant.MinimumCustomerEnteredPrice, IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency, NopContext.Current.WorkingCurrency); decimal maximumCustomerEnteredPrice = IoC.Resolve<ICurrencyService>().ConvertCurrency(productVariant.MaximumCustomerEnteredPrice, IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency, NopContext.Current.WorkingCurrency); warnings.Add(string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.CustomerEnteredPrice.RangeError"), PriceHelper.FormatPrice(minimumCustomerEnteredPrice, false, false), PriceHelper.FormatPrice(maximumCustomerEnteredPrice, false, false))); } } if (quantity < productVariant.OrderMinimumQuantity) { warnings.Add(string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.MinimumQuantity"), productVariant.OrderMinimumQuantity)); } if (quantity > productVariant.OrderMaximumQuantity) { warnings.Add(string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.MaximumQuantity"), productVariant.OrderMaximumQuantity)); } switch ((ManageInventoryMethodEnum)productVariant.ManageInventory) { case ManageInventoryMethodEnum.DontManageStock: { } break; case ManageInventoryMethodEnum.ManageStock: { if ((BackordersModeEnum)productVariant.Backorders == BackordersModeEnum.NoBackorders) { if (productVariant.StockQuantity < quantity) { int maximumQuantityCanBeAdded = productVariant.StockQuantity; if (maximumQuantityCanBeAdded <= 0) warnings.Add(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.OutOfStock")); else warnings.Add(string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.QuantityExceedsStock"), maximumQuantityCanBeAdded)); } } } break; case ManageInventoryMethodEnum.ManageStockByAttributes: { var combination = IoC.Resolve<IProductAttributeService>().FindProductVariantAttributeCombination(productVariant.ProductVariantId, selectedAttributes); if (combination != null) { if (!combination.AllowOutOfStockOrders) { if (combination.StockQuantity < quantity) { int maximumQuantityCanBeAdded = combination.StockQuantity; if (maximumQuantityCanBeAdded <= 0) warnings.Add(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.OutOfStock")); else warnings.Add(string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.QuantityExceedsStock"), maximumQuantityCanBeAdded)); } } } } break; default: break; } //availability dates bool availableStartDateError = false; if (productVariant.AvailableStartDateTime.HasValue) { DateTime now = DateTime.UtcNow; DateTime availableStartDateTime = DateTime.SpecifyKind(productVariant.AvailableStartDateTime.Value, DateTimeKind.Utc); if (availableStartDateTime.CompareTo(now) > 0) { warnings.Add("Product is not available"); availableStartDateError = true; } } if (productVariant.AvailableEndDateTime.HasValue && !availableStartDateError) { DateTime now = DateTime.UtcNow; DateTime availableEndDateTime = DateTime.SpecifyKind(productVariant.AvailableEndDateTime.Value, DateTimeKind.Utc); if (availableEndDateTime.CompareTo(now) < 0) { warnings.Add("Product is not available"); } } //selected attributes warnings.AddRange(GetShoppingCartItemAttributeWarnings(shoppingCartType, productVariantId, selectedAttributes, quantity)); //gift cards warnings.AddRange(GetShoppingCartItemGiftCardWarnings(shoppingCartType, productVariantId, selectedAttributes)); return warnings; }
/// <summary> /// Validates shopping cart item attributes /// </summary> /// <param name="shoppingCartType">Shopping cart type</param> /// <param name="productVariantId">Product variant identifier</param> /// <param name="selectedAttributes">Selected attributes</param> /// <param name="quantity">Quantity</param> /// <returns>Warnings</returns> public List<string> GetShoppingCartItemAttributeWarnings(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, int quantity) { return GetShoppingCartItemAttributeWarnings(shoppingCartType, productVariantId, selectedAttributes, quantity, true); }
/// <summary> /// Validates shopping cart item attributes /// </summary> /// <param name="shoppingCartType">Shopping cart type</param> /// <param name="productVariantId">Product variant identifier</param> /// <param name="selectedAttributes">Selected attributes</param> /// <param name="quantity">Quantity</param> /// <param name="validateQuantity">Value indicating whether to validation quantity</param> /// <returns>Warnings</returns> public List<string> GetShoppingCartItemAttributeWarnings(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, int quantity, bool validateQuantity) { var warnings = new List<string>(); var productVariant = IoC.Resolve<IProductService>().GetProductVariantById(productVariantId); if (productVariant == null) { warnings.Add(string.Format("Product variant (Id={0}) can not be loaded", productVariantId)); return warnings; } //selected attributes var pva1Collection = ProductAttributeHelper.ParseProductVariantAttributes(selectedAttributes); foreach (var pva1 in pva1Collection) { var pv1 = pva1.ProductVariant; if (pv1 != null) { if (pv1.ProductVariantId != productVariant.ProductVariantId) { warnings.Add("Attribute error"); } } else { warnings.Add("Attribute error"); return warnings; } } //existing product attributes var pva2Collection = productVariant.ProductVariantAttributes; foreach (var pva2 in pva2Collection) { if (pva2.IsRequired) { bool found = false; //selected product attributes foreach (var pva1 in pva1Collection) { if (pva1.ProductVariantAttributeId == pva2.ProductVariantAttributeId) { var pvaValuesStr = ProductAttributeHelper.ParseValues(selectedAttributes, pva1.ProductVariantAttributeId); foreach (string str1 in pvaValuesStr) { if (!String.IsNullOrEmpty(str1.Trim())) { found = true; break; } } } } //if not found if (!found) { if (!string.IsNullOrEmpty(pva2.TextPrompt)) { warnings.Add(pva2.TextPrompt); } else { warnings.Add(string.Format(IoC.Resolve<ILocalizationManager>().GetLocaleResourceString("ShoppingCart.SelectAttribute"), pva2.ProductAttribute.LocalizedName)); } } } } return warnings; }
/// <summary> /// Gets shopping cart /// </summary> /// <param name="customerId">Customer identifier</param> /// <param name="shoppingCartType">Shopping cart type</param> /// <returns>Cart</returns> public static ShoppingCart GetCustomerShoppingCart(int customerId, ShoppingCartTypeEnum shoppingCartType) { var customerSession = CustomerManager.GetCustomerSessionByCustomerId(customerId); if (customerSession == null) return new ShoppingCart(); var customerSessionGuid = customerSession.CustomerSessionGuid; return GetShoppingCartByCustomerSessionGuid(shoppingCartType, customerSessionGuid); }
/// <summary> /// Gets a shopping cart by customer session GUId /// </summary> /// <param name="shoppingCartType">Shopping cart type</param> /// <param name="customerSessionGuid">The customer session identifier</param> /// <returns>Cart</returns> public ShoppingCart GetShoppingCartByCustomerSessionGuid(ShoppingCartTypeEnum shoppingCartType, Guid customerSessionGuid) { var query = from sci in _context.ShoppingCartItems orderby sci.CreatedOn where sci.ShoppingCartTypeId == (int)shoppingCartType && sci.CustomerSessionGuid == customerSessionGuid select sci; var scItems = query.ToList(); var shoppingCart = new ShoppingCart(); shoppingCart.AddRange(scItems); return shoppingCart; }
/// <summary> /// Validates whether this shopping cart item is allowed /// </summary> /// <param name="ShoppingCartType">Shopping cart type</param> /// <param name="ProductVariantID">Product variant identifier</param> /// <param name="SelectedAttributes">Selected attributes</param> /// <param name="Quantity">Quantity</param> /// <returns>Warnings</returns> public static List <string> GetShoppingCartItemWarnings(ShoppingCartTypeEnum ShoppingCartType, int ProductVariantID, string SelectedAttributes, int Quantity) { List <string> warnings = new List <string>(); ProductVariant productVariant = ProductManager.GetProductVariantByID(ProductVariantID); if (productVariant == null) { warnings.Add(string.Format("Product variant (ID={0}) can not be loaded", ProductVariantID)); return(warnings); } Product product = productVariant.Product; if (product == null) { warnings.Add(string.Format("Product (ID={0}) can not be loaded", productVariant.ProductID)); return(warnings); } if (product.Deleted || productVariant.Deleted) { warnings.Add("Product is deleted"); return(warnings); } if (!product.Published || !productVariant.Published) { warnings.Add("Product is not published"); } if (productVariant.DisableBuyButton) { warnings.Add("Buying is disabled"); } if (Quantity < productVariant.OrderMinimumQuantity) { warnings.Add(string.Format(LocalizationManager.GetLocaleResourceString("ShoppingCart.MinimumQuantity"), productVariant.OrderMinimumQuantity)); } if (Quantity > productVariant.OrderMaximumQuantity) { warnings.Add(string.Format(LocalizationManager.GetLocaleResourceString("ShoppingCart.MaximumQuantity"), productVariant.OrderMaximumQuantity)); } if (productVariant.ManageInventory) { if (productVariant.StockQuantity < Quantity) { int maximumQuantityCanBeAdded = productVariant.StockQuantity; warnings.Add(string.Format(LocalizationManager.GetLocaleResourceString("ShoppingCart.QuantityExceedsStock"), maximumQuantityCanBeAdded)); } } if (productVariant.AvailableStartDateTime.HasValue) { DateTime now = DateTimeHelper.ConvertToUtcTime(DateTime.Now); if (productVariant.AvailableStartDateTime.Value.CompareTo(now) > 0) { warnings.Add("Product is not available"); } } else if (productVariant.AvailableEndDateTime.HasValue) { DateTime now = DateTimeHelper.ConvertToUtcTime(DateTime.Now); if (productVariant.AvailableEndDateTime.Value.CompareTo(now) < 0) { warnings.Add("Product is not available"); } } //selected attributes ProductVariantAttributeCollection pva1Collection = ProductAttributeHelper.ParseProductVariantAttributes(SelectedAttributes); foreach (ProductVariantAttribute pva1 in pva1Collection) { ProductVariant pv1 = pva1.ProductVariant; if (pv1 != null) { if (pv1.ProductVariantID != productVariant.ProductVariantID) { warnings.Add("Attribute error"); } } else { warnings.Add("Attribute error"); return(warnings); } } //existing product attributes ProductVariantAttributeCollection pva2Collection = productVariant.ProductVariantAttributes; foreach (ProductVariantAttribute pva2 in pva2Collection) { if (pva2.IsRequired) { bool found = false; //selected attributes foreach (ProductVariantAttribute pva1 in pva1Collection) { if (pva1.ProductVariantAttributeID == pva2.ProductVariantAttributeID) { List <string> pvaValuesStr = ProductAttributeHelper.ParseValues(SelectedAttributes, pva1.ProductVariantAttributeID); foreach (string str1 in pvaValuesStr) { if (!String.IsNullOrEmpty(str1.Trim())) { found = true; break; } } } } //if not found if (!found) { if (!string.IsNullOrEmpty(pva2.TextPrompt)) { warnings.Add(pva2.TextPrompt); } else { warnings.Add(string.Format(LocalizationManager.GetLocaleResourceString("ShoppingCart.SelectAttribute"), pva2.ProductAttribute.Name)); } } } } return(warnings); }
public List <string> AddToCart(ShoppingCartTypeEnum shoppingCartType, int productId, int quantity) { throw new NotImplementedException(); }
public List <string> GetShoppingCartItemWarnings(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, decimal customerEnteredPrice, int quantity) { throw new NotImplementedException(); }
/// <summary> /// Inserts a shopping cart item /// </summary> /// <param name="shoppingCartType">The shopping cart type</param> /// <param name="customerSessionGuid">The customer session identifier</param> /// <param name="productVariantId">The product variant identifier</param> /// <param name="attributesXml">The product variant attributes</param> /// <param name="customerEnteredPrice">The price enter by a customer</param> /// <param name="quantity">The quantity</param> /// <param name="createdOn">The date and time of instance creation</param> /// <param name="updatedOn">The date and time of instance update</param> /// <returns>Shopping cart item</returns> internal static ShoppingCartItem InsertShoppingCartItem(ShoppingCartTypeEnum shoppingCartType, Guid customerSessionGuid, int productVariantId, string attributesXml, decimal customerEnteredPrice, int quantity, DateTime createdOn, DateTime updatedOn) { if (attributesXml == null) attributesXml = string.Empty; var context = ObjectContextHelper.CurrentObjectContext; var shoppingCartItem = context.ShoppingCartItems.CreateObject(); shoppingCartItem.ShoppingCartTypeId = (int)shoppingCartType; shoppingCartItem.CustomerSessionGuid = customerSessionGuid; shoppingCartItem.ProductVariantId = productVariantId; shoppingCartItem.AttributesXml = attributesXml; shoppingCartItem.CustomerEnteredPrice = customerEnteredPrice; shoppingCartItem.Quantity = quantity; shoppingCartItem.CreatedOn = createdOn; shoppingCartItem.UpdatedOn = updatedOn; context.ShoppingCartItems.AddObject(shoppingCartItem); context.SaveChanges(); if (shoppingCartItem != null) { if (shoppingCartItem.ShoppingCartType == ShoppingCartTypeEnum.ShoppingCart) { CustomerActivityManager.InsertActivity( "AddToShoppingCart", LocalizationManager.GetLocaleResourceString("ActivityLog.AddToShoppingCart"), shoppingCartItem.ProductVariant.FullProductName); } } return shoppingCartItem; }
public ShoppingCart GetCustomerShoppingCart(int customerId, ShoppingCartTypeEnum shoppingCartType) { throw new NotImplementedException(); }
public ShoppingCart GetCurrentShoppingCart(ShoppingCartTypeEnum shoppingCartType) { throw new NotImplementedException(); }
public ShoppingCart GetShoppingCartByCustomerSessionGuid(ShoppingCartTypeEnum shoppingCartType, Guid customerSessionGuid) { throw new NotImplementedException(); }
public ShoppingCart GetShoppingCartByCustomerSessionGuid(ShoppingCartTypeEnum shoppingCartType, Guid customerSessionGuid) { return(null); }
/// <summary> /// Gets shopping cart /// </summary> /// <param name="customerId">Customer identifier</param> /// <param name="shoppingCartType">Shopping cart type</param> /// <returns>Cart</returns> public ShoppingCart GetCustomerShoppingCart(int customerId, ShoppingCartTypeEnum shoppingCartType) { var customerSession = IoC.Resolve<ICustomerService>().GetCustomerSessionByCustomerId(customerId); if (customerSession == null) return new ShoppingCart(); var customerSessionGuid = customerSession.CustomerSessionGuid; return GetShoppingCartByCustomerSessionGuid(shoppingCartType, customerSessionGuid); }
public List <string> GetShoppingCartItemAttributeWarnings(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, int quantity, bool validateQuantity) { throw new NotImplementedException(); }
/// <summary> /// Updates the shopping cart item /// </summary> /// <param name="shoppingCartItemId">The shopping cart item identifier</param> /// <param name="shoppingCartType">The shopping cart type</param> /// <param name="customerSessionGuid">The customer session identifier</param> /// <param name="productVariantId">The product variant identifier</param> /// <param name="attributesXml">The product variant attributes</param> /// <param name="customerEnteredPrice">The price enter by a customer</param> /// <param name="quantity">The quantity</param> /// <param name="createdOn">The date and time of instance creation</param> /// <param name="updatedOn">The date and time of instance update</param> /// <returns>Shopping cart item</returns> internal static ShoppingCartItem UpdateShoppingCartItem(int shoppingCartItemId, ShoppingCartTypeEnum shoppingCartType, Guid customerSessionGuid, int productVariantId, string attributesXml, decimal customerEnteredPrice, int quantity, DateTime createdOn, DateTime updatedOn) { if (shoppingCartItemId == 0) return null; if (attributesXml == null) attributesXml = string.Empty; var shoppingCartItem = GetShoppingCartItemById(shoppingCartItemId); if (shoppingCartItem == null) return null; var context = ObjectContextHelper.CurrentObjectContext; if (!context.IsAttached(shoppingCartItem)) context.ShoppingCartItems.Attach(shoppingCartItem); shoppingCartItem.ShoppingCartTypeId = (int)shoppingCartType; shoppingCartItem.CustomerSessionGuid = customerSessionGuid; shoppingCartItem.ProductVariantId = productVariantId; shoppingCartItem.AttributesXml = attributesXml; shoppingCartItem.CustomerEnteredPrice = customerEnteredPrice; shoppingCartItem.Quantity = quantity; shoppingCartItem.CreatedOn = createdOn; shoppingCartItem.UpdatedOn = updatedOn; context.SaveChanges(); return shoppingCartItem; }
public List <string> GetShoppingCartItemGiftCardWarnings(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes) { throw new NotImplementedException(); }
/// <summary> /// Gets current user shopping cart /// </summary> /// <param name="shoppingCartType">Shopping cart type</param> /// <returns>Cart</returns> public ShoppingCart GetCurrentShoppingCart(ShoppingCartTypeEnum shoppingCartType) { if (NopContext.Current.Session == null) return new ShoppingCart(); var customerSessionGuid = NopContext.Current.Session.CustomerSessionGuid; return GetShoppingCartByCustomerSessionGuid(shoppingCartType, customerSessionGuid); }
/// <summary> /// Add a product variant to shopping cart /// </summary> /// <param name="ShoppingCartType">Shopping cart type</param> /// <param name="ProductVariantID">Product variant identifier</param> /// <param name="SelectedAttributes">Selected attributes</param> /// <param name="Quantity">Quantity</param> /// <returns>Warnings</returns> public static List <string> AddToCart(ShoppingCartTypeEnum ShoppingCartType, int ProductVariantID, string SelectedAttributes, int Quantity) { List <string> warnings = new List <string>(); if (ShoppingCartType == ShoppingCartTypeEnum.Wishlist && !SettingManager.GetSettingValueBoolean("Common.EnableWishlist")) { return(warnings); } if (NopContext.Current.Session == null) { NopContext.Current.Session = NopContext.Current.GetSession(true); } Guid CustomerSessionGUID = NopContext.Current.Session.CustomerSessionGUID; CustomerManager.ResetCheckoutData(NopContext.Current.Session.CustomerID, false); ShoppingCart Cart = GetShoppingCartByCustomerSessionGUID(ShoppingCartType, CustomerSessionGUID); ShoppingCartItem shoppingCartItem = null; foreach (ShoppingCartItem _shoppingCartItem in Cart) { if (_shoppingCartItem.ProductVariantID == ProductVariantID) { if (ProductAttributeHelper.ParseProductVariantAttributeIDs(_shoppingCartItem.AttributesXML).Count == ProductAttributeHelper.ParseProductVariantAttributeIDs(SelectedAttributes).Count) { bool attributeEquals = true; ProductVariantAttributeCollection pva1Collection = ProductAttributeHelper.ParseProductVariantAttributes(SelectedAttributes); ProductVariantAttributeCollection pva2Collection = ProductAttributeHelper.ParseProductVariantAttributes(_shoppingCartItem.AttributesXML); foreach (ProductVariantAttribute pva1 in pva1Collection) { foreach (ProductVariantAttribute pva2 in pva2Collection) { if (pva1.ProductVariantAttributeID == pva2.ProductVariantAttributeID) { List <string> pvaValues1Str = ProductAttributeHelper.ParseValues(SelectedAttributes, pva1.ProductVariantAttributeID); List <string> pvaValues2Str = ProductAttributeHelper.ParseValues(_shoppingCartItem.AttributesXML, pva2.ProductVariantAttributeID); if (pvaValues1Str.Count == pvaValues2Str.Count) { foreach (string str1 in pvaValues1Str) { bool hasAttribute = false; foreach (string str2 in pvaValues2Str) { if (str1.Trim().ToLower() == str2.Trim().ToLower()) { hasAttribute = true; break; } } if (!hasAttribute) { attributeEquals = false; break; } } } else { attributeEquals = false; break; } } } } if (attributeEquals) { shoppingCartItem = _shoppingCartItem; } } } } DateTime now = DateTime.Now; if (shoppingCartItem != null) { int newQuantity = shoppingCartItem.Quantity + Quantity; warnings.AddRange(GetShoppingCartItemWarnings(ShoppingCartType, ProductVariantID, SelectedAttributes, newQuantity)); if (warnings.Count == 0) { UpdateShoppingCartItem(shoppingCartItem.ShoppingCartItemID, ShoppingCartType, CustomerSessionGUID, ProductVariantID, SelectedAttributes, newQuantity, shoppingCartItem.CreatedOn, now); } } else { warnings.AddRange(GetShoppingCartItemWarnings(ShoppingCartType, ProductVariantID, SelectedAttributes, Quantity)); if (warnings.Count == 0) { InsertShoppingCartItem(ShoppingCartType, CustomerSessionGUID, ProductVariantID, SelectedAttributes, Quantity, now, now); } } return(warnings); }
public static List <ShoppingCartItem> GetByUserGuid(int siteId, ShoppingCartTypeEnum cartType, Guid userGuid) { IDataReader reader = DBShoppingCartItem.GetByUserGuid(siteId, (int)cartType, userGuid); return(LoadListFromReader(reader)); }