/// <summary> /// Prepare related product search model /// </summary> /// <param name="searchModel">Related product search model</param> /// <param name="product">Product</param> /// <returns>Related product search model</returns> protected virtual RelatedProductSearchModel PrepareRelatedProductSearchModel(RelatedProductSearchModel 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); }
public virtual IActionResult RelatedProductList(RelatedProductSearchModel 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.PrepareRelatedProductListModel(searchModel, product); return(Json(model)); }
/// <summary> /// Prepare paged related product list model /// </summary> /// <param name="searchModel">Related product search model</param> /// <param name="product">Product</param> /// <returns>Related product list model</returns> public virtual RelatedProductListModel PrepareRelatedProductListModel(RelatedProductSearchModel searchModel, Product product) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (product == null) { throw new ArgumentNullException(nameof(product)); } //get related products var relatedProducts = _productService.GetRelatedProductsByProductId1(productId1: product.Id, showHidden: true); //prepare grid model var model = new RelatedProductListModel { Data = relatedProducts.PaginationByRequestModel(searchModel).Select(relatedProduct => { //fill in model values from the entity var relatedProductModel = new RelatedProductModel { Id = relatedProduct.Id, ProductId2 = relatedProduct.ProductId2, DisplayOrder = relatedProduct.DisplayOrder }; //fill in additional values (not existing in the entity) relatedProductModel.Product2Name = _productService.GetProductById(relatedProduct.ProductId2)?.Name; return(relatedProductModel); }), Total = relatedProducts.Count }; return(model); }