How to get Customer ID on Vendor page?

2 months ago
i want to display customer id on vendor page (here \Views\Catalog\Vendor.cshtml)

i want to make link for sending private message to the customer (vendor)

like this:
<a href="/sendpm/@CustomerId">send message to this user</a>


i use latest nopcommerce 4.40

please help
2 months ago
@model VendorModel
@using Nop.Core.Domain.Seo
@using Nop.Core
@inject Nop.Core.IWebHelper webHelper
@inject SeoSettings seoSettings

@{
    Layout = "_ColumnsTwo";
    var iWorkContext = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>();
    int customerId = (await iWorkContext.GetCurrentCustomerAsync()).Id;
2 months ago
Yidna wrote:
@model VendorModel
@using Nop.Core.Domain.Seo
@using Nop.Core
@inject Nop.Core.IWebHelper webHelper
@inject SeoSettings seoSettings

@{
    Layout = "_ColumnsTwo";
    var iWorkContext = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>();
    int customerId = (await iWorkContext.GetCurrentCustomerAsync()).Id;


thank you for your help. it works, but it gets current customer id (my own id). i need to make link to send private message to customer. can you tell me how to get customer id to create link for PM?
2 months ago
how to make a link for sending Private Message to a Vendor?
2 months ago
@model VendorModel
@using Nop.Core.Domain.Seo
@inject Nop.Core.IWebHelper webHelper
@inject SeoSettings seoSettings
@using Nop.Services.Customers
@using Nop.Services.Vendors
@{
    Layout = "_ColumnsTwo";

    int vendorCustomerId = 0;
    var iVendorService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IVendorService>();
    var iCustomerSerivce = Nop.Core.Infrastructure.EngineContext.Current.Resolve<ICustomerService>();
    var vendor = (await iVendorService.GetAllVendorsAsync()).Where(v => v.Name == Model.Name).FirstOrDefault();
    if (vendor != null)
    {
        var customer = (await iCustomerSerivce.GetAllCustomersAsync()).Where(c => c.VendorId == vendor.Id).FirstOrDefault();
        if (customer != null)
            vendorCustomerId = customer.Id;
    }

Later you can do
@if (vendorCustomerId != 0)
{
    <a href="/sendpm/@vendorCustomerId">send message to this user</a>
}

Note: If you have a them installed then you may need to edit the theme version of Vendor.cshtml
For example: Nop.Web\Themes\Motion\Views\Catalog\Vendor.cshtml
2 months ago
Yidna wrote:
@model VendorModel
@using Nop.Core.Domain.Seo
@inject Nop.Core.IWebHelper webHelper
@inject SeoSettings seoSettings
@using Nop.Services.Customers
@using Nop.Services.Vendors
@{
    Layout = "_ColumnsTwo";

    int vendorCustomerId = 0;
    var iVendorService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IVendorService>();
    var iCustomerSerivce = Nop.Core.Infrastructure.EngineContext.Current.Resolve<ICustomerService>();
    var vendor = (await iVendorService.GetAllVendorsAsync()).Where(v => v.Name == Model.Name).FirstOrDefault();
    if (vendor != null)
    {
        var customer = (await iCustomerSerivce.GetAllCustomersAsync()).Where(c => c.VendorId == vendor.Id).FirstOrDefault();
        if (customer != null)
            vendorCustomerId = customer.Id;
    }

Later you can do
@if (vendorCustomerId != 0)
{
    <a href="/sendpm/@vendorCustomerId">send message to this user</a>
}

Note: If you have a them installed then you may need to edit the theme version of Vendor.cshtml
For example: Nop.Web\Themes\Motion\Views\Catalog\Vendor.cshtml


it works! thank you so much! :)