Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Reconcile remaining ProductViewModelService rows: vendor-scope product search/bulk-edit, drop dead params (ARCH-001 Phase 1 Task 10)
KrzysztofPajakae5a6d1878e5
diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.csindex ec406619b..e2c3de924 100644--- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs@@ -1229,7 +1229,7 @@ public class ProductController : BaseAdminControllerif (psa == null)await _productViewModelService.InsertProductSpecificationAttributeModel(model, product);else- await _productViewModelService.UpdateProductSpecificationAttributeModel(product, psa, model);+ await _productViewModelService.UpdateProductSpecificationAttributeModel(psa, model);return new JsonResult("");}diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.csindex 2b8476098..0f34ad6ba 100644--- a/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseProductController.cs@@ -1672,10 +1672,8 @@ public abstract class BaseProductController(// HasAccess (strict): mirrors Store's CanAccessProduct check on this action. Vendor's original// ProductSpecAttrPopup(POST) had no check at all, letting any vendor add/edit specification// attributes on another vendor's product by posting its id - closed here the same way as the- // GET popup above. Vendor's original call also used a two-arg- // UpdateProductSpecificationAttributeModel(psa, model) overload that does not exist on the- // shared IProductViewModelService; the shared three-arg (product, psa, model) overload -- // already used by Admin/Store - is used here instead.+ // GET popup above. UpdateProductSpecificationAttributeModel's unused `product` parameter was+ // dropped in ARCH-001 Phase 1 Task 10 to match Vendor's original two-arg (psa, model) shape.if (!await scope.HasAccess(product))return Content(translationService.GetResource($"{scope.ResourceKeyPrefix}.Catalog.Products.Permissions"));@@ -1683,7 +1681,7 @@ public abstract class BaseProductController(if (psa == null)await productViewModelService.InsertProductSpecificationAttributeModel(model, product);else- await productViewModelService.UpdateProductSpecificationAttributeModel(product, psa, model);+ await productViewModelService.UpdateProductSpecificationAttributeModel(psa, model);return new JsonResult("");}diff --git a/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.cs b/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.csindex d62b6c442..639de8354 100644--- a/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.cs@@ -38,4 +38,12 @@ public interface IAdminDataScope<TEntity>/// flag, deliberately distinct from <see cref="DefaultStoreId"/> being null: DefaultStoreId is also/// null for Admin (global, no default store), where the selector should still show.</summary>bool ShowStoreSelector { get; }++ /// <summary>Vendor id to force onto product search/listing queries, overriding whatever a caller-+ /// supplied search model asks for. Null when the host has no vendor concept (Admin: global; Store:+ /// store-scoped, not vendor-scoped). Vendor: the current vendor's id - mirrors Vendor's original+ /// service always passing <c>vendorId: CurrentVendor.Id</c> into <c>IProductService.SearchProducts</c>/+ /// <c>PrepareProductList</c> regardless of any vendor filter a client-supplied model field might carry,+ /// so a vendor can never search or bulk-list another vendor's products.</summary>+ string? DefaultVendorId { get; }}diff --git a/src/Web/Grand.Web.AdminShared/Interfaces/IProductViewModelService.cs b/src/Web/Grand.Web.AdminShared/Interfaces/IProductViewModelService.csindex 5e6f29876..9d03ebb6d 100644--- a/src/Web/Grand.Web.AdminShared/Interfaces/IProductViewModelService.cs+++ b/src/Web/Grand.Web.AdminShared/Interfaces/IProductViewModelService.cs@@ -11,7 +11,7 @@ public interface IProductViewModelServiceTask PrepareProductReviewModel(ProductReviewModel model, ProductReview productReview, bool excludeProperties,bool formatReviewText);- Task OutOfStockNotifications(Product product, ProductModel model, int prevStockQuantity,+ Task OutOfStockNotifications(Product product, int prevStockQuantity,List<ProductWarehouseInventory> prevMultiWarehouseStock);Task OutOfStockNotifications(Product product, ProductAttributeCombination combination,@@ -161,7 +161,7 @@ public interface IProductViewModelServiceTask InsertProductSpecificationAttributeModel(ProductModel.AddProductSpecificationAttributeModel model,Product product);- Task UpdateProductSpecificationAttributeModel(Product product, ProductSpecificationAttribute psa,+ Task UpdateProductSpecificationAttributeModel(ProductSpecificationAttribute psa,ProductModel.AddProductSpecificationAttributeModel model);Task DeleteProductSpecificationAttribute(Product product, ProductSpecificationAttribute psa);diff --git a/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.csindex 9c1d85442..aa6b9647c 100644--- a/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs@@ -15,4 +15,6 @@ public class GlobalAdminDataScope<TEntity> : IAdminDataScope<TEntity>public string ResourceKeyPrefix => "Admin";public bool ShowStoreSelector => true;++ public string? DefaultVendorId => null;}diff --git a/src/Web/Grand.Web.AdminShared/Services/ProductViewModelService.cs b/src/Web/Grand.Web.AdminShared/Services/ProductViewModelService.csindex 490573d65..8706d44f1 100644--- a/src/Web/Grand.Web.AdminShared/Services/ProductViewModelService.cs+++ b/src/Web/Grand.Web.AdminShared/Services/ProductViewModelService.cs@@ -184,7 +184,7 @@ public class ProductViewModelService(model.AssociatedProductName = associatedProduct != null ? associatedProduct.Name : "";}- public virtual async Task OutOfStockNotifications(Product product, ProductModel model, int prevStockQuantity,+ public virtual async Task OutOfStockNotifications(Product product, int prevStockQuantity,List<ProductWarehouseInventory> prevMultiWarehouseStock){@@ -620,12 +620,16 @@ public class ProductViewModelService(var markedAsNewOnly = model.SearchPublishedId == 4;+ // vendorId: scope.DefaultVendorId (when set) overrides whatever the search model asks for - mirrors+ // Vendor's original PrepareProductsModel, which always passed vendorId: CurrentVendor.Id regardless+ // of any vendor filter on the model. Admin/Store have no DefaultVendorId, so this falls back to+ // model.SearchVendorId unchanged for them.var products = (await productService.SearchProducts(categoryIds: categoryIds,brandId: model.SearchBrandId,collectionId: model.SearchCollectionId,storeId: model.SearchStoreId,- vendorId: model.SearchVendorId,+ vendorId: scope.DefaultVendorId ?? model.SearchVendorId,warehouseId: model.SearchWarehouseId,productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null,keywords: model.SearchProductName,@@ -685,12 +689,14 @@ public class ProductViewModelService(break;}+ // vendorId: same override as PrepareProductsModel above - mirrors Vendor's original PrepareProducts,+ // which always passed vendorId: CurrentVendor.Id regardless of the search model.var products = (await productService.SearchProducts(categoryIds: categoryIds,brandId: model.SearchBrandId,collectionId: model.SearchCollectionId,storeId: model.SearchStoreId,- vendorId: model.SearchVendorId,+ vendorId: scope.DefaultVendorId ?? model.SearchVendorId,warehouseId: model.SearchWarehouseId,productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null,keywords: model.SearchProductName,@@ -780,7 +786,7 @@ public class ProductViewModelService(await UpdatePictureSeoNames(product);//out of stock notifications- await OutOfStockNotifications(product, model, prevStockQuantity, prevMultiWarehouseStock);+ await OutOfStockNotifications(product, prevStockQuantity, prevMultiWarehouseStock);//delete an old "download" file (if deleted or updated)if (!string.IsNullOrEmpty(prevDownloadId) && prevDownloadId != product.DownloadId)@@ -840,8 +846,12 @@ public class ProductViewModelService(public virtual async Task<(IList<ProductModel> products, int totalCount)> PrepareProductModel(ProductModel.AddProductModel model, int pageIndex, int pageSize){+ // vendorId: scope.DefaultVendorId (when set) overrides the search model - mirrors Vendor's original+ // PrepareProductModel(AddProductModel,...), which always passed vendorId: CurrentVendor.Id (and+ // storeId: string.Empty) regardless of the model, so the "add related/similar/bundle/etc. product"+ // popups can never surface another vendor's products.var products = await productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId,- model.SearchCollectionId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId,+ model.SearchCollectionId, model.SearchStoreId, scope.DefaultVendorId ?? model.SearchVendorId, model.SearchProductTypeId,model.SearchProductName, pageIndex, pageSize);return (products.Select(x => x.ToModel(dateTimeService)).ToList(), products.TotalCount);}@@ -1255,10 +1265,17 @@ public class ProductViewModelService(if (!string.IsNullOrEmpty(model.SearchCategoryId))searchCategoryIds.Add(model.SearchCategoryId);+ // vendorId: scope.DefaultVendorId forces the bulk-edit grid to the current vendor's own products.+ // Vendor's original PrepareBulkEditProductModel always passed vendorId: CurrentVendor.Id; this+ // shared version previously had no vendor filtering at all - a real gap, since BulkEditListModel+ // has no SearchVendorId field for a caller to (mis)supply in the first place, so there is nothing+ // to fall back to for Admin/Store, whose scope.DefaultVendorId is null and who intentionally see+ // every vendor's products in bulk-edit.var products = (await productService.SearchProducts(categoryIds: searchCategoryIds,brandId: model.SearchBrandId,collectionId: model.SearchCollectionId,storeId: model.SearchStoreId,+ vendorId: scope.DefaultVendorId ?? "",productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null,keywords: model.SearchProductName,pageIndex: pageIndex - 1,@@ -2476,8 +2493,8 @@ public class ProductViewModelService(product.ProductSpecificationAttributes.Add(psa);}- public virtual async Task UpdateProductSpecificationAttributeModel(Product product,- ProductSpecificationAttribute psa, ProductModel.AddProductSpecificationAttributeModel model)+ public virtual async Task UpdateProductSpecificationAttributeModel(ProductSpecificationAttribute psa,+ ProductModel.AddProductSpecificationAttributeModel model){psa = model.ToEntity(psa);await specificationAttributeService.UpdateProductSpecificationAttribute(psa, model.ProductId);@@ -2594,10 +2611,16 @@ public class ProductViewModelService(model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id });}- //vendors- model.AvailableVendors.Add(new SelectListItem { Text = translationService.GetResource("Admin.Common.All"), Value = " " });- foreach (var v in await vendorService.GetAllVendors(showHidden: true))- model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id });+ //vendors - only when the host isn't already forced onto a single vendor (scope.DefaultVendorId):+ //Vendor's original PrepareAddProductModel<T> never populated a vendor picker at all (matches the+ //ShowStoreSelector gate above for the same reason - there's nothing to pick, the search is always+ //forced to the current vendor).+ if (scope.DefaultVendorId is null)+ {+ model.AvailableVendors.Add(new SelectListItem { Text = translationService.GetResource("Admin.Common.All"), Value = " " });+ foreach (var v in await vendorService.GetAllVendors(showHidden: true))+ model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id });+ }//product typesmodel.AvailableProductTypes = enumTranslationService.ToSelectList(ProductType.SimpleProduct, false).ToList();diff --git a/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.csindex 632fbd17c..b1956ff0e 100644--- a/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.cs@@ -41,4 +41,6 @@ public class StoreAdminDataScope<TEntity>(IContextAccessor contextAccessor) : IApublic string ResourceKeyPrefix => "Admin";public bool ShowStoreSelector => true;++ public string? DefaultVendorId => null;}diff --git a/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.csindex c916139a4..250313a6f 100644--- a/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.cs@@ -25,4 +25,6 @@ public class VendorProductDataScope(IContextAccessor contextAccessor) : IAdminDapublic string ResourceKeyPrefix => "Vendor";public bool ShowStoreSelector => false;++ public string? DefaultVendorId => contextAccessor.WorkContext.CurrentVendor.Id;}diff --git a/src/Web/Grand.Web.Store/Controllers/ProductController.cs b/src/Web/Grand.Web.Store/Controllers/ProductController.csindex a53df58e1..571c94310 100644--- a/src/Web/Grand.Web.Store/Controllers/ProductController.cs+++ b/src/Web/Grand.Web.Store/Controllers/ProductController.cs@@ -1421,7 +1421,7 @@ public class ProductController : BaseStoreControllerif (psa == null)await _productViewModelService.InsertProductSpecificationAttributeModel(model, product);else- await _productViewModelService.UpdateProductSpecificationAttributeModel(product, psa, model);+ await _productViewModelService.UpdateProductSpecificationAttributeModel(psa, model);return new JsonResult("");}