protected override void RenderContent(PrintContext printContext, XElement output)
        {
            string ListPriceKey = "List";

            XElement baseXml = new XElement("base");
            base.RenderContent(printContext, baseXml);

            XElement textFrame = baseXml.Element("TextFrame");
            Item dataItem = GetDataItem(printContext);

            XElement xElement = RenderItemHelper.CreateXElement("TextFrame", base.RenderingItem, printContext.Settings.IsClient, dataItem);
            this.SetAttributes(xElement);

            output.Add(xElement);

            XAttribute xAttribute = output.Attribute("ParagraphStyle");
            string text = (xAttribute != null && !string.IsNullOrEmpty(xAttribute.Value)) ? xAttribute.Value : "H1 Orange";

            Field fieldname = dataItem.Fields[this.ContentFieldName];
            DateField dateField = fieldname;

            var request = new GetProductPricesRequest(dataItem["ExternalID"]);
            var response = new PricingServiceProvider();
            var price = response.GetProductPrices(request).Prices[ListPriceKey].Amount;
            //var price = response.Prices.ContainsKey(ListPriceKey) ? response.Prices[ListPriceKey].Amount : decimal.Zero;

            //var price = this.pricingService.GetProductPrice("11");

            IEnumerable<XElement> result = this.FormatText(text, price.ToString("c"));

            xElement.Add(result);

            this.RenderChildren(printContext, xElement);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the product price.
        /// </summary>
        /// <param name="productId">The product identifier.</param>
        /// <returns>The product price.</returns>
        public decimal GetProductPrice(string productId)
        {
            var request = new GetProductPricesRequest(productId);
            var result  = this.serviceProvider.GetProductPrices(request);
            var price   = result.Prices.ContainsKey(ListPriceKey) ? result.Prices[ListPriceKey].Amount : decimal.Zero;

            return(price);
        }
        public string GetExternalPrice(string ExternalID)
        {
            string ListPriceKey = "List";

            var request  = new GetProductPricesRequest(ExternalID);
            var response = new PricingServiceProvider();
            var price    = response.GetProductPrices(request).Prices[ListPriceKey].Amount;

            return(price.ToString("c"));
        }
        public string GetExternalPrice(string ExternalID)
        {
            string ListPriceKey = "List";

            var request = new GetProductPricesRequest(ExternalID);
            var response = new PricingServiceProvider();
            var price = response.GetProductPrices(request).Prices[ListPriceKey].Amount;

            return price.ToString("c");
        }
        /// <summary>
        /// Gets the product prices.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="catalogName">Name of the catalog.</param>
        /// <param name="productId">The product identifier.</param>
        /// <param name="includeVariants">if set to <c>true</c> [include variants].</param>
        /// <param name="priceTypeIds">The price type ids.</param>
        /// <returns>The manager response with the list of prices in the Result.</returns>
        public virtual ManagerResponse <GetProductPricesResult, IDictionary <string, Dictionary <string, Price> > > GetProductPrices([NotNull] CommerceStorefront storefront, string catalogName, string productId, bool includeVariants, params string[] priceTypeIds)
        {
            Assert.ArgumentNotNull(storefront, "storefront");

            if (priceTypeIds == null)
            {
                priceTypeIds = defaultPriceTypeIds;
            }

            var request = new GetProductPricesRequest(catalogName, productId, priceTypeIds);

            request.IncludeVariantPrices = includeVariants;
            var result = this.PricingServiceProvider.GetProductPrices(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetProductPricesResult, IDictionary <string, Dictionary <string, Price> > >(result, result.Prices == null ? new Dictionary <string, Dictionary <string, Price> >() : result.Prices));
        }
Beispiel #6
0
        /// <summary>
        /// Gets the product prices.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="productId">The product identifier.</param>
        /// <param name="priceTypeIds">The price type ids.</param>
        /// <returns>
        /// The manager response with the list of prices in the Result.
        /// </returns>
        public virtual ManagerResponse <GetProductPricesResult, IDictionary <string, Price> > GetProductPrices([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, string productId, params string[] priceTypeIds)
        {
            Assert.ArgumentNotNull(storefront, "storefront");

            var request = new GetProductPricesRequest(productId, priceTypeIds);

            if (Sitecore.Context.User.IsAuthenticated)
            {
                request.UserId = visitorContext.GetCustomerId();
            }

            request.CurrencyCode = StorefrontManager.GetCustomerCurrency();

            var result = this.PricingServiceProvider.GetProductPrices(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetProductPricesResult, IDictionary <string, Price> >(result, result.Prices ?? new Dictionary <string, Price>()));
        }
        public void ShouldGetProductPriceInCurrencyFromService(string priceType)
        {
            // Arrange
            this.client.GetProductPrice("Product", priceType).Returns(1);
            var request = new GetProductPricesRequest("Product", new[] { priceType });

            request.CurrencyCode = "CAD";
            var args = new ServicePipelineArgs(request, new GetProductPricesResult());

            // Act
            this.processor.Process(args);
            var result = ((GetProductPricesResult)args.Result).Prices;

            // Assert
            result[priceType].Amount.Should().Be(1);
            result[priceType].PriceType.Should().Be(priceType);
            result[priceType].CurrencyCode = "CAD";
        }
        public ManagerResponse <GetProductPricesResult, IDictionary <string, Price> > GetProductPrices(string catalogName, string productId, bool includeVariants, string userId, params string[] priceTypeIds)
        {
            if (priceTypeIds == null)
            {
                priceTypeIds = _defaultPriceTypeIds;
            }

            var request = new GetProductPricesRequest(productId, priceTypeIds)
            {
                DateTime = GetCurrentDate()
            };

            request.UserId = userId;

            request.CurrencyCode = CurrencyManager.CurrencyContext.CurrencyCode;
            var result = PricingServiceProvider.GetProductPrices(request);

            result.WriteToSitecoreLog();
            return(new ManagerResponse <GetProductPricesResult, IDictionary <string, Price> >(result, result.Prices ?? new Dictionary <string, Price>()));
        }
        /// <summary>
        /// The update prices.
        /// </summary>
        /// <param name="cart">The cart.</param>
        /// <returns>
        /// The <see cref="Cart" />.
        /// </returns>
        private Cart UpdatePrices([NotNull] Cart cart)
        {
            Assert.ArgumentNotNull(cart, "cart");

            // TODO: [Low] Consider using standard approach for getting prices when it will be implemented.
            foreach (var cartLine in cart.Lines)
            {
                if (cartLine.Product != null && cartLine.Product.ProductId != null)
                {
                    var   priceRequest = new GetProductPricesRequest(cartLine.Product.ProductId, "List");
                    var   priceResult  = this._pricingServiceProvider.GetProductPrices(priceRequest);
                    Price price;

                    if (priceResult.Prices.TryGetValue("List", out price))
                    {
                        cartLine.Product.Price = price;
                    }
                }
            }

            return(cart);
        }
        protected override void RenderContent(PrintContext printContext, XElement output)
        {
            string ListPriceKey = "List";

            XElement baseXml = new XElement("base");

            base.RenderContent(printContext, baseXml);

            XElement textFrame = baseXml.Element("TextFrame");
            Item     dataItem  = GetDataItem(printContext);

            XElement xElement = RenderItemHelper.CreateXElement("TextFrame", base.RenderingItem, printContext.Settings.IsClient, dataItem);

            this.SetAttributes(xElement);

            output.Add(xElement);

            XAttribute xAttribute = output.Attribute("ParagraphStyle");
            string     text       = (xAttribute != null && !string.IsNullOrEmpty(xAttribute.Value)) ? xAttribute.Value : "H1 Orange";

            Field     fieldname = dataItem.Fields[this.ContentFieldName];
            DateField dateField = fieldname;

            var request  = new GetProductPricesRequest(dataItem["ExternalID"]);
            var response = new PricingServiceProvider();
            var price    = response.GetProductPrices(request).Prices[ListPriceKey].Amount;
            //var price = response.Prices.ContainsKey(ListPriceKey) ? response.Prices[ListPriceKey].Amount : decimal.Zero;

            //var price = this.pricingService.GetProductPrice("11");

            IEnumerable <XElement> result = this.FormatText(text, price.ToString("c"));

            xElement.Add(result);

            this.RenderChildren(printContext, xElement);
        }
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(Commerce.Pipelines.ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.request");
            Assert.ArgumentCondition(args.Request is GetProductPricesRequest, "args.Request", "args.Request is GetProductPricesRequest");
            Assert.ArgumentCondition(args.Result is Sitecore.Commerce.Services.Prices.GetProductPricesResult, "args.Result", "args.Result is GetProductPricesResult");

            GetProductPricesRequest request = (GetProductPricesRequest)args.Request;

            Sitecore.Commerce.Services.Prices.GetProductPricesResult result = (Sitecore.Commerce.Services.Prices.GetProductPricesResult)args.Result;

            Assert.ArgumentNotNull(request.ProductCatalogName, "request.ProductCatalogName");
            Assert.ArgumentNotNull(request.ProductId, "request.ProductId");
            Assert.ArgumentNotNull(request.PriceTypeIds, "request.PriceTypeIds");

            ICatalogRepository catalogRepository = ContextTypeLoader.CreateInstance <ICatalogRepository>();
            bool isList     = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.List, StringComparison.OrdinalIgnoreCase)) != null;
            bool isAdjusted = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.Adjusted, StringComparison.OrdinalIgnoreCase)) != null;

            try
            {
                var product = catalogRepository.GetProductReadOnly(request.ProductCatalogName, request.ProductId);

                ExtendedCommercePrice extendedPrice = this.EntityFactory.Create <ExtendedCommercePrice>("Price");

                // BasePrice is a List price and ListPrice is Adjusted price
                if (isList)
                {
                    if (product.HasProperty("BasePrice") && product["BasePrice"] != null)
                    {
                        extendedPrice.Amount = (product["BasePrice"] as decimal?).Value;
                    }
                    else
                    {
                        // No base price is defined, the List price is set to the actual ListPrice define in the catalog
                        extendedPrice.Amount = product.ListPrice;
                    }
                }

                if (isAdjusted && !product.IsListPriceNull())
                {
                    extendedPrice.ListPrice = product.ListPrice;
                }

                result.Prices.Add(request.ProductId, extendedPrice);

                if (request.IncludeVariantPrices && product is ProductFamily)
                {
                    foreach (Variant variant in ((ProductFamily)product).Variants)
                    {
                        ExtendedCommercePrice variantExtendedPrice = this.EntityFactory.Create <ExtendedCommercePrice>("Price");

                        bool hasBasePrice = product.HasProperty("BasePrice");

                        if (hasBasePrice && variant["BasePriceVariant"] != null)
                        {
                            variantExtendedPrice.Amount = (variant["BasePriceVariant"] as decimal?).Value;
                        }

                        if (!variant.IsListPriceNull())
                        {
                            variantExtendedPrice.ListPrice = variant.ListPrice;

                            if (!hasBasePrice)
                            {
                                variantExtendedPrice.Amount = variant.ListPrice;
                            }
                        }

                        result.Prices.Add(variant.VariantId.Trim(), variantExtendedPrice);
                    }
                }
            }
            catch (EntityDoesNotExistException e)
            {
                result.Success = false;
                result.SystemMessages.Add(new SystemMessage {
                    Message = e.Message
                });
            }
        }
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(Commerce.Pipelines.ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.request");
            Assert.ArgumentCondition(args.Request is GetProductPricesRequest, "args.Request", "args.Request is GetProductPricesRequest");
            Assert.ArgumentCondition(args.Result is GetProductPricesResult, "args.Result", "args.Result is GetProductPricesResult");

            GetProductPricesRequest request = (GetProductPricesRequest)args.Request;
            GetProductPricesResult  result  = (GetProductPricesResult)args.Result;

            Assert.ArgumentNotNull(request.ProductCatalogName, "request.ProductCatalogName");
            Assert.ArgumentNotNull(request.ProductId, "request.ProductId");
            Assert.ArgumentNotNull(request.PriceTypeIds, "request.PriceTypeIds");

            ICatalogRepository catalogRepository = CommerceTypeLoader.CreateInstance <ICatalogRepository>();
            bool isList     = Array.FindIndex(request.PriceTypeIds as string[], t => t.IndexOf("List", StringComparison.OrdinalIgnoreCase) >= 0) > -1;
            bool isAdjusted = Array.FindIndex(request.PriceTypeIds as string[], t => t.IndexOf("Adjusted", StringComparison.OrdinalIgnoreCase) >= 0) > -1;

            try
            {
                var product = catalogRepository.GetProductReadOnly(request.ProductCatalogName, request.ProductId);
                Dictionary <string, Price> prices = new Dictionary <string, Price>();

                // BasePrice is a List price and ListPrice is Adjusted price
                if (isList)
                {
                    if (product.HasProperty("BasePrice") && product["BasePrice"] != null)
                    {
                        prices.Add("List", new Price {
                            PriceType = "List", Amount = (product["BasePrice"] as decimal?).Value
                        });
                    }
                    else
                    {
                        // No base price is defined, the List price is set to the actual ListPrice define in the catalog
                        prices.Add("List", new Price {
                            PriceType = "List", Amount = product.ListPrice
                        });
                    }
                }

                if (isAdjusted && !product.IsListPriceNull())
                {
                    prices.Add("Adjusted", new Price {
                        PriceType = "Adjusted", Amount = product.ListPrice
                    });
                }

                result.Prices.Add(request.ProductId, prices);
                if (request.IncludeVariantPrices && product is ProductFamily)
                {
                    foreach (Variant variant in ((ProductFamily)product).Variants)
                    {
                        Dictionary <string, Price> variantPrices = new Dictionary <string, Price>();
                        if (isList && product.HasProperty("BasePrice") && variant["BasePriceVariant"] != null)
                        {
                            variantPrices.Add("List", new Price {
                                PriceType = "List", Amount = (variant["BasePriceVariant"] as decimal?).Value
                            });
                        }

                        if (isAdjusted && !variant.IsListPriceNull())
                        {
                            variantPrices.Add("Adjusted", new Price {
                                PriceType = "Adjusted", Amount = variant.ListPrice
                            });
                        }

                        result.Prices.Add(variant.VariantId, variantPrices);
                    }
                }
            }
            catch (CommerceServer.Core.EntityDoesNotExistException e)
            {
                result.Success = false;
                result.SystemMessages.Add(new SystemMessage {
                    Message = e.Message
                });
            }
        }
        /// <summary>
        /// Gets the product prices.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="productId">The product identifier.</param>
        /// <param name="priceTypeIds">The price type ids.</param>
        /// <returns>The manager response with the list of prices in the Result.</returns>
        public virtual ManagerResponse<GetProductPricesResult, IDictionary<string, Price>> GetProductPrices([NotNull] CommerceStorefront storefront, string productId, params string[] priceTypeIds)
        {
            Assert.ArgumentNotNull(storefront, "storefront");

            var request = new GetProductPricesRequest(productId, priceTypeIds);
            var result = this.PricingServiceProvider.GetProductPrices(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return new ManagerResponse<GetProductPricesResult, IDictionary<string, Price>>(result, result.Prices ?? new Dictionary<string, Price>());
        }
 /// <summary>
 /// Gets the product prices.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>Returns product prices.</returns>
 public virtual GetProductPricesResult GetProductPrices(GetProductPricesRequest request)
 {
     return(this.RunPipeline <GetProductPricesRequest, GetProductPricesResult>("commerce.prices.getProductPrices", request));
 }