Esempio n. 1
0
        private void MapRelatedProductToProductVm(Product product, ProductDetail model)
        {
            foreach (var productLink in product.ProductLinks.Where(x => x.LinkType == ProductLinkType.Relation))
            {
                var relatedProduct   = productLink.LinkedProduct;
                var productThumbnail = new ProductThumbnail
                {
                    Id                = relatedProduct.Id,
                    Name              = relatedProduct.Name,
                    SeoTitle          = relatedProduct.SeoTitle,
                    Price             = relatedProduct.Price,
                    OldPrice          = relatedProduct.OldPrice,
                    SpecialPrice      = relatedProduct.SpecialPrice,
                    SpecialPriceStart = relatedProduct.SpecialPriceStart,
                    SpecialPriceEnd   = relatedProduct.SpecialPriceEnd,
                    StockQuantity     = relatedProduct.StockQuantity,
                    IsAllowToOrder    = relatedProduct.IsAllowToOrder,
                    IsCallForPricing  = relatedProduct.IsCallForPricing,
                    ThumbnailImage    = relatedProduct.ThumbnailImage,
                    NumberVariation   = relatedProduct.ProductLinks.Count,
                    ReviewsCount      = relatedProduct.ReviewsCount,
                    RatingAverage     = relatedProduct.RatingAverage
                };

                productThumbnail.ThumbnailUrl           = _mediaService.GetThumbnailUrl(relatedProduct.ThumbnailImage);
                productThumbnail.CalculatedProductPrice = _productPricingService.CalculateProductPrice(relatedProduct);

                model.RelatedProducts.Add(productThumbnail);
            }
        }
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            var model = new SimpleProductWidgetComponentVm
            {
                Id         = widgetInstance.Id,
                WidgetName = widgetInstance.Name,
                Setting    = JsonConvert.DeserializeObject <SimpleProductWidgetSetting>(widgetInstance.Data)
            };

            foreach (var item in model.Setting.Products)
            {
                var product = _productRepository.Query().Where(x => x.Id == item.Id).FirstOrDefault();

                if (product != null)
                {
                    var productThumbnail = ProductThumbnail.FromProduct(product);
                    productThumbnail.Name                   = _contentLocalizationService.GetLocalizedProperty(nameof(Product), productThumbnail.Id, nameof(product.Name), productThumbnail.Name);
                    productThumbnail.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                    productThumbnail.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
                    model.Products.Add(productThumbnail);
                }
            }

            return(View(this.GetViewPath(), model));
        }
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            var model = new ProductWidgetComponentVm
            {
                Id         = widgetInstance.Id,
                WidgetName = widgetInstance.Name,
                Setting    = JsonConvert.DeserializeObject <ProductWidgetSetting>(widgetInstance.Data)
            };

            var query = _productRepository.Query()
                        .Where(x => x.IsPublished && x.IsVisibleIndividually);

            if (model.Setting.CategoryId.HasValue && model.Setting.CategoryId.Value > 0)
            {
                query = query.Where(x => x.Categories.Any(c => c.CategoryId == model.Setting.CategoryId.Value));
            }

            if (model.Setting.FeaturedOnly)
            {
                query = query.Where(x => x.IsFeatured);
            }

            model.Products = query
                             .Include(x => x.ThumbnailImage)
                             .OrderByDescending(x => x.CreatedOn)
                             .Take(model.Setting.NumberOfProducts)
                             .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            foreach (var product in model.Products)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }
            return(View(this.GetViewPath(), model));
        }
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            List <Product> productlist = new List <Product>();
            var            model       = new HomeProductWidegtViewModel
            {
                Id         = widgetInstance.Id,
                WidgetName = widgetInstance.Name,
                Settings   = JsonConvert.DeserializeObject <HomeProductWidgetSetting>(widgetInstance.Data)
            };

            if (model == null)
            {
                return(View());
            }
            foreach (var item in model.Settings.ProductIds)
            {
                var product = _productRepository.Query().Where(x => x.Id == Convert.ToInt64(item.ProductId)).FirstOrDefault();

                if (product != null)
                {
                    productlist.Add(product);
                }
            }

            model.Products = productlist.OrderByDescending(x => x.CreatedOn)
                             .Take(model.Settings.NumberofProducts)
                             .Select(x => ProductThumbnail.FromProduct(x)).ToList();
            foreach (var product in model.Products)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View("/Modules/SimplCommerce.Module.Cms/Views/Components/HomeProductWidget.cshtml", model));
        }
Esempio n. 5
0
        public IActionResult Index(SearchOption searchOption)
        {
            if (string.IsNullOrWhiteSpace(searchOption.Width) || string.IsNullOrWhiteSpace(searchOption.Profile) ||
                string.IsNullOrWhiteSpace(searchOption.RimSize))
            {
                return(Redirect("~/"));
            }

            var model = new SearchResult
            {
                CurrentSearchOption = searchOption
            };

            var query = _productRepository.Query().Where(x =>
                                                         x.Category.Name == searchOption.Category &&
                                                         x.TyreWidth.Size == searchOption.Width && x.TyreProfile.Size == searchOption.Profile &&
                                                         x.TyreRimSize.Size == searchOption.RimSize && x.IsPublished);

            if (!query.Any())
            {
                model.TotalProduct = 0;
                return(View(model));
            }

            model.TotalProduct = query.Count();

            var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page;

            var offset = (_pageSize * currentPageNum) - _pageSize;

            while (currentPageNum > 1 && offset > model.TotalProduct)
            {
                currentPageNum--;
                offset = (_pageSize * currentPageNum) - _pageSize;
            }

            // todo: save query (search) to db

            query = query.Include(x => x.ThumbnailImage);

            var products = query
                           .Select(x => ProductThumbnail.FromProduct(x))
                           .Skip(offset)
                           .Take(_pageSize)
                           .ToList();

            foreach (var product in products)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            model.Products = products;
            model.CurrentSearchOption.PageSize = _pageSize;
            model.CurrentSearchOption.Page     = currentPageNum;

            return(View(model));
        }
