Copied to clipboard

Flag this post as spam?

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


  • Tom Steer 161 posts 596 karma points
    Nov 29, 2016 @ 08:39
    Tom Steer
    0

    Multiple Saved Baskets

    Morning Rusty,

    Following your advice from a little while back about having the ability to have multiple saved baskets. I have created a savedbasket class (which is based around the wishlist class) everything seems to be working great, but I can't ever get the custom item cache from the itemcacheservice, I've added it in the merchello.config file, and can successfully resolve it from the ItemItemCache.CustomTypeFields, but I can't ever get an instance of it? Do I need to somehow initialise it before I can resolve it?

    Cheers,

    Tom

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 29, 2016 @ 17:21
    Rusty Swayne
    0

    Hey Tom - to get an instance of it, you will need to use the ItemCacheService (and maybe create an extension off of ICustomerCase).

  • Tom 23 posts 79 karma points
    Nov 30, 2016 @ 09:20
    Tom
    0

    Hi Rusty,

    We have actually done both of those, the bit we are struggling with is this part of the wishlist code (line 159):

    var customerItemCache = merchelloContext.Services.ItemCacheService.GetItemCacheWithKey(wishlist.Customer, ItemCacheType.Wishlist);
    

    We have tried ItemCacheType.Custom, (which didn't work) possibly because the ItemCacheTypeField.BuildCache(); doesn't support it?

    AddUpdateCache(ItemCacheType.Custom, NotFound);
    

    We've also tried multiple ways of getting the cache using the custom typefield which we can successfully get via

    var typeField = EnumTypeFieldConverter.ItemItemCache.CustomTypeFields.FirstOrDefault(x => x.TypeKey == Domain.AppConstants.SavedBasketKey);
    

    And tried these:

    var cache = merchelloContext.Services.ItemCacheService.GetItemCaches(typeField.TypeKey);
    var cache2 = merchelloContext.Services.ItemCacheService.GetItemCaches(customer.Key);
    var cache3 = merchelloContext.Services.ItemCacheService.GetByKey(typeField.TypeKey);
    var cache4 = merchelloContext.Services.ItemCacheService.GetByKey(customer.Key);
    var cache5 = merchelloContext.Services.ItemCacheService.GetEntityItemCaches(customer.Key, typeField.TypeKey);
    var cache6 = merchelloContext.Services.ItemCacheService.GetItemCacheByCustomer(customer, typeField.TypeKey);
    

    But still no luck with the custom cache :( Any ideas?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 30, 2016 @ 17:15
    Rusty Swayne
    0

    When you first create your custom item cache, what are you using as the entityKey ... it should be the customer key.

    The EnumTypeFieldConverter is not going to do much for you with custom type fields. For custom type fields it's really only useful for the back office controllers so they don't choke on what would otherwise be a known type field.

    What is being returned for your:

     cache
     cache2
     cache3 ....
    

    If there is a record there it should be returning ... those are pretty much wrapped repository calls ...

  • Tom 23 posts 79 karma points
    Nov 30, 2016 @ 19:57
    Tom
    0

    Hi Rusty,

    We are using the customer key as the entity key.

    cache is empty, cache2 has basket and checkout caches, cache3 is null, cache4 is null, cache5 is empty, cache6 is null.

    Do we have to manually create the custom item caches? we were under the impression that custom item caches would be created by merchello after adding them to the config file, or is that not the case?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 01, 2016 @ 00:00
    Rusty Swayne
    0

    Hey Tom

    You do have to create the item caches.

    Checkout the basket object - it's done internally.

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/Workflow/Basket.cs#L101

  • Tom 23 posts 79 karma points
    Dec 01, 2016 @ 10:13
    Tom
    0

    Hi Rusty,

    That's the bit we are failing on, just here:

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/Workflow/Basket.cs#L112

    The itemcache service doesn't return anything, no matter what we pass it?

    Edit:

    We may have tracked this down, but could use your expert eye on it! It looks like it was failing in the itemcacheservice when trying to create an instance of the itemcache class here:

    https://github.com/Merchello/Merchello/blob/master/src/Merchello.Core/Services/ItemCacheService.cs#L196

    as when the cache is not found or created yet the itemcacheservice creates an instance of itemcache, it looks like it calls this constructor

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Core/Models/ItemCache.cs#L49

    which then goes on to call

    EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey

    which, looks like it will only ever call

    https://github.com/Merchello/Merchello/blob/f3dd636fb3449d58d82ecd178b2ce9b1093c9615/src/Merchello.Core/Models/TypeFields/TypeFieldMapper.cs#L48

    as it is passing a enum, but if it called this instead,

    https://github.com/Merchello/Merchello/blob/f3dd636fb3449d58d82ecd178b2ce9b1093c9615/src/Merchello.Core/Models/TypeFields/TypeFieldMapper.cs#L38

    then it would work as expected?

    We have temporarily bypassed this and called this constructor using reflection (as it is internal)

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Core/Models/ItemCache.cs#L98

    and then saving it using the itemcacheservice, at which point we can then carry on and sucessfully create the object which is added to the cache and then can be used.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Dec 01, 2016 @ 16:13
    Rusty Swayne
    0

    Hi Tom,

    Hmm - I see what you're talking about now. That does indeed need to be reviewed due to the internals.

    It is weird (must have been a reason early on) that I've left the ItemCacheTfKey property public even though it is set via the constructor.

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Core/Models/ItemCache.cs#L126

    Did your bypass approach and circumvent the service for the original creation of the item cache ... something like this?

      // TODO refactor to use service when patch available
      //
      // start by using an ItemCacheType that the converter already has cached.  
      var itemCache = new ItemCache(customer.Key, ItemCacheType.Wishlist);
    
      itemCache.ItemCacheTfKey = [YOUR GUID FROM THE CONFIG];
    
     // save the item cache
     MerchelloContext.Current.Services.ItemCacheService.Save(itemCache);
    

    I'll add a few tasks to 2.4.0 to clean this up!

    Thanks for the effort and helping sort out figure out what the issues are.

  • Tom 23 posts 79 karma points
    Dec 01, 2016 @ 19:27
    Tom
    1

    Hi Rusty,

    I didn't actually think of doing it like that, that's far more elegant than what I did.. haha!

    I ended up doing this..

    var type = typeof(ItemCache);
            var args = new object[] { customer.Key, typeField.TypeKey };
            var instance = type.Assembly.CreateInstance(type.FullName, false, BindingFlags.Instance | BindingFlags.NonPublic, null, args, null, null);
            var itemCache = (ItemCache)instance;
            merchelloContext.Services.ItemCacheService.Save(itemCache);
    

    But I'll definitely update to use your way until 2.4.0

    You're welcome, thanks for your help in pointing us in the right direction to start with and creating a great package :)

Please Sign in or register to post replies

Write your reply to:

Draft