/// <summary> /// Handles the ItemDeleting event of the lvCartItems control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.ListViewDeleteEventArgs"/> instance containing the event data.</param> protected void lvCartItems_ItemDeleting(object sender, ListViewDeleteEventArgs e) { int lineItemId; if (Int32.TryParse(lvCartItems.DataKeys[e.ItemIndex].Value.ToString(), out lineItemId)) { if (!CartHelper.IsEmpty) { foreach (LineItem item in CartHelper.LineItems) { if (item.LineItemId == lineItemId) { item.Delete(); } } } // If cart is empty, remove it from the database if (CartHelper.IsEmpty) { CartHelper.Delete(); } Session.Remove(Constants.LastCouponCode); CartHelper.Cart.AcceptChanges(); Context.RedirectFast(Request.RawUrl); } else { e.Cancel = true; } }
/// <summary> /// Default bind data method. /// </summary> private void BindData() { var isEmpty = CartHelper.IsEmpty; // Make sure to check that prices has not changed if (!isEmpty) { // restore coupon code to context string couponCode = Session[Constants.LastCouponCode] as string; if (!String.IsNullOrEmpty(couponCode)) { MarketingContext.Current.AddCouponToMarketingContext(couponCode); } CartHelper.Cart.ProviderId = "FrontEnd"; CartHelper.RunWorkflow(Constants.CartValidateWorkflowName); // If cart is empty, remove it from the database isEmpty = CartHelper.IsEmpty; if (isEmpty) { CartHelper.Delete(); } CartHelper.Cart.AcceptChanges(); } if (!isEmpty) { lvCartItems.DataSource = CartHelper.LineItems; _promotionResult = CartHelper.GetPromotions(); } lvCartItems.DataBind(); }
/// <summary> /// Profile migrate from anonymous. /// </summary> /// <param name="sender">The sender.</param> /// <param name="pe">The <see cref="ProfileMigrateEventArgs"/> instance containing the event data.</param> private void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe) { var client = ServiceLocator.Current.GetInstance <OrderClient>(); var orders = client.GetAllCustomerOrders(pe.AnonymousID, UserHelper.CustomerSession.StoreId); if (orders != null) { foreach (var order in orders) { order.CustomerId = UserHelper.CustomerSession.CustomerId; order.CustomerName = UserHelper.CustomerSession.CustomerName; } client.SaveChanges(); } // Migrate shopping cart var cart = new CartHelper(CartHelper.CartName); var anonymousCart = new CartHelper(CartHelper.CartName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousCart.IsEmpty) { // Merge cart cart.Add(anonymousCart.Cart, true); cart.SaveChanges(); // Delete anonymous cart anonymousCart.Delete(); anonymousCart.SaveChanges(); } var wishList = new CartHelper(CartHelper.WishListName); var anonymousWishList = new CartHelper(CartHelper.WishListName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousWishList.IsEmpty) { // Merge wish list wishList.Add(anonymousWishList.Cart, true); if (String.IsNullOrEmpty(wishList.Cart.BillingCurrency)) { wishList.Cart.BillingCurrency = UserHelper.CustomerSession.Currency; } wishList.SaveChanges(); // Delete anonymous wish list anonymousWishList.Delete(); anonymousWishList.SaveChanges(); } //Delete the anonymous data from the database //ProfileManager.DeleteProfile(pe.AnonymousID); //Remove the anonymous identifier from the request so //this event will no longer fire for a logged-in user AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
public ActionResult ClearWishList(WishListPage currentPage) { CartHelper ch = new CartHelper(CartHelper.WishListName); ch.Delete(); ch.Cart.AcceptChanges(); return(RedirectToAction("Index")); }
public CartActionResult EmptyCart(string name) { CartHelper ch = new CartHelper(name); ch.Delete(); ch.Cart.AcceptChanges(); return(new CartActionResult() { Success = true }); }
/// <summary> /// Handles the ItemCommand event of the lvCartItems control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ListViewCommandEventArgs"/> instance containing the event data.</param> protected void lvCartItems_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName != "Wishlist") { return; } int lineItemId; if (!Int32.TryParse(lvCartItems.DataKeys[e.Item.DataItemIndex].Value.ToString(), out lineItemId)) { return; } var cart = new CartHelper(Cart.DefaultName); foreach (var item in cart.LineItems) { if (item.LineItemId != lineItemId) { continue; } var qty = item.Quantity; var helper = new CartHelper(CartHelper.WishListName); var entry = CatalogContext.Current.GetCatalogEntry(item.CatalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (entry == null) { continue; } helper.AddEntry(entry, qty, true); item.Delete(); } // If cart is empty, remove it from the database if (CartHelper.IsEmpty) { CartHelper.Delete(); } // Save changes cart.Cart.AcceptChanges(); BindData(); //Move to Wish-List Context.RedirectFast(GetUrl(Settings.WishListPage)); }
public void DeleteCart() { var cart = CartHelper.Cart; foreach (OrderForm orderForm in cart.OrderForms) { foreach (Shipment shipment in orderForm.Shipments) { shipment.Delete(); } orderForm.Delete(); } foreach (OrderAddress address in cart.OrderAddresses) { address.Delete(); } CartHelper.Delete(); cart.AcceptChanges(); }
public CartActionResult EmptyCart(string name) { CartHelper ch = new CartHelper(name); ch.Delete(); ch.Cart.AcceptChanges(); return new CartActionResult() { Success = true }; }