/// <summary>
        /// Initializes this object based on the data contained in the provided cart.
        /// </summary>
        /// <param name="cart">The cart used to initialize this object.</param>
        public override void Initialize(Commerce.Entities.Carts.Cart cart, IProductResolver productResolver)
        {
            base.Initialize(cart, productResolver);

            CommerceCart commerceCart = cart as CommerceCart;

            if (commerceCart == null)
            {
                return;
            }

            if (commerceCart.OrderForms.Count > 0)
            {
                foreach (var promoCode in (commerceCart.OrderForms[0].PromoCodes ?? Enumerable.Empty <String>()))
                {
                    this.PromoCodes.Add(promoCode);
                }
            }

            decimal totalSavings = 0;

            foreach (var lineitem in cart.Lines)
            {
                totalSavings += ((CommerceTotal)lineitem.Total).LineItemDiscountAmount;
            }

            this.Discount = totalSavings.ToCurrency(StorefrontManager.GetCustomerCurrency());
        }
        /// <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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the specified cart.
        /// </summary>
        /// <param name="cart">The cart.</param>
        public virtual void Initialize(Cart cart)
        {
            Assert.ArgumentNotNull(cart, "cart");

            this.LineItemCount = ((CommerceCart)cart).LineItemCount;
            this.Total         = ((CommerceTotal)cart.Total).Subtotal.ToCurrency(StorefrontManager.GetCustomerCurrency());
        }
        public JsonResult GetCheckoutData()
        {
            try
            {
                var result   = new CheckoutDataBaseJsonResult();
                var response = this.CartManager.GetCurrentCart(CurrentStorefront, CurrentVisitorContext, true);
                if (response.ServiceProviderResult.Success && response.Result != null)
                {
                    var cart = (CommerceCart)response.ServiceProviderResult.Cart;
                    if (cart.Lines != null && cart.Lines.Any())
                    {
                        result.Cart = new CSCartBaseJsonResult(response.ServiceProviderResult);
                        result.Cart.Initialize(response.ServiceProviderResult.Cart);

                        result.ShippingMethods       = new List <ShippingMethod>();
                        result.CartLoyaltyCardNumber = cart.LoyaltyCardID;

                        result.CurrencyCode = StorefrontManager.GetCustomerCurrency();

                        this.AddShippingOptionsToResult(result, cart);
                        if (result.Success)
                        {
                            this.AddShippingMethodsToResult(result);
                            if (result.Success)
                            {
                                this.GetAvailableCountries(result);
                                if (result.Success)
                                {
                                    this.GetPaymentOptions(result);
                                    if (result.Success)
                                    {
                                        this.GetPaymentMethods(result);
                                        if (result.Success)
                                        {
                                            this.GetPaymentClientToken(result);
                                            if (result.Success)
                                            {
                                                this.GetUserInfo(result);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                result.SetErrors(response.ServiceProviderResult);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("GetCheckoutData", this, e);
                return(Json(new BaseJsonResult("GetCheckoutData", e), JsonRequestBehavior.AllowGet));
            }
        }
        public void UpdateMiniCart_ShoudReturn_TotalEqualsCartTotal(Database db)
        {
            _mocks.MockContexts(db);
            var expectedResult = ((CommerceTotal)Models.CommerceCartStub.Total)
                                 .Subtotal.ToCurrency(StorefrontManager.GetCustomerCurrency());

            var result = _cartRepository.UpdateMiniCart(true);

            result.Total.Should().Be(expectedResult);
        }
Ejemplo n.º 6
0
        public CheckoutDataBaseJsonResult GetCheckoutData(User user)
        {
            var result   = new CheckoutDataBaseJsonResult();
            var response = this._cartManager.GetCurrentCart(CurrentStorefront, CurrentVisitorContext, true);

            if (response.ServiceProviderResult.Success && response.Result != null)
            {
                var cart = (CommerceCart)response.ServiceProviderResult.Cart;

                if (cart.Lines != null && cart.Lines.Any())
                {
                    result.Cart = new CSCartBaseJsonResult(response.ServiceProviderResult);
                    result.Cart.Initialize(response.ServiceProviderResult.Cart, _productResolver);
                    result.ShippingMethods       = new List <ShippingMethod>();
                    result.CartLoyaltyCardNumber = cart.LoyaltyCardID;
                    result.CurrencyCode          = StorefrontManager.GetCustomerCurrency();
                    this.AddShippingOptionsToResult(result, cart);

                    if (result.Success)
                    {
                        this.AddShippingMethodsToResult(result);

                        if (result.Success)
                        {
                            this.GetAvailableCountries(result);

                            if (result.Success)
                            {
                                this.GetPaymentOptions(result);

                                if (result.Success)
                                {
                                    this.GetPaymentMethods(result);

                                    if (result.Success)
                                    {
                                        this.GetUserInfo(result, user);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            result.SetErrors(response.ServiceProviderResult);

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes the specified gift card.
        /// </summary>
        /// <param name="giftCard">The gift card.</param>
        public virtual void Initialize(GiftCard giftCard)
        {
            Assert.ArgumentNotNull(giftCard, "giftCard");

            var currencyCode = StorefrontManager.GetCustomerCurrency();

            this.ExternalId       = giftCard.ExternalId;
            this.Name             = giftCard.Name;
            this.CustomerId       = giftCard.CustomerId;
            this.ShopName         = giftCard.ShopName;
            this.CurrencyCode     = giftCard.CurrencyCode;
            this.Balance          = giftCard.Balance;
            this.FormattedBalance = giftCard.Balance.ToCurrency(currencyCode);
            this.OriginalAmount   = giftCard.OriginalAmount.ToCurrency(currencyCode);
            this.Description      = giftCard.Description;
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes this object based on the data contained in the provided cart.
        /// </summary>
        /// <param name="cart">The cart used to initialize this object.</param>
        public virtual void Initialize(Cart cart)
        {
            this.Lines       = new List <CartLineBaseJsonResult>();
            this.Adjustments = new List <CartAdjustmentBaseJsonResult>();
            this.PromoCodes  = new List <string>();
            var currencyCode = StorefrontManager.GetCustomerCurrency();

            this.Subtotal      = 0.0M.ToCurrency(currencyCode);
            this.TaxTotal      = 0.0M.ToCurrency(currencyCode);
            this.Total         = 0.0M.ToCurrency(currencyCode);
            this.TotalAmount   = 0.0M;
            this.Discount      = 0.0M.ToCurrency(currencyCode);
            this.ShippingTotal = 0.0M.ToCurrency(currencyCode);

            if (cart == null)
            {
                return;
            }

            foreach (var line in (cart.Lines ?? Enumerable.Empty <CartLine>()))
            {
                var cartLine = CommerceTypeLoader.CreateInstance <CartLineBaseJsonResult>(line);
                this.Lines.Add(cartLine);
            }

            foreach (var adjustment in (cart.Adjustments ?? Enumerable.Empty <CartAdjustment>()))
            {
                this.Adjustments.Add(new CartAdjustmentBaseJsonResult(adjustment));
            }

            var commerceTotal = (CommerceTotal)cart.Total;

            this.Subtotal      = commerceTotal.Subtotal.ToCurrency(currencyCode);
            this.TaxTotal      = cart.Total.TaxTotal.Amount.ToCurrency(currencyCode);
            this.Total         = cart.Total.Amount.ToCurrency(currencyCode);
            this.TotalAmount   = cart.Total.Amount;
            this.Discount      = commerceTotal.OrderLevelDiscountAmount.ToCurrency(currencyCode);
            this.ShippingTotal = commerceTotal.ShippingTotal.ToCurrency(currencyCode);
        }
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(RenderRenderingArgs args)
        {
            if (args.Rendered ||
                HttpContext.Current == null ||
                (!args.Cacheable) ||
                args.Rendering.RenderingItem == null)
            {
                return;
            }

            Item rendering = args.PageContext.Database.GetItem(args.Rendering.RenderingItem.ID);

            if (rendering == null || rendering["VaryByCurrency"] != "1")
            {
                return;
            }

            // When no cache key is present, we generate a full cache key; Otherwise we append to the existing ones.
            if (string.IsNullOrWhiteSpace(args.CacheKey))
            {
                args.CacheKey = string.Format(CultureInfo.InvariantCulture, "_#varyByCurrency_{0}_{1}_{2}_{3}_{4}", Context.Site.Name, Sitecore.Context.Language.Name, HttpContext.Current.Request.Url.AbsoluteUri, args.Rendering.RenderingItem.ID.ToString(), StorefrontManager.GetCustomerCurrency());
            }
            else
            {
                args.CacheKey = string.Format(CultureInfo.InvariantCulture, "_#varybyCurrency_{0}_{1}_{2}", args.CacheKey, args.Rendering.RenderingItem.ID.ToString(), StorefrontManager.GetCustomerCurrency());
            }
        }