We are using the build in Product.GetRelatedProducts() method to get related products, however we are using a multi-store implementation.
And the product has related products from two different stores, both related products are not enabled/available in the other store.
But using this method, just gets all related products. Irrelevant of whether they are available in the store or not? Have a missed something? I would have thought it would check to see if the product is actually allowed to be in the store before adding it?
I guess it's made that way incase you need to do some sort of cross-store related products.
You should however be able to make an extension yourself, that removes the product not present in the current store.
I might be a little tricky to get the info, but im thinking something like:
Get all catalogs from the present store
Get all categories from the catalogs.
Check if the product is present in any of categories.
Related Products With Multiple Stores?
We are using the build in Product.GetRelatedProducts() method to get related products, however we are using a multi-store implementation.
And the product has related products from two different stores, both related products are not enabled/available in the other store.
But using this method, just gets all related products. Irrelevant of whether they are available in the store or not? Have a missed something? I would have thought it would check to see if the product is actually allowed to be in the store before adding it?
I guess it's made that way incase you need to do some sort of cross-store related products. You should however be able to make an extension yourself, that removes the product not present in the current store.
I might be a little tricky to get the info, but im thinking something like:
Not sure if there is an easier way?
Hi Lee,
A solution might be:
ProductProductRelations
.Where(
pr => pr.ProductRelationType.Name == "relationName" &&
pr.RelatedProduct.CategoryProductRelations.Any(pcr => pcr.Category.ProductCatalog == SiteContext.Current.CatalogContext.CurrentCatalog));
I have not tested the code but it should be working as intended. Depending on how much data you have the query should perhaps be optimized.
Best regards Martin
Edit: It should compile now with following namespaces
using UCommerce.EntitiesV2;
using UCommerce.Runtime;
is working on a reply...