Getting the following error straight after registering a new customer:
Unable to cast object of type 'Merchello.Core.Models.AnonymousCustomer' to type 'Merchello.Core.Models.ICustomer'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'Merchello.Core.Models.AnonymousCustomer' to type 'Merchello.Core.Models.ICustomer'.
Source Error:
Line 7: Layout = "Master.cshtml";
Line 8:
Line 9: var customer = (ICustomer)CurrentCustomer;
Line 10: }
Line 11:
Source File: ---\Views\Account.cshtml Line: 9
I can see in the Backoffice Members section that the Customer is getting created and assigned to the Customers group successfully. It appears as though the new customer is not identified as belonging to the Customers group when they're first created and redirected to the Account page.
Anyone else getting this error? (Using V2.1.0 and FastTrack).
I am using the default FastTrack configuration. It has one minor difference to what you've mentioned above, which is the Member Group name is "Customers" as opposed to "Customer".
I didn't unfortunately. That was just 1 of several hurdles I encountered when evaluating Merchello. In the end I decided that trying to get Merchello to do everything I wanted was going to be too steep a learning curve for me at present, so went back to using nopCommerce for the time being.
It wasn't the MemberType or a config issue...it seemed to be corrupt Merchello customer data.
I deleted the member record and delete the corresponding customer records from the database and re-registered via Fast Track and it'll all sprung into life again.
I too have been experiencing this issue. This seems to happen when I am redirected to the Account page on a successful login.
It seems to be occurring within the following file:
Merchello.Web.Store\Controllers\CustomerMembershipController.cs Line: 31
var customer = (ICustomer)CurrentCustomer;
Specifically, It seems to be when CurrentCustomer is being cast to ICustomer.
Also, this only seems to occur when the "merchello" cookie is not present.
When I login and the "merchello" cookie is present, I do not encounter this error.
But, if I logout and delete the "merchello" cookie, and then attempt to login again, this is when I encounter the error.
My site is completely locked down and the first page users will see is the login screen as no other part of the site should be accessible unless the user is logged in. So, when users first come to the site, there will be no "merchello" cookie present, or at least this isn't currently being created at this point.
Is there any reason why the "merchello" cookie is not being created, when one doesn't currently exists? And is there a way that I can ensure that the "merchello" cookie has been created containing the relevant value?
I am using the FastTrack starter kit, pretty much untouched in terms of the membership stuff (i.e. login form and account page).
Thanks for that, thats seems to have pointed me in the correct direction I think.
I was using Umbraco.Web.Mvc.UmbracoTemplatePage on my Layout view, being used by my Login page, instead of Merchello.Web.Mvc.MerchelloTemplatePage, but that in itself didn't fix the issue.
It wasn't until I had called CurrentCustomer.Basket() within the view that it then created the "merchello" cookie.
So, it seems to be all sorted now by calling that.
Once these are in place, use Umbraco Role Based on Account page, for customers. Should redirect automatically to login page then. (don't forget to set login page on role based selection).
Error upon Customer Registration using FastTrack
Getting the following error straight after registering a new customer:
I can see in the Backoffice Members section that the Customer is getting created and assigned to the Customers group successfully. It appears as though the new customer is not identified as belonging to the Customers group when they're first created and redirected to the Account page.
Anyone else getting this error? (Using V2.1.0 and FastTrack).
Hey Gavin,
Are you using a MemberType MerchelloCustomer (aliased "merchelloCustomer") and the Member Group ("Customer")
The Account page by default should also be role based and require the Customer group.
Hi Rusty,
I am using the default FastTrack configuration. It has one minor difference to what you've mentioned above, which is the Member Group name is "Customers" as opposed to "Customer".
Hey Gavin, Did you ever figure this out? I'm getting the same issue with Fast Track out of the box.
I didn't unfortunately. That was just 1 of several hurdles I encountered when evaluating Merchello. In the end I decided that trying to get Merchello to do everything I wanted was going to be too steep a learning curve for me at present, so went back to using nopCommerce for the time being.
Sorry I couldn't be of more help.
If you are using a custom MemberType then you need to update the Merchello.Config to know about it.
Hey Lee,
It's now working fine.
It wasn't the MemberType or a config issue...it seemed to be corrupt Merchello customer data.
I deleted the member record and delete the corresponding customer records from the database and re-registered via Fast Track and it'll all sprung into life again.
Thanks, T
Hello,
I too have been experiencing this issue. This seems to happen when I am redirected to the Account page on a successful login.
It seems to be occurring within the following file:
Specifically, It seems to be when CurrentCustomer is being cast to ICustomer.
Also, this only seems to occur when the "merchello" cookie is not present.
When I login and the "merchello" cookie is present, I do not encounter this error.
But, if I logout and delete the "merchello" cookie, and then attempt to login again, this is when I encounter the error.
My site is completely locked down and the first page users will see is the login screen as no other part of the site should be accessible unless the user is logged in. So, when users first come to the site, there will be no "merchello" cookie present, or at least this isn't currently being created at this point.
Is there any reason why the "merchello" cookie is not being created, when one doesn't currently exists? And is there a way that I can ensure that the "merchello" cookie has been created containing the relevant value?
I am using the FastTrack starter kit, pretty much untouched in terms of the membership stuff (i.e. login form and account page).
Thanks,
Chris
Hi Chris,
The CustomerContext needs to be instantiated at least to add the customer cookie. You can change your initial view you inherit from
This will instantiate the CustomerContext for you.
Hi Rusty,
Thanks for that, thats seems to have pointed me in the correct direction I think.
I was using Umbraco.Web.Mvc.UmbracoTemplatePage on my Layout view, being used by my Login page, instead of Merchello.Web.Mvc.MerchelloTemplatePage, but that in itself didn't fix the issue.
It wasn't until I had called CurrentCustomer.Basket() within the view that it then created the "merchello" cookie.
So, it seems to be all sorted now by calling that.
Thanks again for your help.
Chris
Ah right - that makes sense as there it populates the private
_currentCustomer
when it is first required and it's that class that manages the cookie.Make sure in Umbraco Members these exist
Member Group = Customers Member Type = Merchello Customer
see here https://skrift.io/articles/archive/how-to-quickly-add-ecommerce-to-your-existing-website/
Once these are in place, use Umbraco Role Based on Account page, for customers. Should redirect automatically to login page then. (don't forget to set login page on role based selection).
is working on a reply...