Esempio n. 6
0
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            var model = new ProductWidgetComponentVm
            {
                Id         = widgetInstance.Id,
                WidgetName = _contentLocalizationService.GetLocalizedProperty(nameof(WidgetInstance), widgetInstance.Id, nameof(widgetInstance.Name), widgetInstance.Name),
                Setting    = JsonConvert.DeserializeObject <ProductWidgetSetting>(widgetInstance.Data)
            };

            var query = _productRepository.Query()
                        .Where(x => x.IsPublished && x.IsVisibleIndividually);

            if (model.Setting.CategoryId.HasValue && model.Setting.CategoryId.Value > 0)
            {
                query = query.Where(x => x.Categories.Any(c => c.CategoryId == model.Setting.CategoryId.Value));
            }

            if (model.Setting.FeaturedOnly)
            {
                query = query.Where(x => x.IsFeatured);
            }

            if (model.Setting.OrderBy == ProductWidgetOrderBy.Newest)
            {
                query = query.OrderByDescending(p => p.CreatedOn);
            }

            if (model.Setting.OrderBy == ProductWidgetOrderBy.BestSelling)
            {
                //TODO: ProductWidgetOrderBy.BestSelling must be managed
                // create a new  property in product incremented each time a product
                // is created or updated or calculated how many time the products already
                // ordered ?
            }

            var productThumbnail = query
                                   .Include(x => x.ThumbnailImage)
                                   .Select(x => ProductThumbnail.FromProduct(x));

            if (model.Setting.OrderBy == ProductWidgetOrderBy.Discount)
            {
                model.Products = model.Products.OrderByDescending(p => p.CalculatedProductPrice.PercentOfSaving).ToList();
            }



            model.Products = productThumbnail.Take(model.Setting.NumberOfProducts).ToList();

            foreach (var product in model.Products)
            {
                product.Name                   = _contentLocalizationService.GetLocalizedProperty(nameof(Product), product.Id, nameof(product.Name), product.Name);
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View(this.GetViewPath(), model));
        }
Esempio n. 7
0
        public IActionResult Collection()
        {
            var widgetInstances = _widgetInstanceRepository.Query()
                                  .Where(x => x.WidgetId == WidgetIds.ProductWidget)
                                  .OrderBy(x => x.DisplayOrder)
                                  .Select(x => new
            {
                Id         = x.Id,
                WidgetName = x.Name,
                Setting    = JsonConvert.DeserializeObject <ProductWidgetSetting>(x.Data)
            })
                                  .ToList();

            var productWidgets = new List <ProductWidgetComponentVm>();

            foreach (var item in widgetInstances)
            {
                var model = new ProductWidgetComponentVm
                {
                    Id         = item.Id,
                    WidgetName = item.WidgetName,
                    Setting    = item.Setting
                };

                var query = _productRepository.Query()
                            .Where(x => x.IsPublished && x.IsVisibleIndividually);

                if (model.Setting.CategoryId.HasValue && model.Setting.CategoryId.Value > 0)
                {
                    query = query.Where(x => x.Categories.Any(c => c.CategoryId == model.Setting.CategoryId.Value));
                }

                if (model.Setting.FeaturedOnly)
                {
                    query = query.Where(x => x.IsFeatured);
                }

                model.Products = query
                                 .Include(x => x.ThumbnailImage)
                                 .OrderByDescending(x => x.CreatedOn)
                                 .Take(model.Setting.NumberOfProducts)
                                 .Select(x => ProductThumbnail.FromProduct(x)).ToList();

                foreach (var product in model.Products)
                {
                    product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                    product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
                }

                productWidgets.Add(model);
            }
            ;
            return(Json(productWidgets));
        }
Esempio n. 8
0
        internal ProfileMySpecificOrderPartialVM GetSpecificOrder(int id)
        {
            ProfileMySpecificOrderPartialVM myOrder = new ProfileMySpecificOrderPartialVM();

            OrderArticles[]         orderArticles = OrderArticles.Where(o => o.Oid == id).ToArray();
            List <ProductThumbnail> prodThumbList = new List <ProductThumbnail>();

            myOrder.OrderArticles = new ProductThumbnail[orderArticles.Length];

            foreach (var item in orderArticles)
            {
                bool IsExisting = false;
                if (prodThumbList.Count > 0)
                {
                    foreach (var prod in prodThumbList)
                    {
                        if (item.ArticleNumber == $"{prod.ArticleNrShort}{prod.Size}")
                        {
                            int articleCount = prod.NumberOfSameArticle;
                            articleCount++;

                            prod.NumberOfSameArticle = articleCount;
                            IsExisting = true;
                        }
                    }
                }
                if (!IsExisting)
                {
                    Product currentProduct = Product.First(p => p.ProdArtNr == item.ArticleNumber);
                    Brand   currentBrand   = Brand.First(b => b.BrandId == currentProduct.ProdBrandId);
                    Model   currentModel   = Model.First(m => m.ModelId == currentProduct.ProdModelId);
                    Size    currentSize    = Size.First(s => s.SizeId == currentProduct.ProdSizeId);
                    Color   currentColor   = Color.First(c => c.ColorId == currentProduct.ProdColorId);


                    ProductThumbnail currentThumbnail = new ProductThumbnail
                    {
                        Brand = currentBrand.BrandName,
                        Model = currentModel.ModelName,
                        Price = Convert.ToInt32(currentProduct.ProdPrice),
                        NumberOfSameArticle = 1,
                        Size           = currentSize.SizeName,
                        Color          = currentColor.ColorName,
                        ImgPath        = $"{currentProduct.ProdArtNr.Remove(currentProduct.ProdArtNr.Length - 2)}_1.jpg",
                        ArticleNrShort = currentProduct.ProdArtNr.Substring(0, 5)
                    };
                    prodThumbList.Add(currentThumbnail);
                }
            }

            myOrder.OrderArticles = prodThumbList.ToArray();
            return(myOrder);
        }
