/// <summary>
        /// Handles the PostAcquireRequestState event of the context control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        void context_PostAcquireRequestState(object sender, EventArgs e)
        {
            if (IsResourceFile() || IsWebApi)
                return;

            var application = (HttpApplication)sender;
            var context = application.Context;

            var session = CustomerSession;
            Populate(context, session);

            //Price list can only be evaluated after all customer tagsets are ready
            var priceListHelper = DependencyResolver.Current.GetService<PriceListClient>();
            var priceLists = priceListHelper.GetPriceListStack(session.CatalogId, session.Currency, session.GetCustomerTagSet());
            session.Pricelists = priceLists;

            //Update prices in current currency
            var helper = new CartHelper(CartHelper.CartName);
            if (!helper.IsEmpty && 
                !string.IsNullOrEmpty(session.Currency) && 
                !string.IsNullOrEmpty(helper.Cart.BillingCurrency) && 
                session.Currency != helper.Cart.BillingCurrency)
            {
                helper.RunWorkflow("ShoppingCartValidateWorkflow");
                helper.SaveChanges();
            }


        }
Exemplo n.º 2
0
        public HttpResponseMessage EstimatePost(ShippingEstimateModel shippingEstimateModel)
        {
            if (ModelState.IsValid)
            {
                var helper = new CartHelper(CartHelper.CartName);

                //Find best shipping method
	            var store = StoreHelper.StoreClient.GetCurrentStore();
	            var storeShippingMethods = helper.ShippingClient.GetAllShippingMethods()
					  .Where(sm => sm.PaymentMethodShippingMethods.Select(x => x.PaymentMethod)
		                   .Any(pm => store.PaymentGateways.Any(pg => pg.PaymentGateway == pm.Name)))
						   .Select(s=>s.ShippingMethodId).ToList();
				var bestShipping = helper.GetShippingMethods(storeShippingMethods).Min();

                //Update line items
                foreach (var lineItem in helper.OrderForm.LineItems)
                {
                    lineItem.ShippingMethodId = bestShipping.Id;
                    lineItem.ShippingMethodName = bestShipping.DisplayName;
                }

                // run workflow
                helper.RunWorkflow("ShoppingCartPrepareWorkflow");
                helper.SaveChanges();

                var response = Request.CreateResponse(HttpStatusCode.OK);
                var bShippingJson = System.Web.Helpers.Json.Encode(bestShipping);
                response.Content = new StringContent(bShippingJson);
                return response;
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
        public IHttpActionResult EstimatePost(ShippingEstimateModel shippingEstimateModel)
        {
            if (ModelState.IsValid)
            {
                var helper = new CartHelper(CartHelper.CartName);

                //Find best shipping method
	            var store = StoreHelper.StoreClient.GetCurrentStore();
	            var storeShippingMethods = helper.ShippingClient.GetAllShippingMethods()
					  .Where(sm => sm.PaymentMethodShippingMethods.Select(x => x.PaymentMethod)
		                   .Any(pm => store.PaymentGateways.Any(pg => pg.PaymentGateway == pm.Name)))
						   .Select(s=>s.ShippingMethodId).ToList();
				var bestShipping = helper.GetShippingMethods(storeShippingMethods).Min();

                //Update line items
                foreach (var lineItem in helper.OrderForm.LineItems)
                {
                    lineItem.ShippingMethodId = bestShipping.Id;
                    lineItem.ShippingMethodName = bestShipping.DisplayName;
                }

                // run workflow
                helper.RunWorkflow("ShoppingCartPrepareWorkflow");
                helper.SaveChanges();

                return Ok(bestShipping);
            }

            return BadRequest();
        }
Exemplo n.º 4
0
        /// <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();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Provides an application-wide implementation of the <see cref="P:System.Web.UI.PartialCachingAttribute.VaryByCustom" /> property.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext" /> object that contains information about the current Web request.</param>
        /// <param name="custom">The custom string that specifies which cached response is used to respond to the current request.</param>
        /// <returns>If the value of the <paramref name="custom" /> parameter is "browser", the browser's <see cref="P:System.Web.Configuration.HttpCapabilitiesBase.Type" />; otherwise, null.</returns>
        public override string GetVaryByCustomString(HttpContext context, string custom)
        {

            var varyString = base.GetVaryByCustomString(context, custom) ?? string.Empty;

            //varyString += UserHelper.CustomerSession.Language;//allways vary by language

            if (SettingsHelper.OutputCacheEnabled)
            {
                foreach (var key in custom.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (string.Equals(key, "registered", StringComparison.OrdinalIgnoreCase))
                    {
                        varyString += UserHelper.CustomerSession.IsRegistered ? "registered" : "anonymous";
                    }
                    if (string.Equals(key, "storeparam", StringComparison.OrdinalIgnoreCase))
                    {
                        varyString += UserHelper.CustomerSession.StoreId;
                    }
                    if (string.Equals(key, "currency", StringComparison.OrdinalIgnoreCase))
                    {
                        varyString += UserHelper.CustomerSession.Currency;
                    }
                    if (string.Equals(key, "pricelist", StringComparison.OrdinalIgnoreCase))
                    {
                        varyString += CacheHelper.CreateCacheKey("_pl", UserHelper.CustomerSession.Pricelists);
                    }
                    if (string.Equals(key, "filters", StringComparison.OrdinalIgnoreCase))
                    {
                        var qs = Request.QueryString;
                        var pageSize = qs.AllKeys.Contains("pageSize") ? qs["pageSize"] : StoreHelper.GetCookieValue("pagesizecookie");
                        var sort = qs.AllKeys.Contains("sort") ? qs["sort"] : StoreHelper.GetCookieValue("sortcookie");
                        var sortorder = qs.AllKeys.Contains("sortorder") ? qs["sortorder"] : StoreHelper.GetCookieValue("sortordercookie") ?? "asc";

                        varyString += string.Format("filters_{0}_{1}_{2}", pageSize, sort, sortorder);
                    }

                    if (string.Equals(key, "cart", StringComparison.OrdinalIgnoreCase))
                    {
                        //This method is called from System.Web.Caching module before customerId set 
                        if (string.IsNullOrEmpty(UserHelper.CustomerSession.CustomerId))
                        {
                            if (UserHelper.CustomerSession.IsRegistered)
                            {
                                var account = UserHelper.UserClient.GetAccountByUserName(UserHelper.CustomerSession.Username);
                                if (account != null)
                                {
                                    UserHelper.CustomerSession.CustomerId = account.MemberId;
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(UserHelper.CustomerSession.CustomerId))
                        {
                            UserHelper.CustomerSession.CustomerId = context.Request.AnonymousID ??
                                                                    Guid.NewGuid().ToString();
                        }

                        var ch = new CartHelper(CartHelper.CartName);

                        if (ch.LineItems.Any())
                        {
                            varyString +=
                                new CartHelper(CartHelper.CartName).LineItems.Select(x => x.LineItemId)
                                                                   .Aggregate((x, y) => x + y);
                        }

                    }
                }
            }

            return varyString;
        }
        /// <summary>
        /// Populates the shopping cart.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="session">The session.</param>
        private void PopulateShoppingCart(HttpContext context, ICustomerSession session)
        {
            var set = session.GetCustomerTagSet();

            // cart total
            var helper = new CartHelper(CartHelper.CartName);
            if (!helper.IsEmpty)
            {
                set.Add(ContextFieldConstants.CartTotal, new Tag(helper.Cart.Total));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Reorders the specified order.
        /// </summary>
        /// <param name="orderId">The order identifier.</param>
        /// <returns>ActionResult.</returns>
        /// <exception cref="System.UnauthorizedAccessException"></exception>
        public ActionResult Reorder(string orderId)
        {
            var order = _orderClient.GetCustomerOrder(UserHelper.CustomerSession.CustomerId, orderId);
            if (order == null || String.IsNullOrEmpty(order.CustomerId))
            {
                throw new UnauthorizedAccessException();
            }

            var ch = new CartHelper(CartHelper.CartName);
            ch.ToCart(order);

            return RedirectToAction("Index", "Checkout");
        }
Exemplo n.º 8
0
 public ActionResult Compare()
 {
     var ch = new CartHelper(CartHelper.CompareListName);
     var cm = ch.CreateCompareModel();
     return View(cm);
 }
Exemplo n.º 9
0
        public ActionResult UpdateWishList(List<LineItemUpdateModel> lineItems, string action)
        {
            var ch = new CartHelper(CartHelper.CartName);
            var helper = new CartHelper(CartHelper.WishListName);

            if (action == UserHelper.AddToCartAction)
            {
                //add all to cart
                foreach (var lineItem in lineItems)
                {
                    var li = helper.LineItems.FirstOrDefault(item => item.LineItemId == lineItem.LineItemId);

                    if (li == null)
                    {
                        continue;
                    }

                    var catalogItem = _catalogClient.GetItem(li.CatalogItemId);
                    var parentItem = _catalogClient.GetItem(li.ParentCatalogItemId);
                    ch.AddItem(catalogItem, parentItem, lineItem.Quantity, false);
                    helper.Remove(li);

                    // If wishlist is empty, remove it from the database
                    if (helper.IsEmpty)
                    {
                        helper.Delete();
                    }
                }

                ch.SaveChanges();
            }
            else
            {
                foreach (var lineItem in lineItems)
                {
                    var li = helper.LineItems.FirstOrDefault(item => item.LineItemId == lineItem.LineItemId);
                    if (li == null)
                    {
                        continue;
                    }

                    li.Comment = lineItem.Comment;
                    li.Quantity = lineItem.Quantity;
                }
            }

            helper.SaveChanges();

            return RedirectToAction("WishList");
        }
        /// <summary>
        /// Saves the cart changes.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <returns>Dictionary of errors if any.</returns>
        private Dictionary<string, string> SaveChanges(CartHelper helper)
        {
            if (helper.Cart.Name != CartHelper.CartName)
            {
                _catalogClient.CustomerSession["SkipRewards"] = true;
            }

            var errors = new Dictionary<string, string>();
            if (helper.Cart.Name == CartHelper.CartName)
            {
                //Need to prepare cart because shipment rates could chaange after items added/removed
                //var result = helper.RunWorkflow("ShoppingCartPrepareWorkflow");
                var result = helper.RunWorkflow("ShoppingCartValidateWorkflow");

                if (result.WorkflowResult.Warnings != null)
                {
                    foreach (var warning in result.WorkflowResult.Warnings.Distinct())
                    {
                        errors.Add(warning.Code, warning.Parameters["Message"]);
                    }
                }
            }

            helper.SaveChanges();
            return errors;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates the cart model.
 /// </summary>
 /// <param name="cart">The cart.</param>
 /// <returns>CartModel.</returns>
 private CartModel CreateCartModel(CartHelper cart)
 {
     var model = cart.CreateCartModel(true);
     model.ShippingEstimateModel.Countries = _countryClient.GetAllCountries();
     return model;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Saves the cart changes.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <returns>Dictionary of errors if any.</returns>
        private Dictionary<string, string> SaveChanges(CartHelper helper)
        {
            if (helper.Cart.Name != CartHelper.CartName)
            {
                _catalogClient.CustomerSession["SkipRewards"] = true;
            }

            var errors = new Dictionary<string, string>();
            if (helper.Cart.Name == CartHelper.CartName)
            {
                var result = helper.RunWorkflow("ShoppingCartValidateWorkflow");

                if (result.WorkflowResult.Warnings != null)
                {
                    foreach (var warning in result.WorkflowResult.Warnings.Distinct())
                    {
                        errors.Add(warning.Code, warning.Parameters["Message"]);
                    }
                }
            }

            helper.SaveChanges();
            return errors;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Quicks the access.
 /// </summary>
 /// <returns>ActionResult.</returns>
 //[DonutOutputCache(CacheProfile = "StoreCache", Duration = 0)]
 public ActionResult QuickAccess()
 {
     var wishListHelper = new CartHelper(CartHelper.WishListName);
     var cartHelper = new CartHelper(CartHelper.CartName);
     return PartialView("QuickAccess",
                        (new
                            {
                                Cart = cartHelper.CreateCartModel(true),
                                WishList = wishListHelper.CreateCartModel(true),
                                UserHelper.CustomerSession.CustomerName
                            }).ToExpando());
 }
Exemplo n.º 14
0
 /// <summary>
 /// Quicks the access.
 /// </summary>
 /// <returns>ActionResult.</returns>
 //[ChildActionOnly, DonutOutputCache(CacheProfile = "StoreCache", Duration = 0)]
 public ActionResult CartOptions()
 {
     var compareListHelper = new CartHelper(CartHelper.CompareListName);
     var cartHelper = new CartHelper(CartHelper.CartName);
     return PartialView("CartOptions",
                        (new
                        {
                            Cart = cartHelper.CreateCartModel(true),
                            CompareList = compareListHelper.CreateCompareModel()
                        }).ToExpando());
 }
Exemplo n.º 15
0
        /// <summary>
        /// Reorders the specified order.
        /// </summary>
        /// <param name="orderId">The order identifier.</param>
        /// <returns>ActionResult.</returns>
        /// <exception cref="System.UnauthorizedAccessException"></exception>
        public ActionResult Reorder(string orderId)
        {
            var order = _orderClient.GetCustomerOrder(UserHelper.CustomerSession.CustomerId, orderId);
            if (order == null || String.IsNullOrEmpty(order.CustomerId))
            {
                throw new UnauthorizedAccessException();
            }

            //Convert order forms to shopping cart
            order.OrderForms.ForEach(f=>f.Name = CartHelper.CartName);

            var ch = new CartHelper(CartHelper.CartName);
            ch.Add(order);

            if (String.IsNullOrEmpty(ch.Cart.BillingCurrency))
            {
                ch.Cart.BillingCurrency = UserHelper.CustomerSession.Currency;
            }

            // run workflows
            ch.RunWorkflow("ShoppingCartPrepareWorkflow");

            ch.SaveChanges();

            return RedirectToAction("Index", "Checkout");
        }
Exemplo n.º 16
0
 /// <summary>
 /// View wish list.
 /// </summary>
 /// <returns>ActionResult.</returns>
 public ActionResult WishList()
 {
     var ch = new CartHelper(CartHelper.WishListName);
     return View(ch.CreateCartModel(true));
 }
Exemplo n.º 17
0
        /// <summary>
        /// Saves the cart changes.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <returns>Dictionary of errors if any.</returns>
        private Dictionary<string, string> SaveChanges(CartHelper helper)
        {
            if (helper.Cart.Name != CartHelper.CartName)
            {
                _catalogClient.CustomerSession["SkipRewards"] = true;
            }

            var errors = new Dictionary<string, string>();
            if (helper.Cart.Name == CartHelper.CartName)
            {

                helper.RunWorkflow("ShoppingCartValidateWorkflow", errors);
            }

            helper.SaveChanges();
            return errors;
        }