Copied to clipboard

Flag this post as spam?

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


  • Dan 15 posts 86 karma points
    Jul 09, 2018 @ 10:43
    Dan
    0

    Get extended content from basket item

    To a product (product doctype), I have added a property called 'payment type' to determine if the product is a subscription type product or a one-off payment. I need to get this when looping through my basket items (in a surface controller I have created) to set up the correct payment method in BrainTree (subscription or transaction). When expanding the extended data, the new property I have added to the doctype is not available. I am assuming that I need to get the IProductContent of each item? If so, what helper do I use? If not, what do I need to do to get this property?

    I have seen that I can inherit the BasketItemExtendedDataFactory and override the onCreate method, but I am unsure what to include in here.

    Another query I have, is, is there a way I can relate 2 products together and when one is added to the basket, the other is automatically added as well without overriding the 'AddBasketItem' method?

    Thanks, I really appreciate any help

  • Anon 29 posts 125 karma points
    Jul 13, 2018 @ 07:57
    Anon
    0

    What method are you using to retrieve your basket items? There's plenty of ways to convert between product models, but knowing what to convert from will help :)

    The second point shouldn't be too difficult - you could have a custom property called "Related Items" which - on hitting the Add to Basket method - would be checked and add these items to the basket.

  • Dan 15 posts 86 karma points
    Jul 18, 2018 @ 12:49
    Dan
    0

    Hi Matthew,

    I am using the customer context to retrieve my basket items. They come back as an ILineItemCollection. Below is the code I use.

     CustomerContext merchelloCustomer = new CustomerContext(UmbracoContext);
    var basketItems = merchelloCustomer.CurrentCustomer.Basket().Items;
    

    Thanks,

    Dan

  • Dan 15 posts 86 karma points
    Mar 06, 2019 @ 12:05
    Dan
    0

    Has anyone got an answer for this?

    I am looping through my basket items which each basket item is returned as a Merchello.Core.Models.ItemCacheLineItem but I want to try and convert it to a IProductContent so I can access custom properties that I added in my extended content.

    I have tried using the Merchello helper 2 ways:

    Merchello.TypedProductContent(basketItem.Key) Merchello.Query.Product.GetByKey(basketItem.Key)

    However, both of these return null.

    Does anyone know how to get the extended data?

    Thanks,

    Dan

  • Dave Clinton 31 posts 106 karma points
    Mar 08, 2019 @ 14:12
    Dave Clinton
    0

    Hey Dan,

    We went down the route of creating a custom controller inherited from BasketControllerBase with a custom AddItemModel as there were a few things we wanted to add to extended data.

    We then override the AddBasketItem method and use the default extended data object to store them (or you can create your own factory and override the "OnCreate" method):

    extendedData.SetValue("PaymentType", model.PaymentType);
    

    Wherever you want to get this value back you should be able to do the following with the line item:

    var paymentType = lineItem.ExtendedData.Where(x => x.Key == "paymentType").FirstOrDefault();
    

    Also if you're using the StoreBasketModel you should have access to lineItem.Product which will be an IProductContent object which may be of use?

    Hope that helps!

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft