从nopCommerce中的产品ID访问基本nop模型自定义属性

问题描述 投票:0回答:1

我正在尝试访问我通过产品ID获取的产品的自定义属性,但我真的不知道该怎么做。

所以,如果我像这样抓住产品:

var product = _productService.GetProductByIds(productId);

我想用if语句访问这些​​属性:

product.CustomProperties.Keys.Contains("Popular")   

似乎无法在此找到任何东西,任何人都可以帮忙吗?

c# properties nopcommerce
1个回答
0
投票

首先,GetProductByIds返回产品列表,也许您打算只获得一个产品。因此,请改用GetProductById。

此外,没有像“热门”内部产品模型,可能你已经添加了自定义。

最后,我假设你想检查产品模型中是否存在该属性!这可以做如下,

var product = _productService.GetProductById(productId);
var productProperty =  product.GetType().GetProperty("Sku");
if(productProperty != null)
{
    //exists
}
else
{
    //doesn't exists
} 
© www.soinside.com 2019 - 2024. All rights reserved.