display product availability in _ProductBox.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 years ago
Hi, has anyone got this working in version 4.40
2 years ago
This is code for v4.4
Edit _ProductBox.cshtml
Depending on if you are using a Theme then edit the respective file
Presentation\Nop.Web\Views\Shared\_ProductBox.cshtml
or
Presentation\Nop.Web\Themes\Motion\Views\Shared\_ProductBox.cshtml
Up the top add

@using Nop.Services.Catalog;
@{
    var productService = EngineContext.Current.Resolve<IProductService>();
    var productQuantity = (await productService.GetProductByIdAsync(Model.Id)).StockQuantity;
}

In the markup - for example change
        
        @if (catalogSettings.ShowSkuOnCatalogPages && !string.IsNullOrEmpty(Model.Sku))
        {
            <div class="sku">
                @Model.Sku
            </div>
        }

to
        
        @if (productQuantity < 1)
        {
            <span class="out-of-stock">@T("YourMessage.OutofStock")</span>
        }
        else
        {
            <span class="label">@T("pdfproductcatalog.stockquantity"):</span>
            <span class="value" id="stock-availability-value[email protected]">@productQuantity</span>
        }
2 years ago
Sorry edit timed out...

In the markup - for example change
        
        @if (catalogSettings.ShowSkuOnCatalogPages && !string.IsNullOrEmpty(Model.Sku))
        {
            <div class="sku">
                @Model.Sku
            </div>
        }

to
  
        @if (catalogSettings.ShowSkuOnCatalogPages && !string.IsNullOrEmpty(Model.Sku))
        {
            <div class="sku">
                @Model.Sku
            </div>
        }
        @if (productQuantity < 1)
        {
            <span class="out-of-stock">@T("YourMessage.OutofStock")</span>
        }
        else
        {
            <span class="label">@T("pdfproductcatalog.stockquantity"):</span>
            <span class="value" id="stock-availability-value[email protected]">@productQuantity</span>
        }
[/quote]
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.