Skip to content

Fix store filter override in admin "add product" popup#657

Merged
KrzysztofPajak merged 3 commits intodevelopfrom
copilot/fix-store-filter-popup
Mar 19, 2026
Merged

Fix store filter override in admin "add product" popup#657
KrzysztofPajak merged 3 commits intodevelopfrom
copilot/fix-store-filter-popup

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

BlogViewModelService.PrepareProductModel unconditionally overwrote model.SearchStoreId with StaffStoreId, causing the store dropdown filter in the blog post "add product" popup to have no effect.

Change

Removed the StaffStoreId-based store context override entirely, as the Admin project does not need store context filtering:

// Before
model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;

// After
// (line removed — Admin does not filter by store context)
  • The user's selected store filter is now passed through directly to the product list query without any server-side override
Original prompt

This section details on the original issue you should resolve

<issue_title>Store filtering in "add product" popup not working</issue_title>
<issue_description>Hi GrandNode team,

In admin, on branch 2.3.x, when adding products to blog post, or adding any type of linked products to a product, the store filter in the popup didn't seems to work, no product were filtered.

Looking at the code of the called controller methods, it showed a direct override of the store id filter value with the staff store id:

//limit for store manager
model.SearchStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;

This issue seems to be présent in the following files:

  • Grand.Web.Admin/Services/ProductViewModelService.cs, method PrepareProducts, line 654
  • Grand.Web.Admin/Services/ProductViewModelService.cs, method PrepareProductModel, line 853
  • Grand.Web.Admin/Services/BlogViewModelService.cs, method PrepareProductModel, line 209

Adding conditionnal code to check if the user is a staff member, like in other methods in ProductViewModelService.cs seems to have solved this issue:

//limit for store manager
if (!string.IsNullOrEmpty(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
    model.SearchStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;

Do you see a better solution in order to fix this issue ?

Kind regards</issue_description>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: KrzysztofPajak <16772986+KrzysztofPajak@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix store filtering in add product popup Fix store filter override in admin "add product" popup for non-staff admins Mar 19, 2026
Copilot AI requested a review from KrzysztofPajak March 19, 2026 10:04
@KrzysztofPajak
Copy link
Member

@copilot project Admin do not need to be filtered by store context

…eProductModel

Co-authored-by: KrzysztofPajak <16772986+KrzysztofPajak@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot project Admin do not need to be filtered by store context

Removed the StaffStoreId override entirely from BlogViewModelService.PrepareProductModel in commit 1ed2c6d. The method now passes model.SearchStoreId directly to the product list query without any server-side store context override.

Copilot AI changed the title Fix store filter override in admin "add product" popup for non-staff admins Fix store filter override in admin "add product" popup Mar 19, 2026
@sonarqubecloud
Copy link

@KrzysztofPajak
Copy link
Member

@copilot Check is Grand.Web.Store has limited by StoreContext

Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot Check is Grand.Web.Store has limited by StoreContext

Yes, Grand.Web.Store is still correctly limited by store context. The store filtering is applied at the controller level in Grand.Web.Store/Controllers/BlogController.cs (line 368), which unconditionally sets model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId before calling the shared service method. Removing the same override from the shared BlogViewModelService does not affect the Store project — it continues to enforce its store restriction through the controller.

@KrzysztofPajak KrzysztofPajak marked this pull request as ready for review March 19, 2026 17:47
Copilot AI review requested due to automatic review settings March 19, 2026 17:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the store filter in the Admin “add product” popup for blog posts by preventing the selected SearchStoreId from being overwritten before querying products.

Changes:

  • Removed the unconditional StaffStoreId assignment to model.SearchStoreId in BlogViewModelService.PrepareProductModel.
  • Ensures the selected store filter value is passed through to the product search query.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -209,7 +209,6 @@ public virtual async Task<BlogPost> UpdateBlogPostModel(BlogPostModel model, Blo
public virtual async Task<(IList<ProductModel> products, int totalCount)> PrepareProductModel(
BlogProductModel.AddProductModel model, int pageIndex, int pageSize)
{
Comment on lines 212 to 213
var products = await _productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId,
model.SearchCollectionId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId,
Comment on lines 209 to 213
public virtual async Task<(IList<ProductModel> products, int totalCount)> PrepareProductModel(
BlogProductModel.AddProductModel model, int pageIndex, int pageSize)
{
model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var products = await _productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId,
model.SearchCollectionId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId,
@KrzysztofPajak
Copy link
Member

@copilot please also check
Grand.Web.Admin/Services/ProductViewModelService.cs, method PrepareProducts, line 654
Grand.Web.Admin/Services/ProductViewModelService.cs, method PrepareProductModel, line 853

Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot please also check
Grand.Web.Admin/Services/ProductViewModelService.cs, method PrepareProducts, line 654
Grand.Web.Admin/Services/ProductViewModelService.cs, method PrepareProductModel, lin...

Checked both locations — they are already correct in Grand.Web.AdminShared/Services/ProductViewModelService.cs (the shared service used by the Admin project):

  • PrepareProducts (line 642): passes model.SearchStoreId directly to productService.SearchProducts with no override
  • PrepareProductModel(AddProductModel) (line 820): passes model.SearchStoreId directly to productService.PrepareProductList with no override

Neither method has an unconditional StaffStoreId assignment. The SearchStoreId value comes straight from the user's selection. No changes needed there.

@KrzysztofPajak KrzysztofPajak merged commit a76bbfb into develop Mar 19, 2026
13 checks passed
@KrzysztofPajak KrzysztofPajak deleted the copilot/fix-store-filter-popup branch March 19, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Store filtering in "add product" popup not working

3 participants