Esempio n. 9
0
        internal static MyShoppingCartVM GetArticles(Controller controller, WebShopDBContext context)
        {
            //int count = Convert.ToInt32(GetSessionCount(controller));
            int count                             = Convert.ToInt32(GetSingleSessionCount(controller));
            int totalCost                         = 0;
            int totalNumberOfProducts             = 0;
            MyShoppingCartVM        myCart        = new MyShoppingCartVM();
            List <ProductThumbnail> prodThumbList = new List <ProductThumbnail>();
            string currentArtNr;

            if (count != 0)
            {
                for (int i = 0; i < count; i++)
                {
                    string[] splitString = controller.HttpContext.Session.GetString(i.ToString()).Split(';');
                    currentArtNr = splitString[0];
                    Product currentProduct = context.Product.First(p => p.ProdArtNr == currentArtNr);
                    totalCost             += Convert.ToInt32(currentProduct.ProdPrice) * Convert.ToInt32(splitString[1]);
                    totalNumberOfProducts += Convert.ToInt32(splitString[1]);



                    Model currentModel = context.Model.First(m => m.ModelId == currentProduct.ProdModelId);
                    Brand currentBrand = context.Brand.First(b => b.BrandId == currentProduct.ProdBrandId);
                    Size  currentSize  = context.Size.First(s => s.SizeId == currentProduct.ProdSizeId);
                    Color currentColor = context.Color.First(c => c.ColorId == currentProduct.ProdColorId);


                    ProductThumbnail currentThumbnail = new ProductThumbnail
                    {
                        Brand = currentBrand.BrandName,
                        Model = currentModel.ModelName,
                        Price = Convert.ToInt32(currentProduct.ProdPrice),
                        NumberOfSameArticle = Convert.ToInt32(splitString[1]),
                        Size           = currentSize.SizeName,
                        Color          = currentColor.ColorName,
                        ImgPath        = $"{currentProduct.ProdArtNr.Remove(currentProduct.ProdArtNr.Length - 2)}_1.jpg",
                        ArticleNrShort = currentProduct.ProdArtNr.Substring(0, 5)
                    };
                    prodThumbList.Add(currentThumbnail);
                }
                myCart.Products = prodThumbList.ToArray();
            }

            myCart.TotalNumberOfProducts = totalNumberOfProducts;
            myCart.TotalCost             = totalCost;
            return(myCart);
        }
Esempio n. 10
0
        public IViewComponentResult Invoke()
        {
            var products = _productRepository.Query()
                           .Include(x => x.ThumbnailImage)
                           .Where(x => x.IsPublished && x.IsVisibleIndividually)
                           .Where(x => x.SpecialPriceStart.HasValue && x.SpecialPriceEnd.HasValue)
                           .Where(x => x.SpecialPriceEnd.Value > DateTimeOffset.Now)
                           .OrderByDescending(x => x.CreatedOn)
                           .Select(x => ProductThumbnail.FromProduct(x))
                           .ToList();

            foreach (var product in products)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View(this.GetViewPath(), products));
        }
Esempio n. 11
0
        // TODO Number of items to config
        public IViewComponentResult Invoke(long?productId)
        {
            var user = _workContext.GetCurrentUser().Result;
            IQueryable <Product> query = _productRepository.GetRecentlyViewedProduct(user.Id)
                                         .Include(x => x.ThumbnailImage);

            if (productId.HasValue)
            {
                query = query.Where(x => x.Id != productId.Value);
            }

            var model = query.Take(5)
                        .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            foreach (var product in model)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View("/Modules/SimplCommerce.Module.ProductRecentlyViewed/Views/Components/ProductRecentlyViewed.cshtml", model));
        }
Esempio n. 12
0
        // TODO Number of items to config
        public IViewComponentResult Invoke(long?productId, int itemCount = 5)
        {
            var user = _workContext.GetCurrentUser().Result;
            IQueryable <Product> query = _productRepository.GetRecentlyViewedProduct(user.Id)
                                         .Include(x => x.ThumbnailImage);

            if (productId.HasValue)
            {
                query = query.Where(x => x.Id != productId.Value);
            }

            var model = query.Take(itemCount)
                        .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            foreach (var product in model)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View(this.GetViewPath(), model));
        }
Esempio n. 13
0
        private void MapRelatedProductToProductVm(Product product, ProductDetail model)
        {
            var publishedProductLinks = product.ProductLinks.Where(x => x.LinkedProduct.IsPublished && (x.LinkType == ProductLinkType.Related || x.LinkType == ProductLinkType.CrossSell));

            foreach (var productLink in publishedProductLinks)
            {
                var linkedProduct    = productLink.LinkedProduct;
                var productThumbnail = ProductThumbnail.FromProduct(linkedProduct);

                productThumbnail.ThumbnailUrl           = _mediaService.GetThumbnailUrl(linkedProduct.ThumbnailImage);
                productThumbnail.CalculatedProductPrice = _productPricingService.CalculateProductPrice(linkedProduct);

                if (productLink.LinkType == ProductLinkType.Related)
                {
                    model.RelatedProducts.Add(productThumbnail);
                }

                if (productLink.LinkType == ProductLinkType.CrossSell)
                {
                    model.CrossSellProducts.Add(productThumbnail);
                }
            }
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Configs.Initialize();

            int key = -1;

Start:
            Menu();
            Int32.TryParse(Console.ReadLine().ToString(), out key);
            while (key != 0)
            {
                ICreateThumbnail _thumbnail = null;
                switch (key)
                {
                case 1:
                    _thumbnail = new ProductThumbnail();
                    break;

                case 2: _thumbnail = new CategoryThumbnail(); break;

                case 3: _thumbnail = new OtherThumbnail(); break;

                case 4: Configs.UpdateSettings(); break;

                case 5: Configs.UpdateLocalPath(); break;
                }

                if (_thumbnail != null)
                {
                    _thumbnail.CreateThumbnails();
                }
                goto Start;
            }
        }
        // TODO Number of items to config
        public async Task <IViewComponentResult> InvokeAsync(long?productId, int itemCount = 4)
        {
            var user = await _workContext.GetCurrentUser();

            IQueryable <Product> query = _productRepository.GetRecentlyViewedProduct(user.Id)
                                         .Include(x => x.ThumbnailImage);

            if (productId.HasValue)
            {
                query = query.Where(x => x.Id != productId.Value);
            }

            var model = query.Take(itemCount)
                        .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            foreach (var product in model)
            {
                product.Name                   = _contentLocalizationService.GetLocalizedProperty(nameof(Product), product.Id, nameof(product.Name), product.Name);
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View(this.GetViewPath(), model));
        }
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            var model = new SimpleProductWidgetComponentVm
            {
                Id = widgetInstance.Id,
                WidgetName = widgetInstance.Name,
                Setting = JsonConvert.DeserializeObject<SimpleProductWidgetSetting>(widgetInstance.Data)
            };

            foreach (var item in model.Setting.Products)
            {
                var product = _productRepository.Query().Where(x => x.Id == item.Id).FirstOrDefault();

                if (product != null)
                {
                    var productThumbnail = ProductThumbnail.FromProduct(product);
                    productThumbnail.ThumbnailUrl = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                    productThumbnail.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
                    model.Products.Add(productThumbnail);
                }
            }

            return View("/Modules/SimplCommerce.Module.Catalog/Views/Components/SimpleProductWidget.cshtml", model);
        }
