Can anyone confirm with me the correct procedure for changing the content type of an existing content item?
I'm working on a commerce module (with the guidance from Sipke's excellent webshop blog series) and have defined a CustomerPart for storing commerce related information for each customer, and have defined a "Customer" content type that includes
the existing Orchard UserPart and the CustomerPart that I've defined.
During checkout, this all works well for a new customer signup, as the Customer content item is created, or for an existing customer, the existing authenticated customer's content item is retrieved.
However, I have the situation where I have a number of "Users" that may exist that are not yet "Customers" (ie. they do not have the CustomerPart and their content item type is User, not Customer).
During checkout, if I fail to retrieve the CustomerPart for the currently authenticated User then I want to change the user into a Customer. Something along the lines of:
var customer = currentUser.ContentItem.As<CustomerPart>();
// If the authenticated used is not yet a customer then firstly generate a customer record
if (customer == null)
customer = _customerService.MakeCustomer(currentUser);
Now in the customer service's MakeCustomer implementation, I'm attempting the following:
customerPart = new CustomerPart
Record = new CustomerPartRecord
CreatedAt = _dateTimeService.Now
user.ContentItem.TypeDefinition = _contentDefinitionManager.GetTypeDefinition("Customer");
The problem is, although the customer apart appears to get added to the content item, the type definition of the content item remains as "User". Ie. in the Orchard_Framework_ContentItemRecord table the entry for the User (in my case the admin user
with id = 2) still has a ContentType_id of 2 (User) instead of 10 (Customer). I then have problems when attempting to retrieve the content item as a customer later on.
Is there a more correct approach to this problem?