Esempio n. 1
0
        public RelatedProductsViewModel GetRelatedProducts(Product product)
        {
            var model = new RelatedProductsViewModel {
                Title = String.Empty
            };
            var products = new List <Product>();

            if (product != null)
            {
                model.Title = "Related Products";
                if (product.PublishedRelatedProducts.Any())
                {
                    products.AddRange(product.PublishedRelatedProducts.Take(4));
                }
                else
                {
                    if (product.Categories.Any())
                    {
                        products.AddRange(product.Categories.Last()
                                          .Products.Where(x => x.Id != product.Id && x.Published).Take(4));
                    }
                }
            }
            model.Products = products.Distinct().ToList().GetCardModels();
            model.Cart     = _cart;
            return(model);
        }
Esempio n. 2
0
        /// <summary>
        /// A method to retrieve a list of Product and Variant Ids for products. This method can be used in collaboration with
        /// <seealso cref="GetRelatedProductsAsync"/> to retrieve the full set of products.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>
        /// This method returns a <see cref="RelatedProductsViewModel"/>, however none of its properties will be set.
        /// The returned object is really just a container for the context to expose the produt identifiers to the
        /// JsonContext on the front end.
        /// </returns>
        public async virtual Task <RelatedProductsViewModel> GetProductIdsAsync(TParam param)
        {
            // the identifiers will only be used by the front end
            var vm = new RelatedProductsViewModel();

            vm.Context["ProductIdentifiers"] = await GetProductIdentifiersAsync(param).ConfigureAwait(false);

            return(vm);
        }
Esempio n. 3
0
        public async Task <IViewComponentResult> InvokeAsync(int categoryId, int productId)
        {
            var viewModel = new RelatedProductsViewModel
            {
                Products = await this.productService.GetRelatedProductsByCategoryIdAsync <SingleProductViewModel>(categoryId, productId),
            };

            return(this.View(viewModel));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var viewModel = new RelatedProductsViewModel
            {
                Products = await this.productService.GetMostBuyedProductsAsync <SingleProductViewModel>(),
            };

            return(this.View(viewModel));
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a <see cref="RelatedProductsViewModel"/> which is just a container for a list of <see cref="RelatedProductViewModel"/>
        /// </summary>
        /// <returns></returns>
        protected virtual RelatedProductsViewModel CreateRelatedProductsViewModel(CreateRelatedProductViewModelParam param)
        {
            var relatedProductsViewModel = new RelatedProductsViewModel();

            //iterate over the requested products
            foreach (var productVariant in param.ProductsWithVariant)
            {
                // call the method that actually does the mapping for an individual product
                var productVm = CreateRelatedProductsViewModel(param.BaseUrl, param.CultureInfo, productVariant, param.Prices, param.Images);
                relatedProductsViewModel.Products.Add(productVm);
            }

            return(relatedProductsViewModel);
        }
Esempio n. 6
0
        public IActionResult relatedproducts()
        {
            var allProduct = productRepository.GetAll().Select(c => new ProductReleted()
            {
                ProductID   = c.ProductID,
                ProductName = c.Name
            }).ToList();

            RelatedProductsViewModel model = new RelatedProductsViewModel
            {
                ProductForDisplay = allProduct,
            };

            return(View(model));
        }
Esempio n. 7
0
        public async Task <IActionResult> relatedproducts(RelatedProductsViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.MainProductID == model.RelatedProductID)
                    {
                        throw new Exception("محصولات انتخاب شده یکی میباشد");
                    }

                    if (ProductInfoRepository.CheckExist(model.MainProductID, "RelatedProduct", model.RelatedProductID.ToString()))
                    {
                        throw new Exception("قبلا ثبت شده است");
                    }



                    ProductInfo productInfo = new ProductInfo()
                    {
                        key       = "RelatedProduct",
                        productID = model.MainProductID,
                        Value     = model.RelatedProductID.ToString(),
                    };

                    await ProductInfoRepository.AddAsync(productInfo);
                }
                else
                {
                    var errors = ModelState.Select(x => x.Value.Errors)
                                 .Where(y => y.Count > 0)
                                 .ToList();
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            var allprd = productRepository.GetAll().Select(c => new ProductReleted()
            {
                ProductID   = c.ProductID,
                ProductName = c.Name
            }).ToList();

            model.ProductForDisplay = allprd;
            return(View(model));
        }
Esempio n. 8
0
        public ActionResult RelatedProducts(int categoryID, int productID, int pageSize = 0)
        {
            if (pageSize == 0)
            {
                pageSize = ConfigurationsHelper.RelatedProductsRecordsSizePerPage;
            }

            HttpCookie LangCookie = Request.Cookies["LangCookie"];

            RelatedProductsViewModel model = new RelatedProductsViewModel();

            model.Products = ProductsService.Instance.SearchProducts(new List <int>()
            {
                categoryID
            }, null, null, null, null, 1, pageSize);


            if (model.Products != null && model.Products.Count >= ConfigurationsHelper.RelatedProductsRecordsSizePerPage)
            {
                model.PageTitle = model.Products.FirstOrDefault().Category.Name;
            }
            else
            {
                //the realted products are less than the specfified RelatedProductsRecordsSizePerPage, so instead show featured products
                model.PageTitle = string.Format("{0}'s", ConfigurationsHelper.ApplicationName);
                model.Products  = ProductsService.Instance.SearchFeaturedProducts(pageSize);
            }

            if (LangCookie != null)
            {
                if (LangCookie.Value == "ar")
                {
                    foreach (var elem in model.Products.ToList())
                    {
                        elem.Name          = elem.ArName;
                        elem.Description   = elem.ArDescription;
                        elem.Summary       = elem.ArSummary;
                        elem.Category.Name = elem.Category.ArName;
                    }
                }
            }

            return(PartialView("_RelatedProducts", model));
        }