Search code examples
razore-commercedotnetnuke

How to show file downloads Name and Size in hotcakes e-commerce?


I need help with Hotcakes e-commerce. I want to show the list of "File Downloads" in the Product details. Obviously only we want to show the name and size, so it can't be downloaded. Can you tell me how to get the list of files in the Model.LocalProduct (Razor) or what is the way to do that?

I see how can get this list using ViewBag.FileDownloads in ~/areas/account/views/shared/_OrderDownloads.cshtml but I should like to do something similar in the product details page.

I try to get the list from Model.LocalProduct.FileDownloads but seems this not exists in the Model...

I attached a screenshot of Product details page File Downloads in Page Details Hotcakes


Solution

  • Here's a snippet that you can use to list the download files associated to a product on the Product/Product Details view.

    First, add this using statement:

    @using Hotcakes.Commerce.Catalog;
    

    Next, put this Razor snippet near the top:

    @{
        var HccApp = HccAppHelper.InitHccApp();
        List<ProductFile> fileDownloads = HccApp.CatalogServices.ProductFiles.FindByProductId(Model.LocalProduct.Bvin);
    }
    

    Finally, put this wherever you want to see it in the view.

    @if (fileDownloads != null && fileDownloads.Count > 0)
    {
        <div class="my-class">
            <ul>
                @foreach (var file in fileDownloads)
                {
                    <li>@file.FileName </li>
                }
            </ul>
        </div>
    }