Esempio n. 17
0
        public IActionResult BrandDetail(long id, SearchOption searchOption)
        {
            var brand = _brandRepository.Query().FirstOrDefault(x => x.Id == id);

            if (brand == null)
            {
                return(Redirect("~/Error/FindNotFound"));
            }

            var model = new ProductsByBrand
            {
                BrandId             = id,
                BrandName           = brand.Name,
                BrandSlug           = brand.Slug,
                CurrentSearchOption = searchOption,
                FilterOption        = new FilterOption()
            };

            var query = _productRepository.Query().Where(x => x.BrandId == id && x.IsPublished && x.IsVisibleIndividually);

            if (query.Count() == 0)
            {
                model.TotalProduct = 0;
                return(View(model));
            }

            AppendFilterOptionsToModel(model, query);

            if (searchOption.MinPrice.HasValue)
            {
                query = query.Where(x => x.Price >= searchOption.MinPrice.Value);
            }

            if (searchOption.MaxPrice.HasValue)
            {
                query = query.Where(x => x.Price <= searchOption.MaxPrice.Value);
            }

            var categories = searchOption.GetCategories().ToArray();

            if (categories.Any())
            {
                query = query.Where(x => x.Categories.Any(c => categories.Contains(c.Category.Slug)));
            }

            model.TotalProduct = query.Count();
            var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page;
            var offset         = (_pageSize * currentPageNum) - _pageSize;

            while (currentPageNum > 1 && offset >= model.TotalProduct)
            {
                currentPageNum--;
                offset = (_pageSize * currentPageNum) - _pageSize;
            }

            query = ApplySort(searchOption, query);

            var products = query
                           .Include(x => x.ThumbnailImage)
                           .Skip(offset)
                           .Take(_pageSize)
                           .Select(x => ProductThumbnail.FromProduct(x))
                           .ToList();

            foreach (var product in products)
            {
                product.Name                   = _contentLocalizationService.GetLocalizedProperty(nameof(Product), product.Id, nameof(product.Name), product.Name);
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            model.Products = products;
            model.CurrentSearchOption.PageSize = _pageSize;
            model.CurrentSearchOption.Page     = currentPageNum;

            return(View(model));
        }
        // TODO Number of items to config
        public async Task <IViewComponentResult> InvokeAsync(long?productId, int itemCount = 4)
        {
            List <ProductThumbnail> model = new List <ProductThumbnail>();

            if (productId != null)
            {
                var Prodcrossell = Crosssell(GetIP(), GetSession(), productId);
                foreach (var product in Prodcrossell.result)
                {
                    ProductThumbnail tm = new ProductThumbnail();
                    tm.Id           = long.Parse(product.identifier);
                    tm.Name         = product.description;
                    tm.ThumbnailUrl = product.imagelarge;
                    decimal pr = 0;
                    pr       = decimal.Parse(product.pricewithtax.Replace(".", ","));
                    tm.Price = pr;
                    tm.Slug  = tm.Name.Replace(" ", "-") + "-" + tm.Id;
                    Core.Models.Media pti = new ProductThumbnail().ThumbnailImage;
                    tm.ThumbnailUrl = _mediaService.GetThumbnailUrl(pti);
                    tm.ThumbnailUrl = _mediaService.GetURL(product.imagemedium);

                    //tm.CalculatedProductPrice(p);
                    //tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice((decimal.Parse(p.pricewithtax)));
                    tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice(tm);

                    model.Add(tm);
                    var entity = _entityRepository
                                 .Query()
                                 .Include(x => x.EntityType)
                                 .FirstOrDefault(x => x.Slug == tm.Slug);
                    if (entity == null)
                    {
                        Entity en = new Entity();

                        en.EntityId = (long)tm.Id;
                        en.Name     = tm.Name;
                        en.Slug     = tm.Slug;
                        var enType = _entityTypeRepository.Query().FirstOrDefault(x => x.Id == "Product");
                        en.EntityType = enType;

                        //en.EntityType = (EntityType)enType;
                        //en.EntityType = new EntityType("Product");
                        //en.EntityType.AreaName = "Catalog";
                        //en.EntityType.IsMenuable = false;
                        //en.EntityType.RoutingController = "Product";
                        //en.EntityType.RoutingAction = "ProductDetail";
                        _entityRepository.Add(en);
                        _entityRepository.SaveChanges();
                    }
                }
            }
            //productos relacionados



            return(View(this.GetViewPath(), model));

            // codigo origen
            //var user = await _workContext.GetCurrentUser();
            //IQueryable<Product> query = _productRepository.GetRecentlyViewedProduct(user.Id)
            //    .Include(x => x.ThumbnailImage);
            //if (productId.HasValue)
            //{
            //    query = query.Where(x => x.Id != productId.Value);
            //}

            //var model = query.Take(itemCount)
            //    .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            //foreach (var product in model)
            //{
            //    product.Name = _contentLocalizationService.GetLocalizedProperty(nameof(Product), product.Id, nameof(product.Name), product.Name);
            //    product.ThumbnailUrl = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
            //    product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            //}

            //return View(this.GetViewPath(), model);
        }
Esempio n. 19
0
        public IActionResult CategoryDetail(long id, SearchOption searchOption)
        {
            var category = _categoryRepository.Query().FirstOrDefault(x => x.Id == id);

            if (category == null)
            {
                return(Redirect("~/Error/FindNotFound"));
            }

            var model = new ProductsByCategory
            {
                CategoryId              = category.Id,
                ParentCategorId         = category.ParentId,
                CategoryName            = category.Name,
                CategorySlug            = category.Slug,
                CategoryMetaTitle       = category.MetaTitle,
                CategoryMetaKeywords    = category.MetaKeywords,
                CategoryMetaDescription = category.MetaDescription,
                CurrentSearchOption     = searchOption,
                FilterOption            = new FilterOption()
            };

            var query = _productRepository
                        .Query()
                        .Where(x => x.Categories.Any(c => c.CategoryId == category.Id) && x.IsPublished && x.IsVisibleIndividually);

            if (query.Count() == 0)
            {
                model.TotalProduct = 0;
                return(View(model));
            }

            AppendFilterOptionsToModel(model, query);

            if (searchOption.MinPrice.HasValue)
            {
                query = query.Where(x => x.Price >= searchOption.MinPrice.Value);
            }

            if (searchOption.MaxPrice.HasValue)
            {
                query = query.Where(x => x.Price <= searchOption.MaxPrice.Value);
            }

            var brands = searchOption.GetBrands();

            if (brands.Any())
            {
                var brandIs = _brandRepository.Query().Where(x => brands.Contains(x.Slug)).Select(x => x.Id).ToList();
                query = query.Where(x => x.BrandId.HasValue && brandIs.Contains(x.BrandId.Value));
            }

            model.TotalProduct = query.Count();
            var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page;
            var offset         = (_pageSize * currentPageNum) - _pageSize;

            while (currentPageNum > 1 && offset >= model.TotalProduct)
            {
                currentPageNum--;
                offset = (_pageSize * currentPageNum) - _pageSize;
            }

            query = query
                    .Include(x => x.Brand)
                    .Include(x => x.ThumbnailImage);

            query = AppySort(searchOption, query);

            var products = query
                           .Select(x => ProductThumbnail.FromProduct(x))
                           .Skip(offset)
                           .Take(_pageSize)
                           .ToList();

            foreach (var product in products)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            model.Products = products;
            model.CurrentSearchOption.PageSize = _pageSize;
            model.CurrentSearchOption.Page     = currentPageNum;

            return(View(model));
        }
Esempio n. 20
0
        public IActionResult Index(SearchOption searchOption)
        {
            if (string.IsNullOrWhiteSpace(searchOption.Query))
            {
                return(Redirect("~/"));
            }

            var brand = _brandRepository.Query().FirstOrDefault(x => x.Name == searchOption.Query && x.IsPublished);

            if (brand != null)
            {
                return(Redirect(string.Format("~/{0}", brand.Slug)));
            }

            var model = new SearchResult
            {
                CurrentSearchOption = searchOption,
                FilterOption        = new FilterOption()
            };

            var query = _productRepository.Query().Where(x => x.Name.Contains(searchOption.Query) && x.IsPublished && x.IsVisibleIndividually);

            if (query.Count() == 0)
            {
                model.TotalProduct = 0;
                return(View(model));
            }

            AppendFilterOptionsToModel(model, query);

            if (searchOption.MinPrice.HasValue)
            {
                query = query.Where(x => x.Price >= searchOption.MinPrice.Value);
            }

            if (searchOption.MaxPrice.HasValue)
            {
                query = query.Where(x => x.Price <= searchOption.MaxPrice.Value);
            }

            if (string.Compare(model.CurrentSearchOption.Category, "all", StringComparison.OrdinalIgnoreCase) != 0)
            {
                var categories = searchOption.GetCategories();
                if (categories.Any())
                {
                    var categoryIds = _categoryRepository.Query().Where(x => categories.Contains(x.Slug)).Select(x => x.Id).ToList();
                    query = query.Where(x => x.Categories.Any(c => categoryIds.Contains(c.CategoryId)));
                }
            }

            var brands = searchOption.GetBrands();

            if (brands.Any())
            {
                var brandIs = _brandRepository.Query().Where(x => brands.Contains(x.Slug)).Select(x => x.Id).ToList();
                query = query.Where(x => x.BrandId.HasValue && brandIs.Contains(x.BrandId.Value));
            }

            model.TotalProduct = query.Count();
            var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page;
            var offset         = (_pageSize * currentPageNum) - _pageSize;

            while (currentPageNum > 1 && offset >= model.TotalProduct)
            {
                currentPageNum--;
                offset = (_pageSize * currentPageNum) - _pageSize;
            }

            SaveSearchQuery(searchOption, model);

            query = query
                    .Include(x => x.ThumbnailImage);

            query = AppySort(searchOption, query);

            var products = query
                           .Select(x => ProductThumbnail.FromProduct(x))
                           .Skip(offset)
                           .Take(_pageSize)
                           .ToList();

            foreach (var product in products)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            model.Products = products;
            model.CurrentSearchOption.PageSize = _pageSize;
            model.CurrentSearchOption.Page     = currentPageNum;

            return(View(model));
        }
Esempio n. 21
0
        public IActionResult BrandDetail(long id, SearchOption searchOption)
        {
            var brand = _brandRepository.Query().FirstOrDefault(x => x.Id == id);

            var model = new ProductsByBrand
            {
                BrandId             = id,
                BrandName           = brand.Name,
                BrandSeoTitle       = brand.SeoTitle,
                CurrentSearchOption = searchOption,
                FilterOption        = new FilterOption()
            };

            var query = _productRepository.Query().Where(x => x.BrandId == id && x.IsPublished && x.IsVisibleIndividually);

            model.FilterOption.Price.MaxPrice = query.Select(x => x.Price).DefaultIfEmpty(0).Max();
            model.FilterOption.Price.MinPrice = query.Select(x => x.Price).DefaultIfEmpty(0).Min();

            if (searchOption.MinPrice.HasValue)
            {
                query = query.Where(x => x.Price >= searchOption.MinPrice.Value);
            }

            if (searchOption.MaxPrice.HasValue)
            {
                query = query.Where(x => x.Price <= searchOption.MaxPrice.Value);
            }

            AppendFilterOptionsToModel(model, query);
            var categories = searchOption.GetCategories();

            if (categories.Any())
            {
                var categoryIds = _categoryRepository.Query().Where(x => categories.Contains(x.SeoTitle)).Select(x => x.Id).ToList();
                query = query.Where(x => x.Categories.Any(c => categoryIds.Contains(c.CategoryId)));
            }

            model.TotalProduct = query.Count();
            var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page;
            var offset         = (_pageSize * currentPageNum) - _pageSize;

            while (currentPageNum > 1 && offset >= model.TotalProduct)
            {
                currentPageNum--;
                offset = (_pageSize * currentPageNum) - _pageSize;
            }

            query = query
                    .Include(x => x.ThumbnailImage);

            query = AppySort(searchOption, query);

            var products = query
                           .Select(x => ProductThumbnail.FromProduct(x))
                           .Skip(offset)
                           .Take(_pageSize)
                           .ToList();

            foreach (var product in products)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            model.Products = products;
            model.CurrentSearchOption.PageSize = _pageSize;
            model.CurrentSearchOption.Page     = currentPageNum;

            return(View(model));
        }
Esempio n. 22
0
        public IActionResult Index(SearchOption searchOption)
        {
            if (string.IsNullOrWhiteSpace(searchOption.Query))
            {
                return(Redirect("~/"));
            }
            var productos = RecuperaArtículosQuery(GetIP(), GetSession(), searchOption.Query);
            var model     = new SearchResult
            {
                CurrentSearchOption = searchOption,
                FilterOption        = new FilterOption()
            };

            if (productos.result.Count == 0 || productos is null)
            {
                model.TotalProduct = 0;
                return(View(model));
            }
            //AppendFilterOptionsToModel(model, query);

            model.TotalProduct = productos.result.Count();
            var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page;
            var offset         = (_pageSize * currentPageNum) - _pageSize;

            while (currentPageNum > 1 && offset >= model.TotalProduct)
            {
                currentPageNum--;
                offset = (_pageSize * currentPageNum) - _pageSize;
            }


            foreach (var p  in productos.result)
            {
                ProductThumbnail tm = new ProductThumbnail();
                tm.Id           = long.Parse(p.identifier);
                tm.Name         = p.description;
                tm.ThumbnailUrl = p.imagelarge;
                int r = 0;
                _ = int.TryParse(p.stocks, out r);
                tm.StockQuantity = r;
                decimal pr = 0;
                pr                = decimal.Parse(p.pricewithtax.Replace(".", ","));
                tm.Price          = pr;
                tm.ReviewsCount   = int.Parse(p.likeothers);
                tm.IsAllowToOrder = true;
                tm.Slug           = tm.Name.Replace(" ", "-") + "-" + tm.Id;
                Core.Models.Media pti = new ProductThumbnail().ThumbnailImage;
                tm.ThumbnailUrl = _mediaService.GetThumbnailUrl(pti);
                tm.ThumbnailUrl = _mediaService.GetURL(p.imagelarge);

                //tm.CalculatedProductPrice(p);
                //tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice((decimal.Parse(p.pricewithtax)));
                tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice(tm);
                model.Products.Add(tm);
                //añadimos a la tabla slug si no existe
                var entity = _entityRepository
                             .Query()
                             .Include(x => x.EntityType)
                             .FirstOrDefault(x => x.Slug == tm.Slug);
                if (entity == null)
                {
                    Entity en = new Entity();

                    en.EntityId = (long)tm.Id;
                    en.Name     = tm.Name;
                    en.Slug     = tm.Slug;
                    var enType = _entityTypeRepository.Query().FirstOrDefault(x => x.Id == "Product");
                    en.EntityType = enType;

                    //en.EntityType = (EntityType)enType;
                    //en.EntityType = new EntityType("Product");
                    //en.EntityType.AreaName = "Catalog";
                    //en.EntityType.IsMenuable = false;
                    //en.EntityType.RoutingController = "Product";
                    //en.EntityType.RoutingAction = "ProductDetail";
                    _entityRepository.Add(en);
                    _entityRepository.SaveChanges();
                }
            }


            model.CurrentSearchOption.PageSize = _pageSize;
            model.CurrentSearchOption.Page     = currentPageNum;

            return(View(model));



            //var brand = _brandRepository.Query().FirstOrDefault(x => x.Name == searchOption.Query && x.IsPublished);
            //if (brand != null)
            //{
            //    return Redirect(string.Format("~/{0}", brand.Slug));
            //}

            //var model = new SearchResult
            //{
            //    CurrentSearchOption = searchOption,
            //    FilterOption = new FilterOption()
            //};

            //var query = _productRepository.Query().Where(x => x.Name.Contains(searchOption.Query) && x.IsPublished && x.IsVisibleIndividually);
            //if (!query.Any())
            //{
            //    model.TotalProduct = 0;
            //    return View(model);
            //}



            //AppendFilterOptionsToModel(model, query);

            //if (searchOption.MinPrice.HasValue)
            //{
            //    query = query.Where(x => x.Price >= searchOption.MinPrice.Value);
            //}

            //if (searchOption.MaxPrice.HasValue)
            //{
            //    query = query.Where(x => x.Price <= searchOption.MaxPrice.Value);
            //}

            //if (string.Compare(model.CurrentSearchOption.Category, "all", StringComparison.OrdinalIgnoreCase) != 0)
            //{
            //    var categories = searchOption.GetCategories().ToArray();
            //    if (categories.Any())
            //    {
            //        query = query.Where(x => x.Categories.Any(c => categories.Contains(c.Category.Slug)));
            //    }
            //}

            //// EF Core bug, so we have to covert to Array
            //var brands = searchOption.GetBrands().ToArray();
            //if (brands.Any())
            //{
            //    query = query.Where(x => x.BrandId.HasValue && brands.Contains(x.Brand.Slug));
            //}

            //model.TotalProduct = query.Count();
            //var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page;
            //var offset = (_pageSize * currentPageNum) - _pageSize;
            //while (currentPageNum > 1 && offset >= model.TotalProduct)
            //{
            //    currentPageNum--;
            //    offset = (_pageSize * currentPageNum) - _pageSize;
            //}

            //SaveSearchQuery(searchOption, model);

            //query = AppySort(searchOption, query);

            //var products = query
            //    .Include(x => x.ThumbnailImage)
            //    .Skip(offset)
            //    .Take(_pageSize)
            //    .Select(x => ProductThumbnail.FromProduct(x))
            //    .ToList();

            //foreach (var product in products)
            //{
            //    product.Name = _contentLocalizationService.GetLocalizedProperty(nameof(Product), product.Id, nameof(product.Name), product.Name);
            //    product.ThumbnailUrl = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
            //    product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            //}

            //model.Products = products;
            //model.CurrentSearchOption.PageSize = _pageSize;
            //model.CurrentSearchOption.Page = currentPageNum;

            //return View(model);
        }
        public async Task <IActionResult> ProductDetail(long id)
        {
            var product = _productRepository.Query()
                          .Include(x => x.OptionValues)
                          .Include(x => x.Categories).ThenInclude(c => c.Category)
                          .Include(x => x.AttributeValues).ThenInclude(a => a.Attribute)
                          .Include(x => x.ProductLinks).ThenInclude(p => p.LinkedProduct).ThenInclude(m => m.ThumbnailImage)
                          .Include(x => x.ThumbnailImage)
                          .Include(x => x.Medias).ThenInclude(m => m.Media)
                          .FirstOrDefault(x => x.Id == id && x.IsPublished);

            if (product == null)
            {
                return(NotFound());
            }

            // Get brand
            var brand = _brandRepository.Query().FirstOrDefault(x => x.Id == product.BrandId);

            var model = new ProductDetail
            {
                Id   = product.Id,
                Name = product.Name,
                CalculatedProductPrice = _productPricingService.CalculateProductPrice(product),
                IsCallForPricing       = product.IsCallForPricing,
                IsAllowToOrder         = product.IsAllowToOrder,
                StockTrackingIsEnabled = product.StockTrackingIsEnabled,
                StockQuantity          = product.StockQuantity,
                ShortDescription       = product.ShortDescription,
                MetaTitle       = product.MetaTitle,
                MetaKeywords    = product.MetaKeywords,
                MetaDescription = product.MetaDescription,
                Description     = product.Description,
                Specification   = product.Specification,
                ReviewsCount    = product.ReviewsCount,
                RatingAverage   = product.RatingAverage,
                // add brand id
                BrandId    = product.BrandId,
                BrandName  = brand.Name,
                BrandSlug  = brand.Slug,
                Attributes = product.AttributeValues.Select(x => new ProductDetailAttribute {
                    Name = x.Attribute.Name, Value = x.Value
                }).ToList(),
                Categories = product.Categories.Select(x => new ProductDetailCategory {
                    Id = x.CategoryId, Name = x.Category.Name, Slug = x.Category.Slug
                }).ToList()
            };

            MapProductVariantToProductVm(product, model);
            MapRelatedProductToProductVm(product, model);
            MapProductOptionToProductVm(product, model);
            MapProductImagesToProductVm(product, model);

            await _mediator.Publish(new EntityViewed { EntityId = product.Id, EntityTypeId = "Product" });

            _productRepository.SaveChanges();

            var query    = _productRepository.Query().Where(x => x.BrandId == product.BrandId && x.IsPublished && x.IsVisibleIndividually).Include(x => x.ThumbnailImage);
            var products = query
                           .Select(x => ProductThumbnail.FromProduct(x))
                           .ToList();

            foreach (var product2 in products)
            {
                product2.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product2.ThumbnailImage);
                product2.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product2);
            }
            model.Products = products;
            return(View(model));
        }
