Copied to clipboard

Flag this post as spam?

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


  • Peter 27 posts 192 karma points
    Nov 08, 2016 @ 13:07
    Peter
    0

    Implementing a custom ConversionStrategy

    Hello,

    I am trying to implement my own ConversionStrategy for updating the basket items upon login. I have based my implementation on the documentation which states:

    Creating a customized the basket conversion strategy can be accomplished by adding a new class that inherits from BasketConversionBase and implementing the Merge() method and then introducing the type reference in the merchello.config.

    My setup is as follows:

    <strategies>
        ...
        <!--<strategy alias="DefaultAnonymousBasketConversionStrategy" type="Merchello.Web.Workflow.BasketConversionByDiscardingPreviousCustomerBasket, Merchello.Web" />-->
        <!--<strategy alias="DefaultAnonymousBasketConversionStrategy" type="Merchello.Web.Workflow.BasketConversionByCombiningAnonymousBasket, Merchello.Web" />-->
        <strategy alias="DefaultAnonymousBasketConversionStrategy" type="My.Namespace.MyType, MyLibrary />
    </strategies>
    

    My custom class sub-classing BasketConversionBase

    public class MyType : BasketConversionBase
    {
        public override IBasket Merge()
        {
            // update basket item prices and return basket
        }
    }
    

    This will not compile though, as I get the following error message: 'BasketConversionBase' does not contain a constructor that takes 0 arguments. Cannot access internal constructor 'BasketConversionBase' here.

    I tried implementing the Merge() method instead of overriding it:

    public class MyType : IBasketConversionBase
    {
        public IBasket Merge()
        {
            // update basket item prices and return basket
        }
    }
    

    This does compile but will not trigger.

    I am using Umbraco 7.5.3 with Merchello 2.2.1. I also tested with Merchello 2.3.0 but I am getting the same error.

    How can I proceed with this?

    Additional question: How would I go about implementing a conversion strategy for the reversed scenario - when a user is logging out?

    BR Peter

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 08, 2016 @ 17:16
    Rusty Swayne
    100

    Hey Peter,

    It looks like you've found a logic error. The constructor in BasketConversionBase should be protected not internal. I'll raise the issue and get it resolved for the next release. I'll look at creating a patch build for you today ...

    This is the issue:

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/Workflow/BasketConversionBase.cs

        /// <summary>
        /// Initializes a new instance of the <see cref="BasketConversionBase"/> class.
        /// </summary>
        /// <param name="anonymousBasket">
        /// The anonymousBasket.
        /// </param>
        /// <param name="customerBasket">
        /// The customerBasket.
        /// </param>
        internal BasketConversionBase(IBasket anonymousBasket, IBasket customerBasket)
        {
            Mandate.ParameterNotNull(anonymousBasket, "anonymousBasket");
            Mandate.ParameterNotNull(customerBasket, "customerBasket");
    
            AnonymousBasket = anonymousBasket;
            CustomerBasket = customerBasket;
        }
    
  • Peter 27 posts 192 karma points
    Nov 09, 2016 @ 08:06
    Peter
    0

    Hey Rusty,

    Thank you for responding - I am looking forward to getting the issue fixed :]

    Do you have any suggestions how I can proceed with a logout ConversionStrategy to convert the basket items into anonymous basket items?

    BR Peter

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 10, 2016 @ 13:57
    Rusty Swayne
    0

    Hey Peter,

    When a customer logs out a new anonymous customer is generated which creates an empty basket. Anything that was in the basket for the logged in customer is still there - so if they log in again, they will see it.

    What do you need to do when the customer logs out?

  • Peter 27 posts 192 karma points
    Nov 11, 2016 @ 12:32
    Peter
    0

    Hey Rusty,

    I am handling multiple subscription types, which influence the price you pay for a product - the most expensive subscription type will give you the biggest discounts etc.

    Additionally users must be able to purchase a product without logging in/without any subscriptions running, resulting in no discount. For this reason I would like to be able to modify the basket items upon login, so that the discounts are taken into account - this is what I am doing with the conversion strategy mentioned earlier.

    Similarly I would like to persist the basket items upon logout, and change the prices of all items to base prices (no discount)...does this make sense?

    I know it is probably a thought-up scenario, but I could imagine customers being confused, if they logged out and all their basket items were gone - especially when they are not required to login in order to purchase products.

Please Sign in or register to post replies

Write your reply to:

Draft