Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Christian Wendler 46 posts 155 karma points
    Mar 08, 2011 @ 01:22
    Christian Wendler
    1

    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).

    Replace this

    <value>${Checkout.CreateMemberForCustomer}</value>

    with

    <value>${Checkout.LinkCustomerToMember}</value>

    and insert the following after <!-- Pipeline Tasks-->:

      <component id="Checkout.LinkCustomerToMember"
           service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
           type="YourNamespaceHere.Pipelines.Checkout.LinkCustomerToMember, YourAssembly"
           lifestyle="Thread" />

    Don't forget to enable "Create customers as members" in your catalog settings.

     

    Hope this may be useful to anyone besides me. ;-)

     

    bye

    Christian

  • Søren Spelling Lund 1797 posts 2786 karma points
    Mar 08, 2011 @ 16:53
    Søren Spelling Lund
    0

    Cool stuff. I'll look into splitting the existing pipeline to support both scenarios out of the box.

Please Sign in or register to post replies

Write your reply to:

Draft