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 22, 2016 @ 17:21
    Tom Steer
    0

    Get products from collection without using Examine cache

    Hey,

    I'm writing a CSV import and need a way to get all the current products which are part of a collection but aren't in the examine cache. I've tried the following but they all seem to try get products from Examine:

    categoryCollection.GetEntities<IProduct>()
    
    _merchelloServices.ProductService.GetFromCollection(categoryCollection.Key, 1, 100)
    

    categoryCollection is an IEntityCollection. Any ideas of the correct way to do this?

    Thanks,

    Tom

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

    The extensions off of IEntityCollection will use the Merchello helper to query the products (so Examine first).

    However, you can use the fallback method directly from the ProductService

     public Page<IProduct> GetFromCollection( Guid collectionKey, long page,  long itemsPerPage, string sortBy = "",  SortDirection sortDirection = SortDirection.Descending)
    
  • Tom Steer 161 posts 596 karma points
    Nov 22, 2016 @ 18:07
    Tom Steer
    0

    Hi Rusty,

    Thanks for coming back to me. I did try GetFromCollection as you can see in my original post but this also didn't return any products.

    The reason I can't rely on examine is because the import saves the products with raise events set to false, which from what i can tell results in them not being added to the examine cache.

    However if I run the import again straight afterwards both of those method calls seem to return 0 products.

    Thanks,

    Tom

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 22, 2016 @ 18:55
    Rusty Swayne
    0

    Are you using the product service in your import? Maybe it's the RuntimeCache not getting cleared?

  • Tom Steer 161 posts 596 karma points
    Nov 23, 2016 @ 09:07
    Tom Steer
    1

    Hi Rusty,

    This is working now, it turned out to be something I was doing rather than anything in the Merchello code base :( . Thank you for your help anyway and sorry to waste your time.

    Cheers, Tom

Please Sign in or register to post replies

Write your reply to:

Draft