Ejemplo n.º 1
0
        public ActionResult ShowAddToCart(string productCode, int? quantity, string viewName)
        {
            if (productCode.IsNullOrEmpty())
            {
                return new EmptyResult();
            }
            var product = CatalogService.GetProductByCode(productCode);
            if (product == null)
            {
                return PartialView("_unknownproduct");
            }

            var qty = GetQuantity(product, quantity.GetValueOrDefault(1));
            var cart = AddToCart(product, qty);

            // Application du tarif client
            // var list = new List<Models.Product>() { product };
            // CatalogService.ApplyBestPrice(list, User.GetUserPrincipal().CurrentUser);
            var urlHelper = new UrlHelper(this.ControllerContext.RequestContext);
            bool isCustomerPriceApplied = false;
            var price = SalesService.GetProductSalePrice(product, User.GetUserPrincipal().CurrentUser, qty, out isCustomerPriceApplied);
            //var cart = CartService.GetCurrentOrderCart(User.GetUserPrincipal());

            ViewData.Model = new Models.CartItemNeeded()
            {
                Product = product,
                CartUrl = urlHelper.CartHref(),
                Quantity = qty,
                Price = price,
                Cart = cart,
            };
            viewName = viewName ?? "_addtocart";
            return PartialView(viewName);
        }
Ejemplo n.º 2
0
        private ActionResult JsAddToCart(Models.Product product, int quantity)
        {
            if (product == null
                || product.SaleMode != ERPStore.Models.ProductSaleMode.Sellable)
            {
                return new JsonResult();
            }

            var cart = AddToCart(product, quantity);

            var urlHelper = new UrlHelper(this.ControllerContext.RequestContext);
            SalesService.ProcessExport(cart, User.GetUserPrincipal().CurrentUser);

            var data = new
            {
                status = cart.GetStatusText(),
                cartGrandTotal = cart.GrandTotal.ToString("#,#0.00"),
                cartGrandTaxTotal = cart.GrandTaxTotal.ToString("#,#0.00"),
                cartGrandTotalWithTax = cart.GrandTotalWithTax.ToString("#,#0.00"),
                title = product.Title,
                quantity = quantity,
                cartUrl = urlHelper.CartHref(),
                productImage = product.DefaultImage != null ? HttpUtility.UrlEncode(product.DefaultImage.Url) : string.Empty,
            };

            var result = Json(data);

            return result;
        }
Ejemplo n.º 3
0
        private ActionResult JsAddItemToCart(ShoppingCart.Web.Mvc.Model.IProduct product, int quantity)
        {
            if (product == null)
            {
                return new JsonResult();
            }
            var price = CatalogService.GetPriceByProduct(product);
            var cart = CartService.GetOrCreateCart(Request.AnonymousID);
            CartService.AddItem(cart, product.Code, product.SaleUnitValue, product.Packaging, quantity, price);

            var urlHelper = new UrlHelper(this.ControllerContext.RequestContext);

            return Json(new
            {
                status = cart.GetStatusText(),
                cartTotal = cart.TotalWithTax.ToString("#,#0.00"),
                title = product.Title,
                quantity = quantity,
                cartUrl = urlHelper.CartHref(),
            });
        }