public ShippingMethodCollectionCacheContext(Customer customer, Address address, CartItemCollection cartItems, int storeId) { Customer = customer; Address = address; CartItems = cartItems; StoreId = storeId; }
public CartController() { itemColl = new CartItemCollection(); drinkColl = new DrinkCollection(); specificColl = new CartItemSpecificsCollection(); DVM = new List <CartItemViewModel>(); }
public ShippingMethodCollection Get(Customer customer, Address address, CartItemCollection cartItems, int storeId) { return(CachedObjectProvider.Get(new ShippingMethodCollectionCacheContext( customer: customer, address: address, cartItems: cartItems, storeId: storeId))); }
public CustomerController() { customerCollection = new CustomerCollection(); itemColl = new CartItemCollection(); drinkColl = new DrinkCollection(); CIM = new List <CartItemModel>(); cartColl = new ShoppingCartCollection(); }
public AdminController() { cartColl = new ShoppingCartCollection(); itemColl = new CartItemCollection(); drinkColl = new DrinkCollection(); customerColl = new CustomerCollection(); specificColl = new CartItemSpecificsCollection(); CIVM = new List <CartItemViewModel>(); drinkVal = new DrinkValidation(); }
public void AddProductToCart(int productId, int productQty, string jsonProductFieldData) { //UpdateCartItemInCart(null, productId, productQty, true, jsonProductFieldData); DataModel.Cart cart = null; using (esTransactionScope transaction = new esTransactionScope()) { cart = GetCartFromDatabase(true); CartItemCollection cartItemCollection = cart.CartItemCollectionByCartId; List <CartItem> cartItems = cartItemCollection.ToList(); int index = cartItems.FindIndex(ci => (ci.ProductId.Value == productId) && (ci.ProductFieldData == jsonProductFieldData)); if (index >= 0) { // product is in the cart if (productQty <= 0) { // remove from cart cartItemCollection[index].MarkAsDeleted(); } else { // add/update quantity cartItemCollection[index].Quantity += productQty; // update ProductFieldData if (!string.IsNullOrEmpty(jsonProductFieldData)) { cartItemCollection[index].ProductFieldData = jsonProductFieldData; } } } else if (productQty > 0) { // add to cart CartItem newItem = cartItemCollection.AddNew(); newItem.ProductId = productId; newItem.Quantity = productQty; newItem.ProductFieldData = jsonProductFieldData; } //---- update some cart fields too... if (storeContext.UserId.HasValue) { cart.UserId = storeContext.UserId.Value; } cart.Save(); transaction.Complete(); } //return cart; }
public ActionResult Save(Bam.Net.Data.Tests.CartItem[] values) { try { CartItemCollection saver = new CartItemCollection(); saver.AddRange(values); saver.Save(); return(Json(new { Success = true, Message = "", Dao = "" })); } catch (Exception ex) { return(GetErrorResult(ex)); } }
public void RemoveCartItemFromCart(int cartItemId) { //UpdateCartItemInCart(cartItemId, null, 0, false, string.Empty); DataModel.Cart cart = GetCartFromDatabase(false); CartItemCollection cartItemCollection = cart.CartItemCollectionByCartId; CartItem toDelete = cartItemCollection.FindByPrimaryKey(cartItemId); if (toDelete != null) { toDelete.MarkAsDeleted(); cart.Save(); } }
protected void ctrlMiniCart_OnMiniCartItemUpdate(object sender, EventArgs e) { ShoppingCartControl ctrlMiniCart = this.FindControl("ctrlMiniCart") as ShoppingCartControl; int quantity = 0; int sRecID = 0; string itemNotes = string.Empty; CartItemCollection cartItemsCopy = null; for (int i = 0; i < ctrlMiniCart.Items.Count; i++) { quantity = ctrlMiniCart.Items[i].Quantity; sRecID = ctrlMiniCart.Items[i].ShoppingCartRecId; itemNotes = ctrlMiniCart.Items[i].ItemNotes; //prevent negative quantities if (quantity > 0) { cart.SetItemQuantity(sRecID, quantity); cart.SetItemNotes(sRecID, CommonLogic.CleanLevelOne(itemNotes)); } else { cart.SetItemQuantity(sRecID, 0); cart.SetItemNotes(sRecID, CommonLogic.CleanLevelOne(itemNotes)); } cart.CheckMinimumQuantities(ThisCustomer.CustomerID); cartItemsCopy = cart.CartItems; } cart = new ShoppingCart(ThisCustomer.SkinID, ThisCustomer, CartTypeEnum.ShoppingCart, 0, false, true); foreach (var a in cartItemsCopy.Where(n => n.MinimumQuantityUdpated.Equals(true))) { for (int i = 0; i < cart.CartItems.Count; i++) { if (cart.CartItems[i].ShoppingCartRecordID == a.ShoppingCartRecordID) { cart.CartItems[i].MinimumQuantityUdpated = a.MinimumQuantityUdpated; break; } } } BindMiniCart(); }
public void DoRegistryQuantityDeduction(CartItemCollection cartItems) { foreach (var cartItem in cartItems) { if (!cartItem.GiftRegistryID.HasValue) { continue; } decimal quatityToremove = cartItem.m_Quantity; //to avoid negative value upon deduction decimal?trueQuantity = cartItem.RegistryItemQuantity; if (trueQuantity < cartItem.m_Quantity) { quatityToremove = trueQuantity.Value; } GiftRegistryDA.DeductGiftRegistryItemQuantity(cartItem.GiftRegistryID.Value, cartItem.RegistryItemCode.Value, quatityToremove, cartItem.m_Quantity); } }
public void UpdateCartItemQuantity(int cartItemId, int quantity) { //UpdateCartItemInCart(cartItemId, null, quantity, false, string.Empty); using (esTransactionScope transaction = new esTransactionScope()) { DataModel.Cart cart = GetCartFromDatabase(false); CartItemCollection cartItems = cart.CartItemCollectionByCartId; cartItems.Filter = cartItems.AsQueryable().Where(x => x.Id == cartItemId); //cartItems.Filter = CartItemMetadata.ColumnNames.Id + " = " + cartItemId; if (cartItems.Count > 0) { // item is in the cart if (quantity <= 0) { // remove from cart cartItems[0].MarkAsDeleted(); } else { cartItems[0].Quantity = quantity; } } //cartItems.Filter = ""; cartItems.Filter = null; //---- update some cart fields too... if (storeContext.UserId.HasValue) { cart.UserId = storeContext.UserId.Value; } cart.Save(); transaction.Complete(); } }
public ShippingCalculationContext( Customer customer, Address shippingAddress, CartItemCollection cartItems, decimal taxRate, bool shippingIsFreeIfIncludedInFreeList, decimal handlingExtraFee, bool excludeZeroFreightCosts, int storeId, decimal weight, CartSubtotalDelegate cartSubtotal) { Customer = customer; ShippingAddress = shippingAddress; CartItems = cartItems; TaxRate = taxRate; ShippingIsFreeIfIncludedInFreeList = shippingIsFreeIfIncludedInFreeList; HandlingExtraFee = handlingExtraFee; ExcludeZeroFreightCosts = excludeZeroFreightCosts; StoreId = storeId; Weight = weight; CartSubtotal = cartSubtotal; }
public ShippingCalculationContext( ShippingCalculationContext source, Customer customer = null, Address shippingAddress = null, CartItemCollection cartItems = null, decimal?taxRate = null, bool?shippingIsFreeIfIncludedInFreeList = null, decimal?handlingExtraFee = null, bool?excludeZeroFreightCosts = null, int?storeId = null, decimal?weight = null, CartSubtotalDelegate cartSubtotal = null) { Customer = customer ?? source.Customer; ShippingAddress = shippingAddress ?? source.ShippingAddress; CartItems = cartItems ?? source.CartItems; TaxRate = taxRate ?? source.TaxRate; ShippingIsFreeIfIncludedInFreeList = shippingIsFreeIfIncludedInFreeList ?? source.ShippingIsFreeIfIncludedInFreeList; HandlingExtraFee = handlingExtraFee ?? source.HandlingExtraFee; ExcludeZeroFreightCosts = excludeZeroFreightCosts ?? source.ExcludeZeroFreightCosts; StoreId = storeId ?? source.StoreId; Weight = weight ?? source.Weight; CartSubtotal = cartSubtotal ?? source.CartSubtotal; }
/// <summary> /// Processes individual line items in the address select list and reconciles it with the ShoppingCart line items /// </summary> private void ProcessCartItemAddresses() { /******************************************************************************* * 1. CartItem and address not modified * - Leave as is * 2. CartItem and address are modified * - Find out if this is the only CartItem * - Qty = 1 : only modify the shipping address * - Qty > 1 : Add another line item cloning the original line item *******************************************************************************/ // Data-Structure that will hold all shippingAddress selected for a particular shipping address // Key = The address id // Value = Collection of CartItems marked to ship to that Address Dictionary <int, CartItemCollection> itemsPerAddress = new Dictionary <int, CartItemCollection>(); CartItemCollection individualBoundItems = ctrlCartItemAddresses.DataSource as CartItemCollection; Dictionary <int, KitComposition> Compositions = new Dictionary <int, KitComposition>(); for (int ctr = 0; ctr < individualBoundItems.Count; ctr++) { CartItem boundItem = individualBoundItems[ctr]; //gather compositions so that we can reference the original later if (boundItem.IsAKit && !Compositions.ContainsKey(boundItem.ShoppingCartRecordID)) { Compositions.Add(boundItem.ShoppingCartRecordID, KitComposition.FromCart(ThisCustomer, CartTypeEnum.ShoppingCart, boundItem.ShoppingCartRecordID)); } if (boundItem.Shippable) { // get the selected address id from the address drop down int preferredAddress = 0; DropDownList cboShipToAddress = ctrlCartItemAddresses.Items[ctr].FindControl("cboShipToAddress") as DropDownList; HtmlInputHidden ihiddenAddressOption = ctrlCartItemAddresses.Items[ctr].FindControl("ShipAddressOption") as HtmlInputHidden; if (!Boolean.Parse(ihiddenAddressOption.Value)) { preferredAddress = AppLogic.GiftRegistryShippingAddressID(boundItem.GiftRegistryForCustomerID); } else { if (cboShipToAddress != null) { if (int.TryParse(cboShipToAddress.SelectedValue, out preferredAddress)) { // check to see if the address was modified if (boundItem.ShippingAddressID != preferredAddress) { if (!itemsPerAddress.ContainsKey(preferredAddress)) { itemsPerAddress.Add(preferredAddress, new CartItemCollection()); } CartItemCollection itemsInThisAddress = itemsPerAddress[preferredAddress]; // check if we duplicates if (!itemsInThisAddress.Contains(boundItem)) { // first line item found for this address itemsInThisAddress.Add(boundItem); boundItem.MoveableQuantity = 1; } else { // we have multiple line items that are marked // to ship to this address, increment boundItem.MoveableQuantity++; } } } } } } else { // non-shippable item // ship this to primary if not yet set.. // get the original cartItem from the ShoppingCart line items CartItem originalCartItem = cart.CartItems.Find(boundItem.ShoppingCartRecordID); if (originalCartItem != null) { cart.SetItemAddress(originalCartItem.ShoppingCartRecordID, ThisCustomer.PrimaryShippingAddressID); } } } foreach (int preferredAddress in itemsPerAddress.Keys) { foreach (CartItem item in itemsPerAddress[preferredAddress]) { // get the original cartItem from the ShoppingCart line items CartItem originalCartItem = cart.CartItems.Find(item.ShoppingCartRecordID); if (originalCartItem == null) { continue; } // reset the quantity for the original line item that got sliced int resetQuantity = originalCartItem.Quantity - item.MoveableQuantity; KitComposition itemKitComposition = null; if (item.IsAKit && Compositions.ContainsKey(item.ShoppingCartRecordID)) { itemKitComposition = Compositions[item.ShoppingCartRecordID]; } if (resetQuantity == 0 || item.IsGift) { cart.SetItemAddress(originalCartItem.ShoppingCartRecordID, preferredAddress); } else { cart.SetItemQuantity(originalCartItem.ShoppingCartRecordID, resetQuantity); // now duplicate the line item but for this shipping address cart.AddItem(ThisCustomer, preferredAddress, item.ProductID, item.VariantID, item.MoveableQuantity, item.ChosenColor, item.ChosenColorSKUModifier, item.ChosenSize, item.ChosenSizeSKUModifier, item.TextOption, CartTypeEnum.ShoppingCart, false, false, item.GiftRegistryForCustomerID, item.CustomerEntersPrice ? item.Price : decimal.Zero, itemKitComposition, item.IsGift); } } } }
public ShippingMethodCollection GetShippingMethods(Customer customer, Address address, CartItemCollection cartItems, int storeId) { if (!cartItems.Any()) { return(new ShippingMethodCollection()); } if (cartItems.IsAllDownloadComponents()) { return(new ShippingMethodCollection()); } if (cartItems.IsAllSystemComponents()) { return(new ShippingMethodCollection()); } if (cartItems.NoShippingRequiredComponents()) { return(new ShippingMethodCollection()); } if (cartItems.IsAllEmailGiftCards()) { return(new ShippingMethodCollection()); } if (!AppLogic.AppConfigBool("FreeShippingAllowsRateSelection") && cartItems.IsAllFreeShippingComponents()) { return(new ShippingMethodCollection()); } var shippingCalculation = AspDotNetStorefrontCore.Shipping.GetActiveShippingCalculation(); if (shippingCalculation == null) { return(new ShippingMethodCollection()); } var returnInStorePickupRate = (shippingCalculation.GetType() == typeof(UseRealTimeRatesShippingCalculation)) && //In-Store Pickup is only allowed with realtime rates AppLogic.AppConfigBool("RTShipping.AllowLocalPickup"); var appliedStoreId = AppLogic.GlobalConfigBool("AllowShippingFiltering") ? storeId : AspDotNetStorefrontCore.Shipping.DONT_FILTER_PER_STORE; var cart = cartItems.First().ThisShoppingCart; var shippingCalculationContext = new ShippingCalculationContext( customer: customer, cartItems: cartItems, shippingAddress: address, taxRate: cart.VatIsInclusive ? customer.TaxRate(AppLogic.AppConfigUSInt("ShippingTaxClassID")) / 100m : 0, excludeZeroFreightCosts: AppLogic.AppConfigBool("FilterOutShippingMethodsThatHave0Cost"), shippingIsFreeIfIncludedInFreeList: cart.ShippingIsFree, handlingExtraFee: AppLogic.AppConfigUSDecimal("ShippingHandlingExtraFee"), storeId: appliedStoreId, weight: cart.WeightTotal(), cartSubtotal: cart.SubTotal); var availableShippingMethods = shippingCalculation.GetShippingMethods(shippingCalculationContext); if (returnInStorePickupRate && LocalPickupAvailable(address)) { availableShippingMethods.Add(new ShippingMethod { Name = "In-Store Pickup", Freight = AppLogic.AppConfigNativeDecimal("RTShipping.LocalPickupCost"), ShippingIsFree = AppLogic.AppConfigNativeDecimal("RTShipping.LocalPickupCost") == 0, }); } if (!availableShippingMethods.Any() && appliedStoreId != AspDotNetStorefrontCore.Shipping.DONT_FILTER_PER_STORE) { // no shipping methods found, let's try and fallback to the default store // (if we're not already in it) // when we're on a multi-store scenario var stores = Store.GetStoreList(); var defaultStore = Store.GetDefaultStore(); if (stores.Count > 1 && defaultStore != null && defaultStore.StoreID != appliedStoreId) { availableShippingMethods = shippingCalculation.GetShippingMethods(new ShippingCalculationContext( source: shippingCalculationContext, storeId: defaultStore.StoreID)); } // log if we still didn't find any shipping methods if (!availableShippingMethods.Any()) { var message = string.Format("No Shipping method found for StoreId: {0}", appliedStoreId); var logDetails = customer.IsRegistered ? string.Format(@" StoreId: {0} CalculationMode: {1} CustomerId: {2} Address: {3}" , appliedStoreId, AspDotNetStorefrontCore.Shipping.GetActiveShippingCalculationID(), customer.CustomerID, address.DisplayHTML(true)) : string.Empty; SysLog.LogMessage(message, logDetails, MessageTypeEnum.Informational, MessageSeverityEnum.Alert); } } //Filter out non-free shipping methods if necessary if (cart.ShippingIsFree && !AppLogic.AppConfigBool("FreeShippingAllowsRateSelection")) { var freeShippingMethodIds = AppLogic.AppConfig("ShippingMethodIDIfFreeShippingIsOn").ParseAsDelimitedList <int>(); if (freeShippingMethodIds.Any()) { availableShippingMethods.RemoveAll(sm => !freeShippingMethodIds.Contains(sm.Id)); } } //Apply shipping promotion discounts if any var shippingDiscounts = cart.DiscountResults.SelectMany(p => p.Promotion.PromotionDiscounts.OfType <Promotions.ShippingPromotionDiscount>()); if (shippingDiscounts.Any()) { foreach (var shippingMethod in availableShippingMethods) { ApplyShippingPromotion(shippingMethod, shippingDiscounts); } } return(availableShippingMethods); }
/// <summary> /// Creates the child controls in a control derived from System.Web.UI.WebControls.CompositeControl. /// </summary> protected override void CreateChildControls() { Controls.Clear(); IntializeControlsDefaultValues(); /********************************/ /******** CREATE CONTROLS *******/ /********************************/ //*********************// //*** USE TEMPLATES ***// //*********************// //outer box string style = string.Empty; style = "shopping_cart"; Controls.Add(new LiteralControl("<table style='width: 100%' cellpadding='0' cellspacing='0' border='0'>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td class=\"" + style + "\" >")); //if the page developer does not explicitly add a <HeaderTemplate> tag //in ShoppingCartControl's declarative syntax if (HeaderTemplate == null) { if (this.DesignMode) { ITemplate defaultTemplate = new MobileDefaultHeaderTemplate("Product", "Quantity", "SubTotal", "Delete"); defaultTemplate.InstantiateIn(this); } else { if (this.DataSource != null) { CartItemCollection cic = this.DataSource; if (cic.Count != 0) { ITemplate defaultTemplate = new MobileDefaultHeaderTemplate("Product", "Quantity", "SubTotal", "Delete"); defaultTemplate.InstantiateIn(this); } else { Topic emptyCartTopic = new Topic(this.EmptyCartTopicName); ITemplate defaultTemplate = new MobileDefaultHeaderTemplate(emptyCartTopic.Contents); defaultTemplate.InstantiateIn(this); } } else { ITemplate defaultTemplate = new MobileDefaultHeaderTemplate("Product", "Quantity", "SubTotal", "Delete"); defaultTemplate.InstantiateIn(this); } } } else { if (this.DataSource != null) { CartItemCollection cic = (CartItemCollection)this.DataSource; if (cic.Count != 0) { CustomTemplate headerTemplateItem = new CustomTemplate(); headerTemplateItem.ID = "headerTemplateItem"; HeaderTemplate.InstantiateIn(headerTemplateItem); Controls.Add(new LiteralControl(" <table style='width : 100%;' cellpadding='0' cellspacing='0' border='0'>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td>")); Controls.Add(headerTemplateItem); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl(" </table>")); } else { Topic emptyCartTopic = new Topic(this.EmptyCartTopicName); ITemplate defaultTemplate = new MobileDefaultHeaderTemplate(emptyCartTopic.Contents); defaultTemplate.InstantiateIn(this); } } else { CustomTemplate headerTemplateItem = new CustomTemplate(); headerTemplateItem.ID = "headerTemplateItem"; HeaderTemplate.InstantiateIn(headerTemplateItem); Controls.Add(new LiteralControl(" <table style='width : 100%;' cellpadding='0' cellspacing='0' border='0'>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td>")); Controls.Add(headerTemplateItem); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl(" </table>")); } } ShoppingCart cart = null; //ITEMS Template if (DataSource != null) { Items.Clear(); int alternateItem = 0; CartItemCollection sortedCartItemForMinicart = new CartItemCollection(); sortedCartItemForMinicart = this.DataSource; Panel pnlItems = new Panel(); pnlItems.ID = "pnlCartItems"; pnlItems.CssClass = "cart_items"; foreach (CartItem cItem in sortedCartItemForMinicart) { cart = cItem.ThisShoppingCart; if (alternateItem > 0) { // alternating separator pnlItems.Controls.Add(new LiteralControl("<div style='border-top: solid 1px #444444'></div>")); } item = new MobileShoppingCartControlItem(this.LineItemSettings); item.CartItem = cItem; item.AllowEdit = this.AllowEdit; item.DisplayMode = this.DisplayMode; if (cItem.ThisShoppingCart.CartType == CartTypeEnum.Deleted) { item.IsDeleted = true; } Items.Add(item); pnlItems.Controls.Add(item); alternateItem++; } Controls.Add(pnlItems); } if (DesignMode) { Controls.Add(new LiteralControl("<table style='width: 100%;' cellpadding='0' cellspacing='0' border='0'>")); Controls.Add(new LiteralControl(" <tr>")); //dummy line item description Controls.Add(new LiteralControl(" <td style='width:60%' valign='top'>")); Controls.Add(new LiteralControl(" <table style='width: 100%;' cellpadding='0' cellspacing='0' border='0'>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td>Product Name : Unbound</td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td>SKU : Unbound</td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td>Size : Unbound</td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td>Color : Unbound</td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl(" </table>")); Controls.Add(new LiteralControl(" </td>")); //dummy quantity & delete button TextBox txtQuantity = new TextBox(); txtQuantity.Text = "Unbound"; LinkButton lnkDelete = new LinkButton(); lnkDelete.Text = "shoppingcart.cs.107".StringResource(); Controls.Add(new LiteralControl(" <td style='width:15%' valign='top'>")); Controls.Add(txtQuantity); Controls.Add(lnkDelete); Controls.Add(new LiteralControl(" </td>")); //dummy extended price Controls.Add(new LiteralControl(" <td style='width:25%;' align='right' valign='top'>Unbound")); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl("</table>")); } else { if (FooterTemplate == null) { ITemplate defaultTemplate = new DefaulFooterTemplate(); defaultTemplate.InstantiateIn(this); } else { CustomTemplate footerTemplateItem = new CustomTemplate(); footerTemplateItem.ID = "footerTemplateItem"; FooterTemplate.InstantiateIn(footerTemplateItem); Controls.Add(new LiteralControl("<div>")); Controls.Add(footerTemplateItem); Controls.Add(new LiteralControl("</div>")); } } //end outer box Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl("</table>")); }