/// <summary> /// Prepare paged associated product list model /// </summary> /// <param name="searchModel">Associated product search model</param> /// <param name="product">Product</param> /// <returns>Associated product list model</returns> public virtual AssociatedProductListModel PrepareAssociatedProductListModel(AssociatedProductSearchModel searchModel, Product product) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (product == null) { throw new ArgumentNullException(nameof(product)); } //get associated products var associatedProducts = _productService.GetAssociatedProducts(showHidden: true, parentGroupedProductId: product.Id, vendorId: _workContext.CurrentVendor?.Id ?? 0); //prepare grid model var model = new AssociatedProductListModel { //fill in model values from the entity Data = associatedProducts.PaginationByRequestModel(searchModel).Select(associatedProduct => new AssociatedProductModel { Id = associatedProduct.Id, ProductName = associatedProduct.Name, DisplayOrder = associatedProduct.DisplayOrder }), Total = associatedProducts.Count }; return(model); }
public virtual IActionResult AssociatedProductList(AssociatedProductSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { return(AccessDeniedKendoGridJson()); } //try to get a product with the specified id var product = _productService.GetProductById(searchModel.ProductId) ?? throw new ArgumentException("No product found with the specified id"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id) { return(Content("This is not your product")); } //prepare model var model = _productModelFactory.PrepareAssociatedProductListModel(searchModel, product); return(Json(model)); }
/// <summary> /// Prepare associated product search model /// </summary> /// <param name="searchModel">Associated product search model</param> /// <param name="product">Product</param> /// <returns>Associated product search model</returns> protected virtual AssociatedProductSearchModel PrepareAssociatedProductSearchModel(AssociatedProductSearchModel searchModel, Product product) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (product == null) { throw new ArgumentNullException(nameof(product)); } searchModel.ProductId = product.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }