Get price from Umbraco commerce

Hi

I have created a document type which includes a field called stock.

I need to display this price in my view. Do I use the normal way of showing the price like I would do with any other field in the document type or is there a preferred way to do this with Umbraco commerce?

I’m confused a bit. Are you asking about displaying the stock field or the price field?

Anyway, for the stock field, you can display it just like a normal umbraco property. It’s just a number property.

For the price field, you can call CalculatePriceAsync method like showing in the Umbraco Commerce Demo Store repository.

<p>@(await product.CalculatePriceAsync().FormattedAsync())</p>

Hiya

Sorry should have said price and not stock.

I have a document type called Item with a field called Price using the Umbraco commerce price as the data type.

I need to display the price listed in this field. I tried the code you posted but I don’t have a product document type. I changed this over to Item (my document type) but this didn’t have the available code you posted. I must be missing something?

My bad, that method is an extension method which is defined in PublishedContentExtensions-Product.cs

IProductComp is just a IPublishedContent so you can modify it to match your document type.

I feel like you’re not familiar with the basic setup of Umbraco Commerce, maybe Adrian’s talk at the Codegarden 2025 will be useful.

Just curious, don’t Umbraco have a getting started tutorial or training course for Commerce at the moment?

You could take a look at

This gives you the store with some ideas of how to go about setting your site up.

Theres some How to guides found at Overview | Umbraco Commerce which have samples of how price is retrieved.

I dont think they have any at present but im sure someone did request this recently too.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.