My code collection

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
This thread will probably my little stuff regarding the mods I'm trying to make in nopCommerce.

I hope the admins don't mind that I share my codes?

You can implement the codes but I warn you that I do not take responsibility of your mistakes that may cause to bug down your web site.

Ok so here's my little list.
1. Add PM and Username on Product Details page.
https://www.nopcommerce.com/boards/t/25350/my-code-collection.aspx#103501

2. Make new registered Customers act as a Vendor automatically after registration
https://www.nopcommerce.com/boards/t/25350/my-code-collection.aspx#103502

I hope it could be added as one of the features in nopCommerce soon.
10 years ago
Add Customer Name and PM link on Product Details page
http://screencast.com/t/0r7HXJJifQpK

Prereq:
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?
10 years ago
Set Vendors role on any new customer so the can post their products

This will make the new registered customer as a Vendor.

the result would be like this (video)
http://screencast.com/t/wJVzhmz28m

CODES
-------------------------------------------------------

ICustomerRegistrationService.cs
~\nopCommerce\Libraries\Nop.Services\Customers\ICustomerRegistrationService.cs

update the method signature from
CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request);

to
CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request, string fullname = "");


-------------------------------------------------------

CustomerRegistrationService.cs
~\nopCommerce\Libraries\Nop.Services\Customers\CustomerRegistrationService.cs

update this method from
public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request)

to
public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request, string fullname = "")


look for this code
//add to 'Registered' role
var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered);
if (registeredRole == null) throw new NopException("'Registered' role could not be loaded");
request.Customer.CustomerRoles.Add(registeredRole);


after that code, add this
// make registered user as a vendor too.
{
  var vendor = new Vendor()
  {
    Name = fullname,
    Email = request.Customer.Email,
    Active = true
  };
  this._vendorService.InsertVendor(vendor);
  request.Customer.VendorId = vendor.Id;

  registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Vendors);
  if (registeredRole == null) throw new NopException("'Vendors' role could not be loaded");
  request.Customer.CustomerRoles.Add(registeredRole);
}


-------------------------------------------------------

CustomerController.cs
~\nopCommerce\Presentation\Nop.Web\Controllers\CustomerController.cs

look for this line
var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest);

and update it to
var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest, model.FirstName + " " + model.LastName);
10 years ago
updating the code so I can show products from a specific vendor..
9 years ago
jaysonragasa wrote:
updating the code so I can show products from a specific vendor..


If you are using a specific vendor account for the users don't you think users will be able to edit the product of each other?
9 years ago
jaysonragasa wrote:
Set Vendors role on any new customer so the can post their products

This will make the new registered customer as a Vendor.

the result would be like this (video)
http://screencast.com/t/wJVzhmz28m

CODES
-------------------------------------------------------

ICustomerRegistrationService.cs
~\nopCommerce\Libraries\Nop.Services\Customers\ICustomerRegistrationService.cs

update the method signature from
CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request);

to
CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request, string fullname = "");


-------------------------------------------------------

CustomerRegistrationService.cs
~\nopCommerce\Libraries\Nop.Services\Customers\CustomerRegistrationService.cs

update this method from
public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request)

to
public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request, string fullname = "")


look for this code
//add to 'Registered' role
var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered);
if (registeredRole == null) throw new NopException("'Registered' role could not be loaded");
request.Customer.CustomerRoles.Add(registeredRole);


after that code, add this
// make registered user as a vendor too.
{
  var vendor = new Vendor()
  {
    Name = fullname,
    Email = request.Customer.Email,
    Active = true
  };
  this._vendorService.InsertVendor(vendor);
  request.Customer.VendorId = vendor.Id;

  registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Vendors);
  if (registeredRole == null) throw new NopException("'Vendors' role could not be loaded");
  request.Customer.CustomerRoles.Add(registeredRole);
}


-------------------------------------------------------

CustomerController.cs
~\nopCommerce\Presentation\Nop.Web\Controllers\CustomerController.cs

look for this line
var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest);

and update it to
var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest, model.FirstName + " " + model.LastName);


Good job. But I think you do not need to change the signature of the method specially when you are not assigning any value to the 'full name' variable.
8 years ago
hello sir,

i want to create two radio button in register page that is customer and vendor.if i select customer than it only register not go to admin side but if i select vendor than i want to go admin side.i use this above code but all customer became vendor but i dnt want all customer to be vendor.

please suggest me answer.

thank you
7 years ago
jaysonragasa wrote:
Set Vendors role on any new customer so the can post their products

This will make the new registered customer as a Vendor.

the result would be like this (video)
http://screencast.com/t/wJVzhmz28m

CODES
-------------------------------------------------------

ICustomerRegistrationService.cs
~\nopCommerce\Libraries\Nop.Services\Customers\ICustomerRegistrationService.cs

update the method signature from
CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request);

to
CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request, string fullname = "");


-------------------------------------------------------

CustomerRegistrationService.cs
~\nopCommerce\Libraries\Nop.Services\Customers\CustomerRegistrationService.cs

update this method from
public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request)

to
public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request, string fullname = "")


look for this code
//add to 'Registered' role
var registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered);
if (registeredRole == null) throw new NopException("'Registered' role could not be loaded");
request.Customer.CustomerRoles.Add(registeredRole);


after that code, add this
// make registered user as a vendor too.
{
  var vendor = new Vendor()
  {
    Name = fullname,
    Email = request.Customer.Email,
    Active = true
  };
  this._vendorService.InsertVendor(vendor);
  request.Customer.VendorId = vendor.Id;

  registeredRole = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Vendors);
  if (registeredRole == null) throw new NopException("'Vendors' role could not be loaded");
  request.Customer.CustomerRoles.Add(registeredRole);
}


-------------------------------------------------------

CustomerController.cs
~\nopCommerce\Presentation\Nop.Web\Controllers\CustomerController.cs

look for this line
var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest);

and update it to
var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest, model.FirstName + " " + model.LastName);




Make new registered Customers act as a Vendor automatically after registration is not work on 3.8 version
any ideas.
7 years ago
PM to vendor is not working on 3.80.

Those lines are in Product Controller, not in CatalogController.cs anymore.

Any suggestions to do it?
7 years ago
dianoche wrote:
PM to vendor is not working on 3.80.

Those lines are in Product Controller, not in CatalogController.cs anymore.

Any suggestions to do it?


Solved. Just make changes on Product Controller. Vendor is already there. All you need to do is add customer part.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.