Linking members to customers without member creation
Hi there,
I had to deal with a request by our client, that there should be a way to checkout without creating any member data in Umbraco. But IF an user is a registered member, he should still be linked to his customer record. This gives us the possibility to display his order history, order address and so on.
At the moment of writing this, UCommerce only supports linking in combination with the creation of new members, when a customer isn't logged in and has no already registered email address.
So I had to create my own pipeline task for this, which I like to share with you. The code is based on Søren's work, I just modified it to fit my needs.
Here's the code, build this and put it into /bin:
namespace YourNamespaceHere.Pipelines.Checkout { public class LinkCustomerToMember : IPipelineTask<PurchaseOrder> { private Member GetUmbracoMember(string username, string emailAddress, int memberGroupId, int? umbracoMemberTypeId) { try { if(Member.IsLoggedOn()) { return Member.GetAllAsList().Where(m => m.Id == Member.CurrentMemberId()).Single(); //return Member.GetCurrentMember(); <- not working properly in Umbraco 4.7RC } if(Member.IsMember(emailAddress)) { return Member.GetMemberFromEmail(emailAddress); } } catch(Exception ex) { return null; } return null; } private void LinkUmbracoMemberForOrder(PurchaseOrder purchaseOrder) { if(purchaseOrder.ProductCatalogGroup.UmbracoMemberGroupId.Value <= 0) { throw new ConfigurationErrorsException(string.Format("No member group configured for product catalog group {0}", purchaseOrder.ProductCatalogGroup.Name)); } if(purchaseOrder.ProductCatalogGroup.UmbracoMemberTypeId.Value <= 0) { throw new ConfigurationErrorsException(string.Format("No member type configured for product catalog group {0}", purchaseOrder.ProductCatalogGroup.Name)); } Customer customer = purchaseOrder.Customer; Member member = this.GetUmbracoMember(customer.EmailAddress, customer.EmailAddress, purchaseOrder.ProductCatalogGroup.UmbracoMemberGroupId.Value, purchaseOrder.ProductCatalogGroup.UmbracoMemberTypeId); if(member != null) { customer.UmbracoMemberId = member.Id; customer.Save(); } } public PipelineExecutionResult Execute(PurchaseOrder purchaseOrder) { if(purchaseOrder.ProductCatalogGroup.CreateCustomersAsUmbracoMembers) { this.LinkUmbracoMemberForOrder(purchaseOrder); } return PipelineExecutionResult.Success; } } }
Now you have to edit /umbraco/UCommerce/Pipelines/Checkout.config (don't forget to backup first).
Linking members to customers without member creation
Hi there,
I had to deal with a request by our client, that there should be a way to checkout without creating any member data in Umbraco. But IF an user is a registered member, he should still be linked to his customer record. This gives us the possibility to display his order history, order address and so on.
At the moment of writing this, UCommerce only supports linking in combination with the creation of new members, when a customer isn't logged in and has no already registered email address.
So I had to create my own pipeline task for this, which I like to share with you. The code is based on Søren's work, I just modified it to fit my needs.
Here's the code, build this and put it into /bin:
Now you have to edit /umbraco/UCommerce/Pipelines/Checkout.config (don't forget to backup first).
Replace this
with
and insert the following after <!-- Pipeline Tasks-->:
Don't forget to enable "Create customers as members" in your catalog settings.
Hope this may be useful to anyone besides me. ;-)
bye
Christian
Cool stuff. I'll look into splitting the existing pipeline to support both scenarios out of the box.
is working on a reply...