Posted on 22/12/2022 15:48:35
Hi Aki
Yes - but that problem you mention here, comes not from the missing primary setting, but from a "malformed" link to the product on the frontpage.
When rendering the list of products, you have to create a link that contains the "PrimaryOrDefault" group from the product - which takes the current shop context into consideration. That will then return a group from the current shop. On that group, you can specify the default page for the group (and that can be different on different languages). Using that group and the pageid from that group instance, you can create a URL like this /Default.aspx?ID={GroupPrimaryPageID}&GroupID={Product.PrimaryOrDefaultGroupID}&ProductID={ProductID}.
The productViewmodel has a property, PrimaryOrDefaultGroup, that will give you the correct groupid. Also there is an extention method for ProductViewmodel in Dynamicweb.Ecommerce.Productcatalog namespace that will give you a GetProductLink() method that will generate the above URL for you (you need a relatively late DW 9.14 to get that extension method)
With what you describe, it sounds like you just do "Default.aspx?ID={CurrentPageID}&ProductID={ProductID}.
Also it indicates that you are still on the 'old' URL system and not the page based URL providers that are more 'precise' and can be controlled better.
For reference - this is how the above extension method is creating the link - if you need to re-create it on older installations:
public static string GetProductLink(this ProductViewModel product, int pageId, bool usePrimaryGroupPageId = true)
{
if (product.PrimaryOrDefaultGroup.PrimaryPageId > 0 && usePrimaryGroupPageId)
pageId = product.PrimaryOrDefaultGroup.PrimaryPageId;
var productlink = $"Default.aspx?ID={pageId}&GroupID={product.PrimaryOrDefaultGroup.Id}&ProductID={product.Id}";
if (!string.IsNullOrEmpty(product.VariantId))
productlink += $"&VariantID={product.VariantId}";
return productlink;
}
If you are still on the tag based product catalog, it also contains a tag for this.