在nopCommerce中从产品ID访问基本Nop模型定制属性

时间:2019-03-29 03:20:55

标签: c# properties nopcommerce

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

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

var product = _productService.GetProductByIds(productId);

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

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

似乎找不到任何东西,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

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

此外,产品模型中没有类似“热门” 的商品,可能您已经添加了自定义商品。

最后,假设您要检查产品模型中是否存在该属性!可以做到如下,

var product = _productService.GetProductById(productId);
var productProperty =  product.GetType().GetProperty("Sku");
if(productProperty != null)
{
    //exists
}
else
{
    //doesn't exists
}