How to get Customer ID on Vendor page?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 2 años
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
Hace 2 años
@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;
Hace 2 años
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?
Hace 2 años
how to make a link for sending Private Message to a Vendor?
Hace 2 años
@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
Hace 2 años
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! :)
Hace 1 año
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


hi, can you please give the same solution but for registered user? the idea is to show pm link for sending message to the user who created the product. i want to show "pm product creator" link in productbox.cshtml
Hace 1 año
Up top add to exisitng

@using Nop.Services.Customers
@using Nop.Services.Vendors

    int vendorCustomerId = 0;
    var iVendorService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IVendorService>();
    var iProductSerivce = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IProductService>();
    var iCustomerSerivce = Nop.Core.Infrastructure.EngineContext.Current.Resolve<ICustomerService>();

    var product = await iProductSerivce.GetProductByIdAsync(Model.Id);
    if (product != null)
    {
        var vendor = (await iVendorService.GetVendorByIdAsync(product.VendorId));
        if (vendor != null)
        {
            var customer = (await iCustomerSerivce.GetAllCustomersAsync()).Where(c => c.VendorId == vendor.Id).FirstOrDefault();
            if (customer != null)
                vendorCustomerId = customer.Id;
        }
    }
}

In markup

@if (vendorCustomerId != 0)
{
    <a href="/sendpm/@vendorCustomerId">send message to this user</a>
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.