Esempio n. 24
0
        private void MapRelatedProductToProductVm(Product product, ProductDetail model)
        {
            var Prodcrossell = Crosssell(GetIP(), GetSession(), product.Id);

            foreach (var productcr in Prodcrossell.result)
            {
                ViewModels.ProductThumbnail tm = new ProductThumbnail();
                tm.Id           = long.Parse(productcr.identifier);
                tm.Name         = productcr.description;
                tm.ThumbnailUrl = productcr.imagelarge;
                decimal pr = 0;
                pr       = decimal.Parse(productcr.pricewithtax.Replace(".", ","));
                tm.Price = pr;
                tm.Slug  = tm.Name.Replace(" ", "-") + "-" + tm.Id;
                Core.Models.Media pti = new ProductThumbnail().ThumbnailImage;
                tm.ThumbnailUrl = _mediaService.GetThumbnailUrl(pti);
                tm.ThumbnailUrl = _mediaService.GetURL(productcr.imagemedium);

                //tm.CalculatedProductPrice(p);
                //tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice((decimal.Parse(p.pricewithtax)));
                tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice(tm);
                model.CrossSellProducts.Add(tm);
                model.RelatedProducts.Add(tm);
                //añadimos a la tabla slug si no existe
                var entity = _entityRepository
                             .Query()
                             .Include(x => x.EntityType)
                             .FirstOrDefault(x => x.Slug == tm.Slug);
                if (entity == null)
                {
                    Entity en = new Entity();

                    en.EntityId = (long)tm.Id;
                    en.Name     = tm.Name;
                    en.Slug     = tm.Slug;
                    var enType = _entityTypeRepository.Query().FirstOrDefault(x => x.Id == "Product");
                    en.EntityType = enType;

                    //en.EntityType = (EntityType)enType;
                    //en.EntityType = new EntityType("Product");
                    //en.EntityType.AreaName = "Catalog";
                    //en.EntityType.IsMenuable = false;
                    //en.EntityType.RoutingController = "Product";
                    //en.EntityType.RoutingAction = "ProductDetail";
                    _entityRepository.Add(en);
                    _entityRepository.SaveChanges();
                }
            }
            //codigo origen
            //var publishedProductLinks = product.ProductLinks.Where(x => x.LinkedProduct.IsPublished && (x.LinkType == ProductLinkType.Related || x.LinkType == ProductLinkType.CrossSell));
            //foreach (var productLink in publishedProductLinks)
            //{
            //    var linkedProduct = productLink.LinkedProduct;
            //    var productThumbnail = ProductThumbnail.FromProduct(linkedProduct);
            //    productThumbnail.Name = _contentLocalizationService.GetLocalizedProperty(nameof(Product), productThumbnail.Id, nameof(product.Name), productThumbnail.Name);
            //    productThumbnail.ThumbnailUrl = _mediaService.GetThumbnailUrl(linkedProduct.ThumbnailImage);
            //    productThumbnail.CalculatedProductPrice = _productPricingService.CalculateProductPrice(linkedProduct);

            //    if (productLink.LinkType == ProductLinkType.Related)
            //    {
            //        model.RelatedProducts.Add(productThumbnail);
            //    }

            //    if (productLink.LinkType == ProductLinkType.CrossSell)
            //    {
            //        model.CrossSellProducts.Add(productThumbnail);
            //    }
            //}
        }
