Copied to clipboard

Flag this post as spam?

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


  • Pantelis 53 posts 107 karma points
    Jun 19, 2015 @ 11:13
    Pantelis
    0

    Existing Basket after Customer Signin

    Hi, I have a strange issue with the Basket when a customer signs in and it's not empty. The Basket contents are preserved but the "ItemCache" table is not updated. The Basket is recreated in memory (I have checked that the item keys are newly generated, they are not the same with the pre-signing in keys).

    As soon as I make a Basket Table update (change a quantity or add a new item), the items are again recreated (I have a new 3rd unique item key, so a 3rd version of the Basket) which then are written to the "ItemCache" table.

    What it does is it creates the 3rd version of the Basket guid's by copying the 1st version and inserting only the newly added items. All changes (quantity updates) on the 2nd version are dropped.

    I'm playing by copying code from Bazaar into a custom implementation and I faced an error of "no parameter-less constructor available" for the:

    UmbracoViewPage<MyBasketModel>
    

    So I ignored that inheriting from UmbracoTemplatePage, and what I did was a bit silly but I still think it should work:

    @Html.Partial("ShopBasketTable", new MyBasketTableModel(Model.Content))
    

    which creates a similar to BasketTable model from "CurrentCustomer.Basket" which is newly referenced in MyBasketTableModel constructor:

    this.CurrentCustomer = new CustomerContext(Umbraco.Web.UmbracoContext.Current).CurrentCustomer;
    

    And I'm guessing something is going terribly wrong among these lines :( because my signin code is basically identical to Bazaar's.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jun 19, 2015 @ 16:03
    Rusty Swayne
    0

    Hi there. Actually I think your the first to be trying this sort of thing (which is exactly why I set things up this way ... so I'm pretty stoked your giving it a go).

    A couple of things:

    The basket conversion process happens in the CustomerContext. What happens is when the customer gets converted from anonymous to a customer the reference record in merchAnonymousCustomer is abandoned and the application starts referencing the merchCustomer record (so it uses the pk from that table instead of the pk in the merchAnonymousCustomer table).

    In order to keep your reference to your third ItemCache, you will need to make sure that the "entityKey" GUID in your customer ItemCache gets updated to the new CustomerKey (pk from merchCustomer). We don't have an event setup at the moment (writing that down now to get into 1.9.1 - CustomerContextBase.ConvertingBasket and CustomerContextBase.ConvertedBasket) - but the quickest way to do it now would be to write your own converting strategy.

    Depending on how you want the anonymous to customer baskets merged, you can look at either for a reference:

    https://github.com/Merchello/Merchello/blob/1.9.0/src/Merchello.Web/Workflow/BasketConversionByCombiningAnonymousBasket.cs (Merges the two together)

    or

    https://github.com/Merchello/Merchello/blob/1.9.0/src/Merchello.Web/Workflow/BasketConversionByDiscardingPreviousCustomerBasket.cs (Overwrites the previously saved customer basket if there are any items in the anonymous customer basket).

    Then write your own class sub-classing BasketConversionBase to update your 3rd item cache entity key reference.

    In order to get Merchello to use your strategy instead of the one it ships with, go to the merchello.config file and find the line:

        <strategies>
          <!-- replace the following with a reference to your class -->
          <strategy alias="DefaultAnonymousBasketConversionStrategy" type="Merchello.Web.Workflow.BasketConversionByDiscardingPreviousCustomerBasket, Merchello.Web" />
    
        </strategies>
    

    so

       <strategies>
            <strategy alias="DefaultAnonymousBasketConversionStrategy" type="MyType, My.Library" />
      </strategies>
    

    That should do the trick.

    Regarding:

    I'm playing by copying code from Bazaar into a custom implementation and I faced an error of "no parameter-less constructor available" for the:

    The Bazaar models inherit from PublishedContentWrapped which take the respective content IPublishedContent as a parameter. We will be refactoring these to use PublishedContentModel instead of PublishedContentWrapped (basically the same thing) but it will be easier to use my new favorite package Ditto =)

    Love to know how this goes.

  • Pantelis 53 posts 107 karma points
    Jun 19, 2015 @ 20:14
    Pantelis
    1

    Well what I love about Merchello is that you can basically implement an e-shop anyway you like it.

    Thanks about the heads-up on PublishContentWrapped, I fixed that! And yes, I was inheriting from a wrong class.

    Concerning the issue, I traced the basket conversion on profiler and it runs when the basket view is actually requested. It empties the customer's old basket and tries to convert the anonymous basket.

    (Side note: shouldn't the basket conversion process take place upon signin? Since we are going to abandon the anonymous basket anyway I think it's better to do it ahead.)

    What it ends up with is inserting the items from the anonymous basket 6 times. Maybe that's because trying to troubleshoot this I overused Basket.Save(). Every one of the 6 times it inserts into ItemCacheItem it uses a new unique key (and 5 times it clears it up). My basket view for some reason grabs and displays the 5th insert. When I refresh the view it correctly displays the keys from the 6th insert.

    I couldn't run a debugger now, but I will pursue this issue further when I have some free time and I'll keep you posted.

    Also the two new events sound great!

    Thank you very much.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jun 19, 2015 @ 20:56
    Rusty Swayne
    0

    I really appreciate your comments.

    There are a couple of different reasons we chose not to do the conversion process at sign-in.

    • It is possible for certain member types to be customers while others are not.
    • We cannot be certain the site uses the default MembershipProvider that ships with Umbraco.

    The process actually gets kicked off in the CustomerContext. The entire purpose of that class is to keep track of the customer - manages the cookie and pays attention to whether or not the member is authenticated.

Please Sign in or register to post replies

Write your reply to:

Draft