Exemplo n.º 1
0
        public JsonResult RemoveDiscount(DiscountInputModel model)
        {
            try
            {
                Assert.ArgumentNotNull(model, "model");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var response = this.CartManager.RemovePromoCodeFromCart(CurrentStorefront, CurrentVisitorContext, model.PromoCode);
                var result   = new AXCartBaseJsonResult(response.ServiceProviderResult);
                if (response.ServiceProviderResult.Success && response.Result != null)
                {
                    result.Initialize(response.Result);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("RemoveDiscount", this, e);
                return(Json(new BaseJsonResult("RemoveDiscount", e), JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        public JsonResult UpdateLineItem(UpdateCartLineInputModel inputModel)
        {
            try
            {
                Assert.ArgumentNotNull(inputModel, "inputModel");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var response = this.CartManager.ChangeLineQuantity(CurrentStorefront, CurrentVisitorContext, inputModel);
                var result   = new AXCartBaseJsonResult(response.ServiceProviderResult);
                if (response.ServiceProviderResult.Success && response.Result != null)
                {
                    result.Initialize(response.Result);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("UpdateLineItem", this, e);
                return(Json(new BaseJsonResult("UpdateLineItem", e), JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SetPaymentMethods(PaymentInputModel inputModel)
        {
            try
            {
                Assert.ArgumentNotNull(inputModel, "inputModel");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var response = this.CartManager.GetCurrentCart(CurrentStorefront, CurrentVisitorContext, false);
                AXCartBaseJsonResult cartResult = new AXCartBaseJsonResult(response.ServiceProviderResult);
                if (response.ServiceProviderResult.Success && response.Result != null)
                {
                    cartResult.Initialize(response.ServiceProviderResult.Cart);
                }

                return(Json(cartResult, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("SetPaymentMethods", this, e);
                return(Json(new BaseJsonResult("SetPaymentMethods", e), JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 4
0
        public JsonResult GetCurrentCart()
        {
            try
            {
                var id        = this.CurrentVisitorContext.GetCustomerId();
                var cartCache = CommerceTypeLoader.CreateInstance <CartCacheHelper>();
                var cart      = cartCache.GetCart(id);
                AXCartBaseJsonResult cartResult;

                // The following condition stops the creation of empty carts on startup.
                if (cart == null && CartCookieHelper.DoesCookieExistForCustomer(id))
                {
                    var response = this.CartManager.GetCurrentCart(CurrentStorefront, CurrentVisitorContext, true);
                    cartResult = new AXCartBaseJsonResult(response.ServiceProviderResult);
                    if (response.ServiceProviderResult.Success && response.Result != null)
                    {
                        cartResult.Initialize(response.ServiceProviderResult.Cart);
                        if (response.ServiceProviderResult.Cart != null)
                        {
                            cartCache.AddCartToCache(response.ServiceProviderResult.Cart as CommerceCart);
                        }
                    }
                }
                else
                {
                    cartResult = new AXCartBaseJsonResult();
                    cartResult.Initialize(cart);
                }

                return(Json(cartResult, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("GetCurrentCart", this, e);
                return(Json(new BaseJsonResult("GetCurrentCart", e), JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SetShippingMethods(SetShippingMethodsInputModel inputModel)
        {
            try
            {
                Assert.ArgumentNotNull(inputModel, "inputModel");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var response = this.CartManager.SetShippingMethods(CurrentStorefront, CurrentVisitorContext, inputModel);
                var result   = new AXCartBaseJsonResult(response.ServiceProviderResult);
                if (!response.ServiceProviderResult.Success || response.Result == null)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                // QUERYING FOR THE CART AGAIN BECAUSE THE SHIPPING COST AND TAX TOTAL ARE NOT BEING UPDATED
                // ON THE RETURNED CART OF THE SETSHIPPINGMETHOD REQUEST
                var cartResponse = this.CartManager.GetCurrentCart(CurrentStorefront, CurrentVisitorContext, true);
                result.SetErrors(cartResponse.ServiceProviderResult);
                if (cartResponse.ServiceProviderResult.Success && response.Result != null)
                {
                    result.Initialize(cartResponse.Result);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("SetShippingMethods", this, e);
                return(Json(new BaseJsonResult("SetShippingMethods", e), JsonRequestBehavior.AllowGet));
            }
        }