Esempio n. 25
0
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            //cambiamos aqui, tenemos que anaizar de donde vienen los widgets para poder diferenciar que cargar y donde.
            // se definene en la parte de admnistracion
            var productos = RecArticle(GetIP(), GetSession());
            //var model = new ProductWidgetComponentVm
            //{
            //    Id = widgetInstance.Id,
            //    WidgetName = widgetInstance.Name,
            //    Setting = JsonConvert.DeserializeObject<ProductWidgetSetting>(widgetInstance.Data)
            //};



            var model = new ProductWidgetComponentVm
            {
                Id         = widgetInstance.Id,
                WidgetName = widgetInstance.Name,
                Setting    = JsonConvert.DeserializeObject <ProductWidgetSetting>(widgetInstance.Data)
            };

            model.Products = new List <ProductThumbnail>();

            //CODIGO ORIGEN
            //var query = _productRepository.Query()
            //  .Where(x => x.IsPublished && x.IsVisibleIndividually);

            //if (model.Setting.CategoryId.HasValue && model.Setting.CategoryId.Value > 0)
            //{
            //    query = query.Where(x => x.Categories.Any(c => c.CategoryId == model.Setting.CategoryId.Value));
            //}

            //if (model.Setting.FeaturedOnly)
            //{
            //    query = query.Where(x => x.IsFeatured);
            //}

            //model.Products = query
            //  .Include(x => x.ThumbnailImage)
            //  .OrderByDescending(x => x.CreatedOn)
            //  .Take(model.Setting.NumberOfProducts)
            //  .Select(x => ProductThumbnail.FromProduct(x)).ToList();
            //foreach (var product in model.Products)
            //{
            //    product.Name = _contentLocalizationService.GetLocalizedProperty(nameof(Product), product.Id, nameof(product.Name), product.Name);
            //    product.ThumbnailUrl = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
            //    product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            //}

            //FIN CODIGO ORIGEN
            foreach (producto p in productos.Result.result)
            {
                ViewModels.ProductThumbnail tm = new ProductThumbnail();
                tm.Id           = long.Parse(p.identifier);
                tm.Name         = p.description;
                tm.ThumbnailUrl = p.imagelarge;
                int r = 0;
                _ = int.TryParse(p.stocks, out r);
                tm.StockQuantity = r;
                decimal pr = 0;
                pr                = decimal.Parse(p.pricewithtax.Replace(".", ","));
                tm.Price          = pr;
                tm.ReviewsCount   = int.Parse(p.likeothers);
                tm.IsAllowToOrder = true;
                tm.Slug           = tm.Name.Replace(" ", "-") + "-" + tm.Id;
                Core.Models.Media pti = new ProductThumbnail().ThumbnailImage;
                tm.ThumbnailUrl = _mediaService.GetThumbnailUrl(pti);
                tm.ThumbnailUrl = _mediaService.GetURL(p.imagelarge);

                //tm.CalculatedProductPrice(p);
                //tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice((decimal.Parse(p.pricewithtax)));
                tm.CalculatedProductPrice = _productPricingService.CalculateProductPrice(tm);
                model.Products.Add(tm);
                //añadimos a la tabla slug si no existe
                var entity = _entityRepository
                             .Query()
                             .Include(x => x.EntityType)
                             .FirstOrDefault(x => x.Slug == tm.Slug);
                if (entity == null)
                {
                    Entity en = new Entity();

                    en.EntityId = (long)tm.Id;
                    en.Name     = tm.Name;
                    en.Slug     = tm.Slug;
                    var enType = _entityTypeRepository.Query().FirstOrDefault(x => x.Id == "Product");
                    en.EntityType = enType;

                    //en.EntityType = (EntityType)enType;
                    //en.EntityType = new EntityType("Product");
                    //en.EntityType.AreaName = "Catalog";
                    //en.EntityType.IsMenuable = false;
                    //en.EntityType.RoutingController = "Product";
                    //en.EntityType.RoutingAction = "ProductDetail";
                    _entityRepository.Add(en);
                    _entityRepository.SaveChanges();
                }
            }

            return(View(this.GetViewPath(), model));
        }
Esempio n. 26
0
 public CalculatedProductPrice CalculateProductPrice(ProductThumbnail productThumbnail)
 {
     return(CalculateProductPrice(productThumbnail.Price, productThumbnail.OldPrice, productThumbnail.SpecialPrice, productThumbnail.SpecialPriceStart, productThumbnail.SpecialPriceEnd));
 }