Ejemplo n.º 1
0
        public IViewComponentResult Invoke(string widgetZone, ProductDetailsModel additionalData)
        {
            var wZone = widgetZone;

            if (wZone == "productdetails_after_pictures" && additionalData != null)
            {
                var product = _productService.GetProductById(additionalData.Id);
                var model   = new PublicInfoModel()
                {
                    ProductId = product.Id
                };
                var productVideoRecords = _productVideoRecordService.GetByProductId(product.Id);
                if (productVideoRecords.Count == 0)
                {
                    return(Content(""));
                }
                foreach (var embedVideoModel in productVideoRecords.Select(productVideoRecord => new PublicInfoModel.EmbedVideoModel()
                {
                    Id = productVideoRecord.Id,
                    VideoThumbUrl = _pictureService.GetPictureUrl(productVideoRecord.VideoThumbId, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage),
                    EmbedVideoHtmlCode = productVideoRecord.EmbedVideoHtmlCode
                }))
                {
                    model.EmbedVideoRecordModels.Add(embedVideoModel);
                }

                return(View("~/Plugins/Widgets.BsProductVideo/Views/ProductVideo/PublicInfo.cshtml", model));
            }

            return(Content(""));
        }
Ejemplo n.º 2
0
        public ActionResult ProductList(DataSourceRequest command, ProductListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(Content("Access denied"));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null)
            {
                model.SearchVendorId = _workContext.CurrentVendor.Id;
            }

            var categoryIds = new List <int> {
                model.SearchCategoryId
            };

            //include subcategories
            if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0)
            {
                categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId));
            }

            //0 - all (according to "ShowHidden" parameter)
            //1 - published only
            //2 - unpublished only
            bool?overridePublished = null;

            if (model.SearchPublishedId == 1)
            {
                overridePublished = true;
            }
            else if (model.SearchPublishedId == 2)
            {
                overridePublished = false;
            }

            var products = _productService.SearchProducts(
                categoryIds: categoryIds,
                manufacturerId: model.SearchManufacturerId,
                storeId: model.SearchStoreId,
                vendorId: model.SearchVendorId,
                warehouseId: model.SearchWarehouseId,
                productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null,
                keywords: model.SearchProductName,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize,
                showHidden: true,
                overridePublished: overridePublished
                );
            var gridModel = new DataSourceResult();

            gridModel.Data = products.Select(x =>
            {
                var productModel = x.ToModel();
                //little hack here:
                //ensure that product full descriptions are not returned
                //otherwise, we can get the following error if products have too long descriptions:
                //"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. "
                //also it improves performance
                productModel.FullDescription = "";

                productModel.DownloadExpirationDays = _productVideoRecordService.GetByProductId(x.Id).Count();

                //picture
                var defaultProductPicture        = _pictureService.GetPicturesByProductId(x.Id, 1).FirstOrDefault();
                productModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true);
                //product type
                productModel.ProductTypeName = x.ProductType.GetLocalizedEnum(_localizationService, _workContext);
                //friendly stock qantity
                //if a simple product AND "manage inventory" is "Track inventory", then display
                if (x.ProductType == ProductType.SimpleProduct && x.ManageInventoryMethod == ManageInventoryMethod.ManageStock)
                {
                    productModel.StockQuantityStr = x.GetTotalStockQuantity().ToString();
                }

                return(productModel);
            });
            gridModel.Total = products.TotalCount;

            return(Json(gridModel));
        }
        public ActionResult ProductList(DataSourceRequest command, ProductSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedKendoGridJson());
            }



            //get parameters to filter comments
            var overridePublished = searchModel.SearchPublishedId == 0 ? null : (bool?)(searchModel.SearchPublishedId == 1);

            if (_workContext.CurrentVendor != null)
            {
                searchModel.SearchVendorId = _workContext.CurrentVendor.Id;
            }
            var categoryIds = new List <int> {
                searchModel.SearchCategoryId
            };

            if (searchModel.SearchIncludeSubCategories && searchModel.SearchCategoryId > 0)
            {
                var childCategoryIds = _categoryService.GetChildCategoryIds(parentCategoryId: searchModel.SearchCategoryId, showHidden: true);
                categoryIds.AddRange(childCategoryIds);
            }

            //get products
            var products = _productService.SearchProducts(showHidden: true,
                                                          categoryIds: categoryIds,
                                                          manufacturerId: searchModel.SearchManufacturerId,
                                                          storeId: searchModel.SearchStoreId,
                                                          vendorId: searchModel.SearchVendorId,
                                                          warehouseId: searchModel.SearchWarehouseId,
                                                          productType: searchModel.SearchProductTypeId > 0 ? (ProductType?)searchModel.SearchProductTypeId : null,
                                                          keywords: searchModel.SearchProductName,
                                                          pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize,
                                                          overridePublished: overridePublished);

            //prepare list model
            var model = new ProductListModel
            {
                Data = products.Select(product =>
                {
                    //fill in model values from the entity
                    var productModel = product.ToModel <ProductModel>();

                    //little performance optimization: ensure that "FullDescription" is not returned
                    productModel.FullDescription        = string.Empty;
                    productModel.DownloadExpirationDays = _productVideoRecordService.GetByProductId(product.Id).Count();
                    //fill in additional values (not existing in the entity)
                    var defaultProductPicture        = _pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault();
                    productModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75);
                    productModel.ProductTypeName     = _localizationService.GetLocalizedEnum(product.ProductType);
                    if (product.ProductType == ProductType.SimpleProduct && product.ManageInventoryMethod == ManageInventoryMethod.ManageStock)
                    {
                        productModel.StockQuantityStr = _productService.GetTotalStockQuantity(product).ToString();
                    }

                    return(productModel);
                }),
                Total = products.TotalCount
            };


            return(Json(model));
        }