Add Customer Name and PM link on Product Details page
http://screencast.com/t/0r7HXJJifQpKPrereq:
Forums and Private Message must be enabled
CODES------------------------------------------------------
CustomerService.cs~\nopCommerce\Libraries\Nop.Services\Customers\CustomerService.cs
add this method
public virtual Customer GetCustomerByVendorId(int id)
{
var query = from c in _customerRepository.Table
orderby c.Id
where c.VendorId == id
select c;
var customer = query.FirstOrDefault();
return customer;
}
------------------------------------------------------
ICustomerService.cs~\nopCommerce\Libraries\Nop.Services\Customers\ICustomerService.cs
add this method signature
Customer GetCustomerByVendorId(int id);
------------------------------------------------------
ProductDetailsModel.cs~\nopCommerce\Presentation\Nop.Web\Models\Catalog\ProductDetailsModel.cs
add this properties
public string VendorName { get; set; }
public int VendorId { get; set; }
public string CustomerName { get; set; }
public int CustomerID { get; set; }
------------------------------------------------------
CatalogController.cs~\nopCommerce\Presentation\Nop.Web\Controllers\CatalogController.cs
add this on Fields
private readonly IVendorService _vendorService;
private readonly ICustomerService _customerService;
and on the Constructor parameter, add this params
IVendorService venderService,
ICustomerService customerService,
and implement them inside the constructor
this._vendorService = venderService;
this._customerService = customerService;
go to
public ActionResult Product(int productId)
and after this line of code
//prepare the model
var model = PrepareProductDetailsPageModel(product, false);
add these codes
var vendor = _vendorService.GetVendorById(product.VendorId);
model.VendorId = vendor.Id;
model.VendorName = vendor.Name;
var customer = _customerService.GetCustomerByVendorId(product.VendorId);
model.CustomerID = customer.Id;
model.CustomerName = customer.GetFullName();
------------------------------------------------------
ProductTemplate.Simple.cshtml~\nopCommerce\Presentation\Nop.Web\Views\Catalog\ProductTemplate.Simple.cshtml
add these html anywhere you want
<div>
<span class="label">Seller</span>
<span class="value">@Model.CustomerName</span>
<br />
<div class="send-pm-box"><a class="pm-link-button" href="/sendpm/@Model.CustomerID">
PM
</a></div>
<br /><br />
</div>
------------------------------------------------------
PROBLEM
I can send PM to my self. Can you think of any work around?