Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm outputting the category name on the productlist - which works fine:
var category = SiteContext.Current.CatalogContext.CurrentCategory; <h1>@category.DisplayName()</h1>
But if I try the same lines of code in the productcard, "category" will always be null.
Does this have to do with a product being able to have multiple categories?
If the URI is correct you should be able to the the current category by context.
Could you post the relative URL for the product page?
(It should look something like this: /niceUrlCategory/contextCategory/productName/c-1/c-2/p-3 )
Hi Nickolaj. I see that that the category context is missing from my produktcard URI
Productlist URI: /produkter/tilbehoer/c-23/c-69
Productcard URI: /produkter/sort-stol/c-23/p-105
Perhaps I am missing something in my productlist...?
var category = SiteContext.Current.CatalogContext.CurrentCategory;foreach (var cat in category.Categories) {var products = CatalogLibrary.GetProducts(cat); @foreach (var product in products) {<a href="@CatalogLibrary.GetNiceUrlForProduct(product)">Product</a>}}
Hi skooter You need to use the UCommerce.Api.CatalogLibrary.GetNiceUrlForProduct(product,category) overload, to get the category context on the product page :)
UCommerce.Api.CatalogLibrary.GetNiceUrlForProduct(product,category)
Thankyou very much Nickolaj. That did it :-)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Output category name on productcard
I'm outputting the category name on the productlist - which works fine:
But if I try the same lines of code in the productcard, "category" will always be null.
Does this have to do with a product being able to have multiple categories?
If the URI is correct you should be able to the the current category by context.
Could you post the relative URL for the product page?
(It should look something like this: /niceUrlCategory/contextCategory/productName/c-1/c-2/p-3 )
Hi Nickolaj. I see that that the category context is missing from my produktcard URI
Productlist URI: /produkter/tilbehoer/c-23/c-69
Productcard URI: /produkter/sort-stol/c-23/p-105
Perhaps I am missing something in my productlist...?
Hi skooter You need to use the
UCommerce.Api.CatalogLibrary.GetNiceUrlForProduct(product,category)
overload, to get the category context on the product page :)Thankyou very much Nickolaj. That did it :-)
is working on a reply...