How to associate a store to a Vendor In NopCommerce

hasan abiat
2 min readDec 29, 2023

--

If you want to limited vendor per each store in nopcommerce we should do this steps:

1-limited each customer to specific store because vendors are types of customers

Notice we couldn’t limited customers to stores, first step is add this avability this to nopcommerce

in nopcommerce we have StoreMapping table with EntityName,StoreId,EntityId fields

we set EntityName to ‘Customer’ and set storeId to id of store we want limited vendors to it and set EntityId to customerId of vendor

To Implement this we should change method create/Edit CustomerController in admin area and change _CreateOrUpdate.Info view inside Customer Folder.

below code we should use in _CreateOrUpdate.Info for limited vendor per store

 <div class="form-group row">
<div class="col-md-3">
<nop-label asp-for="SelectedStoreIds" />
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<nop-select asp-for="SelectedStoreIds" asp-items="Model.AvailableStores" asp-multiple="true" />
<script>
$(document).ready(function () {
var storesIdsInput = $('#@Html.IdFor(model => model.SelectedStoreIds)').data("kendoMultiSelect");
storesIdsInput.setOptions({
autoClose: false,
filter: "contains"
});

@if (Model.AvailableStores.Count == 0)
{
<text>
storesIdsInput.setOptions({
enable: false,
placeholder: 'No stores available'
});
storesIdsInput._placeholder();
storesIdsInput._enable();
</text>
}
});
</script>
</div>
<div class="col-md-8">
@await Component.InvokeAsync(typeof(MultistoreDisabledWarningViewComponent))
</div>
</div>
</div>
</div> <div class="form-group row">
<div class="col-md-3">
<nop-label asp-for="SelectedStoreIds" />
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<nop-select asp-for="SelectedStoreIds" asp-items="Model.AvailableStores" asp-multiple="true" />
<script>
$(document).ready(function () {
var storesIdsInput = $('#@Html.IdFor(model => model.SelectedStoreIds)').data("kendoMultiSelect");
storesIdsInput.setOptions({
autoClose: false,
filter: "contains"
});

@if (Model.AvailableStores.Count == 0)
{
<text>
storesIdsInput.setOptions({
enable: false,
placeholder: 'No stores available'
});
storesIdsInput._placeholder();
storesIdsInput._enable();
</text>
}
});
</script>
</div>
<div class="col-md-8">
@await Component.InvokeAsync(typeof(MultistoreDisabledWarningViewComponent))
</div>
</div>
</div>
</div>

It’s be look like this picture:

--

--