簡體   English   中英

從nopCommerce中的產品ID訪問基本nop模型自定義屬性

[英]Accessing base nop model custom properties from a product id in nopCommerce

我正在嘗試訪問我通過產品ID獲取的產品的自定義屬性,但我真的不知道該怎么做。

所以,如果我像這樣抓住產品:

var product = _productService.GetProductByIds(productId);

我想用if語句訪問這些​​屬性:

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

似乎無法在此找到任何東西,任何人都可以幫忙嗎?

首先, GetProductById 回歸的產品列表,或許你打算只得到一個單一的產品。 因此,請改用GetProductById。

此外,沒有像“熱門”內部產品模型,可能你已經添加了自定義。

最后,我假設你想檢查產品模型中是否存在該屬性! 這可以做如下,

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM