public JsonResult SubmitOrder(SubmitOrderInputModel inputModel)
        {
            try
            {
                Assert.ArgumentNotNull(inputModel, "inputModel");

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

                var response = this.OrderManager.SubmitVisitorOrder(CurrentStorefront, CurrentVisitorContext, inputModel);
                var result   = new SubmitOrderBaseJsonResult(response.ServiceProviderResult);
                if (!response.ServiceProviderResult.Success || response.Result == null || response.ServiceProviderResult.CartWithErrors != null)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                result.Initialize(string.Concat(StorefrontManager.StorefrontUri("checkout/OrderConfirmation"), "?confirmationId=", (response.Result.TrackingNumber)));
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("SubmitOrder", this, e);
                return(Json(new BaseJsonResult("SubmitOrder", e), JsonRequestBehavior.AllowGet));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CartLineBaseJsonResult"/> class.
        /// </summary>
        /// <param name="line">The line.</param>
        public CartLineBaseJsonResult(CustomCommerceCartLine line)
        {
            this.DiscountOfferNames = new List <string>();

            var product     = (CommerceCartProduct)line.Product;
            var productItem = ProductItemResolver.ResolveCatalogItem(product.ProductId, product.ProductCatalog, true);

            if (line.Images.Count > 0)
            {
                this.Image = line.Images[0].GetImageUrl(100, 100);
            }

            var userCurrency = StorefrontManager.GetCustomerCurrency();

            this.DisplayName        = product.DisplayName;
            this.Color              = product.Properties["Color"] as string;
            this.LineDiscount       = ((CommerceTotal)line.Total).LineItemDiscountAmount.ToCurrency(this.GetCurrencyCode(userCurrency, ((CommerceTotal)line.Total).CurrencyCode));
            this.Quantity           = line.Quantity.ToString(Context.Language.CultureInfo);
            this.LinePrice          = product.Price.Amount.ToCurrency(this.GetCurrencyCode(userCurrency, product.Price.CurrencyCode));
            this.LineTotal          = line.Total.Amount.ToCurrency(this.GetCurrencyCode(userCurrency, line.Total.CurrencyCode));
            this.ExternalCartLineId = StringUtility.RemoveCurlyBrackets(line.ExternalCartLineId);
            this.ProductUrl         = product.ProductId.Equals(StorefrontManager.CurrentStorefront.GiftCardProductId, StringComparison.OrdinalIgnoreCase)
                ? StorefrontManager.StorefrontUri("/buygiftcard")
                : LinkManager.GetDynamicUrl(productItem);
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WishListHeaderItemBaseJsonResult"/> class.
 /// </summary>
 /// <param name="header">The wish list header.</param>
 public WishListHeaderItemBaseJsonResult(WishListHeader header)
 {
     this.ExternalId = header.ExternalId;
     this.Name       = header.Name;
     this.IsFavorite = header.IsFavorite;
     this.DetailsUrl = string.Concat(StorefrontManager.StorefrontUri("/accountmanagement/mywishlist"), "?id=", header.ExternalId);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderHeaderItemBaseJsonResult"/> class.
 /// </summary>
 /// <param name="header">The order header.</param>
 public OrderHeaderItemBaseJsonResult(OrderHeader header)
 {
     this.ExternalId   = header.ExternalId;
     this.Status       = header.Status;
     this.LastModified = ((CommerceOrderHeader)header).LastModified.ToDisplayedDate();
     this.DetailsUrl   = string.Concat(StorefrontManager.StorefrontUri("/accountmanagement/myorder"), "?id=", header.ExternalId);
     this.OrderId      = header.ExternalId;
 }
예제 #5
0
        public SubmitOrderBaseJsonResult SubmitOrder(SubmitOrderInputModel inputModel)
        {
            var response = this._orderManager.SubmitVisitorOrder(CurrentStorefront, CurrentVisitorContext, inputModel);
            var result   = new SubmitOrderBaseJsonResult(response.ServiceProviderResult);

            if (response.ServiceProviderResult.Success && response.Result != null && response.ServiceProviderResult.CartWithErrors == null)
            {
                result.Initialize(string.Concat(StorefrontManager.StorefrontUri("checkout/OrderConfirmation"), "?confirmationId=", (response.Result.TrackingNumber)));
            }

            return(result);
        }
        public ActionResult StartCheckout()
        {
            var cart = _checkoutRepository.GetCommerceCart();

            if (cart.Lines == null || !cart.Lines.Any())
            {
                var cartPageUrl = StorefrontManager.StorefrontUri("/shoppingcart");
                return(Redirect(cartPageUrl));
            }

            return(View("Checkout", new CartRenderingModel(cart)));
        }
        /// <summary>
        /// Initializes the specified address.
        /// </summary>
        /// <param name="address">The address.</param>
        public virtual void Initialize(Party address)
        {
            Assert.ArgumentNotNull(address, "address");

            this.ExternalId    = address.ExternalId;
            this.Address1      = address.Address1;
            this.City          = address.City;
            this.State         = address.State;
            this.ZipPostalCode = address.ZipPostalCode;
            this.Country       = address.Country;
            this.FullAddress   = string.Concat(address.Address1, ", ", address.City, ", ", address.ZipPostalCode);
            this.DetailsUrl    = string.Concat(StorefrontManager.StorefrontUri("/accountmanagement/addressbook"), "?id=", address.ExternalId);
        }
        public ActionResult StartCheckout()
        {
            var response = this.CartManager.GetCurrentCart(CurrentStorefront, CurrentVisitorContext, true);
            var cart     = (CommerceCart)response.ServiceProviderResult.Cart;

            if (cart.Lines == null || !cart.Lines.Any())
            {
                var cartPageUrl = StorefrontManager.StorefrontUri("/shoppingcart");
                return(Redirect(cartPageUrl));
            }

            return(View(this.CurrentRenderingView, new CartRenderingModel(cart)));
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WishListItemBaseJsonResult" /> class.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="wishListId">The wish list identifier.</param>
        public WishListItemBaseJsonResult(WishListLine line, string wishListId)
        {
            Assert.ArgumentNotNull(line, "line");
            Assert.ArgumentNotNullOrEmpty(wishListId, "wishListId");

            var product     = (CommerceCartProduct)line.Product;
            var productItem = Sitecore.Reference.Storefront.SitecorePipelines.ProductItemResolver.ResolveCatalogItem(product.ProductId, product.ProductCatalog, true);

            var currencyCode = StorefrontManager.GetCustomerCurrency();

            this.DisplayName    = product.DisplayName;
            this.Color          = product.Properties["Color"] as string;
            this.LineDiscount   = ((CommerceTotal)line.Total).LineItemDiscountAmount.ToString(Sitecore.Context.Language.CultureInfo);
            this.Quantity       = line.Quantity.ToString(Sitecore.Context.Language.CultureInfo);
            this.LineTotal      = line.Total.Amount.ToCurrency(currencyCode);
            this.ExternalLineId = line.ExternalId;
            this.ProductId      = product.ProductId;
            this.VariantId      = product.ProductVariantId;
            this.ProductCatalog = product.ProductCatalog;
            this.WishListId     = wishListId;
            this.ProductUrl     = product.ProductId.Equals(StorefrontManager.CurrentStorefront.GiftCardProductId, StringComparison.OrdinalIgnoreCase)
              ? StorefrontManager.StorefrontUri("/buygiftcard")
              : LinkManager.GetDynamicUrl(productItem);

            if (product.Price.Amount != 0M)
            {
                this.LinePrice = product.Price.Amount.ToCurrency(currencyCode);
            }

            var imageInfo = product.Properties["_product_Images"] as string;

            if (imageInfo != null)
            {
                var       imageId   = imageInfo.Split('|')[0];
                MediaItem mediaItem = Sitecore.Context.Database.GetItem(imageId);
                this.Image = mediaItem.GetImageUrl(100, 100);
            }

            var giftCardAmount = line.GetPropertyValue("GiftCardAmount");

            if (giftCardAmount != null)
            {
                decimal amount = System.Convert.ToDecimal(giftCardAmount, Sitecore.Context.Language.CultureInfo);
                this.GiftCardAmount = amount.ToCurrency(currencyCode);
            }
        }
        public static string BuildUrl(string itemName, string itemFriendlyName, string catalogName, string root)
        {
            Assert.ArgumentNotNullOrEmpty(itemName, "itemName");

            var route = new StringBuilder("/");

            if (IncludeLanguage)
            {
                route.Append(Sitecore.Context.Language.Name);
                route.Append("/");
            }

            var isGiftCard = (itemName == StorefrontManager.CurrentStorefront.GiftCardProductId);

            if (isGiftCard)
            {
                route.Append(ProductItemResolver.LandingUrlRoute);
                route.Append("/");
                route.Append(ProductItemResolver.BuyGiftCardUrlRoute);
            }
            else
            {
                if (!string.IsNullOrEmpty(catalogName))
                {
                    route.Append(EncodeUrlToken(catalogName, true));
                    route.Append("/");
                }

                route.Append(root);
                route.Append("/");

                if (!string.IsNullOrEmpty(itemFriendlyName))
                {
                    route.Append(EncodeUrlToken(itemFriendlyName, true));
                    route.Append(UrlTokenDelimiter);
                }

                route.Append(EncodeUrlToken(itemName, false));
            }

            var url = StorefrontManager.StorefrontUri(route.ToString());

            return(url);
        }
        public ActionResult StartCheckout()
        {
            var viewRequested = this.Request.QueryString["view"];

            if (viewRequested != null && viewRequested == "DynamicsCheckout")
            {
                return(View(this.GetRenderingView("DynamicsCheckout")));
            }

            var response = this.CartManager.GetCurrentCart(CurrentStorefront, CurrentVisitorContext, true);
            var cart     = (CommerceCart)response.ServiceProviderResult.Cart;

            if (cart.Lines == null || !cart.Lines.Any())
            {
                var cartPageUrl = StorefrontManager.StorefrontUri("/shoppingcart");
                return(Redirect(cartPageUrl));
            }

            return(View(this.CurrentRenderingView, new CartRenderingModel(response.Result)));
        }
 /// <summary>
 /// Get a proper product link
 /// </summary>
 /// <returns>The pruduct url.</returns>
 public string GetLink()
 {
     return(this.ProductId.Equals(StorefrontManager.CurrentStorefront.GiftCardProductId, StringComparison.OrdinalIgnoreCase)
      ? StorefrontManager.StorefrontUri("/buygiftcard")
      : LinkManager.GetDynamicUrl(Item));
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CSOrderHeaderItemBaseJsonResult"/> class.
 /// </summary>
 /// <param name="header">The order header.</param>
 public CSOrderHeaderItemBaseJsonResult(OrderHeader header) : base(header)
 {
     this.DetailsUrl = string.Concat(StorefrontManager.StorefrontUri("/accountmanagement/myorder"), "?id=", header.OrderID);
     this.OrderId    = header.OrderID;
 }
예제 #14
0
        public static string BuildShopUrl(string categoryId, string categoryName, string productId, string productName, string variantId, string variantName, string catalogName)
        {
            Assert.ArgumentNotNullOrEmpty(categoryId, "categoryId");

            var route = new StringBuilder("/");

            if (IncludeLanguage)
            {
                route.Append(Sitecore.Context.Language.Name);
                route.Append("/");
            }

            var isGiftCard = (productId == StorefrontManager.CurrentStorefront.GiftCardProductId);

            if (isGiftCard)
            {
                route.Append(ProductItemResolver.LandingUrlRoute);
                route.Append("/");
                route.Append(ProductItemResolver.BuyGiftCardUrlRoute);
            }
            else
            {
                if (!string.IsNullOrEmpty(catalogName))
                {
                    route.Append(EncodeUrlToken(catalogName, true));
                    route.Append("/");
                }

                route.Append(ProductItemResolver.ShopUrlRoute);
                route.Append("/");

                if (!string.IsNullOrEmpty(categoryName))
                {
                    route.Append(EncodeUrlToken(categoryName, true));
                    route.Append(_urlTokenDelimiter);
                }

                route.Append(EncodeUrlToken(categoryId, false));

                if (!string.IsNullOrEmpty(productId))
                {
                    route.Append("/");

                    if (!string.IsNullOrEmpty(productName))
                    {
                        route.Append(EncodeUrlToken(productName, true));
                        route.Append(_urlTokenDelimiter);
                    }

                    route.Append(EncodeUrlToken(productId, false));

                    if (!string.IsNullOrEmpty(variantId))
                    {
                        route.Append("/");

                        if (!string.IsNullOrEmpty(variantName))
                        {
                            route.Append(EncodeUrlToken(variantName, true));
                            route.Append(_urlTokenDelimiter);
                        }

                        route.Append(EncodeUrlToken(variantId, false));
                    }
                }
            }

            var url = StorefrontManager.StorefrontUri(route.ToString());

            return(url);
        }