public IViewComponentResult Invoke(string widgetZone, object additionalData)
        {
            var wZone = widgetZone;

            if (wZone == "productdetails_top" && additionalData != null)
            {
                var product = _productService.GetProductById((int)additionalData);
                var model   = new PublicInfoModel()
                {
                    ProductId = product.Id
                };
                var productMessageRecords = _productMessageRecordService.GetByProductId(product.Id);
                if (productMessageRecords.Count == 0)
                {
                    return(Content(""));
                }

                var firstproductMessageRecord = productMessageRecords.First();

                PublicInfoModel.EmbedMessageModel embedMessageModel = new PublicInfoModel.EmbedMessageModel();

                embedMessageModel.Id = firstproductMessageRecord.Id;
                embedMessageModel.MessageHtmlCode = firstproductMessageRecord.MessageHtmlCode;

                model.EmbedMessageRecordModels.Add(embedMessageModel);


                return(View("~/Plugins/Widgets.MyProductMessage/Views/ProductMessage/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 = _productMessageRecordService.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));
        }