문제

I would like to add the Gtin to the _ProductPrice.cshtml View I've added it to ProductPriceModel in the ProductModel,

public string Gtin { get; set; }

But can't seem to populate it. I can populate the Price and OldPrice as that's standard to NopCommerce, they all come from the same table but I don't know where they are being populated?

I've tried to populate Gtin in the NonAction in CatalogController.cs:

protected ProductModel.ProductPriceModel PrepareProductPriceModel(Product product)

But to no avail, where should I be looking next,

Any help would be greatly appreciated.

도움이 되었습니까?

해결책 2

I was able to obtain the value in the:

protected ProductModel.ProductPriceModel PrepareProductPriceModel(Product product)

Action via the productVariant model

model.Gtin = productVariant.Gtin;

다른 팁

I don't recommend you modify the default View Models. Future upgrades will break your templates. Believe me, I've been on that path.

I think the Gtin attribute is already available in the ProductDetailsModel, so perhaps you could use the ViewBag property to make it available for the inner ProductPrice view.

Something like this on the outer view:

@{ 
     ViewBag.Gtin = Model.Gtin
 }

And then in the inner (price) view:

<span class="gtin">@(ViewBag.Gtin ?? "")</span>

Just to avoid errors if null.

Hope it helps!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top