Developer forum

Forum » Development » Related Product List Provider

Related Product List Provider

Mikkel Toustrup Olsen
Reply

Hey all, 

I am trying to implement a custom product list provider, where I would like remove products based on the logged in user's permission. We have some custom code that filters products based on the user's customer number. So e.g. Customer A may see 4 products in a context where Customer B may see 6 products and so on.

I am using a related product list provider, as one of the related products should be "removed" for Customer A. However, I cannot seem to trigger the actual removal of the product.

I am able to loop the products in the above mentioned context and furthermore parse the correct product  id to a ProductCollection - called ProductsToRemove. I then try to Remove this productcollection from my original one (that I instantiate at the beginning with the evetnArgs.Products) - however no luck.

Am I missing something? - Attached is a dump of my provider.

BR

Mikkel

_relatedProductListProvider.png

Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Mikkel

You have 2 collections - and each collection have the different instances of the same products. So when you call Remove on one collection using a product instance from another collection, they are not the same, and will therefore not be removed. So you should not remove by instance, but by productID. Makes sense?

BR Nicolai

Votes for this answer: 1
 
Mikkel Toustrup Olsen
Reply

Hi Nicolai,

Yeah, makes perfect sense. I actually got it working in the mean time. I figured I could handle the logik in my ProducListCollectionProvider where I already filtered the products a specific user is allowed to see. In that context I was able to catch the collection returned from the .RelatedProducts() method and filter it afterwards :-) 

... and yeah I do the logic on the productid as you mentioned.

BR

Mikkel

 

You must be logged in to post in the forum