Question

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.

Was it helpful?

Solution 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;

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top