Example #1
0
        /// <summary>
        /// This method retrieves all the products for a product given in the <see cref="GetRelatedProductsParam"/>
        /// then converts them to to a <see cref="RelatedProductsViewModel"/>. The change the behaviour of this method,
        /// developers should override <seealso cref="RetrieveProductsAsync"/> or <seealso cref="CreateRelatedProductsViewModel(Orckestra.Composer.Product.Parameters.CreateRelatedProductViewModelParam)"/>.
        /// This method makes a number of asynchronous calls, so in cases where only the product IDs are desired,
        /// <seealso cref="GetProductIdsAsync"/> should be used.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async virtual Task <RelatedProductsViewModel> GetRelatedProductsAsync(GetRelatedProductsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            if (!param.ProductIds.Any())
            {
                return(new RelatedProductsViewModel());
            }

            var products = await RetrieveProductsAsync(param).ConfigureAwait(false);

            // make a single request to get all product prices at once, instead of making a request for each product
            var productIds = param.ProductIds.Select(p => p.ProductId).ToList();
            var prices     = ProductRepository.CalculatePricesAsync(productIds, param.Scope);
            var images     = GetImagesAsync(products);
            await Task.WhenAll(prices, images);

            var createVmParam = new CreateRelatedProductViewModelParam
            {
                BaseUrl             = param.BaseUrl,
                CultureInfo         = param.CultureInfo,
                ProductsWithVariant = products,
                Scope  = param.Scope,
                Prices = await prices,
                Images = await images
            };

            var vm = CreateRelatedProductsViewModel(createVmParam);

            return(vm);
        }
        public virtual async Task <IHttpActionResult> RelatedProducts(IEnumerable <ProductIdentifier> relatedProductIdentifiers)  //TODO: Make a ViewModel for this.
        {
            var param = new GetRelatedProductsParam
            {
                ProductIds  = relatedProductIdentifiers,
                CultureInfo = ComposerContext.CultureInfo,
                Scope       = ComposerContext.Scope,
                BaseUrl     = RequestUtils.GetBaseUrl(Request)
            };

            var vm = await RelatedProductViewService.GetRelatedProductsAsync(param);

            return(Ok(vm));
        }
Example #3
0
        /// <summary>
        /// Gets a list of products with the defined variant specified.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>
        /// An array of <see cref="ProductWithVariant"/>.
        /// This class is used instead of the <see cref="Overture.ServiceModel.Products.Product"/> class
        /// because specific variants are presented to the user when specified in Orchestrator.
        /// </returns>
        protected virtual async Task <ProductWithVariant[]> RetrieveProductsAsync(GetRelatedProductsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var productRequestTasks = new List <Task <ProductWithVariant> >();

            foreach (var productIdentifier in param.ProductIds)
            {
                // it's helpful to tie the VariantId to the product at this point
                var task = GetProductWithVariantAsync(productIdentifier.ProductId, productIdentifier.VariantId,
                                                      param.Scope, param.CultureInfo);
                productRequestTasks.Add(task);
            }

            var products = await Task.WhenAll(productRequestTasks).ConfigureAwait(false);

            var results = products.Where(p => p != null).ToArray();

            return(results);
        }
 public async Task <ProductWithVariant[]> RetrieverRelatedProductsAsyncProxy(GetRelatedProductsParam param)
 {
     return(await RetrieveProductsAsync(param));
 }
Example #5
0
        public override async Task <RelatedProductsViewModel> GetRelatedProductsAsync(GetRelatedProductsParam param)
        {
            var vm = await base.GetRelatedProductsAsync(param).ConfigureAwait(false);

            vm.Context["ListName"] = "Related Products";

            return(vm);
        }