Not able to insert the customer SeName in UrlRecord Table in nopcommerce

132 views Asked by At

Currently i am stucked in one point that when the customer completes its registration process what i want to do is Create a SeName from customers email address and store it in UrlRecord Table so that i can enable navigation to customers profile page. Below is the code that i had tried till now.

string CustomerSeName = "";
var CustomerModel=_customerService.GetCustomerById(_workContext.CurrentCustomer.Id);
if (CustomerModel != null)
{
       CustomerSeName = customer.ValidateSeName(CustomerSeName, CustomerModel.Email, true);
       _urlRecordService.SaveSlug(CustomerModel, CustomerSeName, 0);
}

in above code i am getting all the value in CustomerModel and CustomerSeName but when it executes SaveSlug() method it throws an Object reference not set error. I dont know which value it missing.Please help me out if someone knows the solution. Thanks in advance..!

1

There are 1 answers

3
Raphael On BEST ANSWER

I tried your code and couldn't compile.

After adding ISlugSupported to Customer entity and using this code all worked

private void GenerateCurrentCustomerSlug()
{
    var slug = _workContext.CurrentCustomer.ValidateSeName(seName: "", name: _workContext.CurrentCustomer.Email, ensureNotEmpty: true);
    _urlRecordService.SaveSlug(_workContext.CurrentCustomer, slug, languageId: 0);
}

The above code also works if there is no email set for current customer.