Hello,
Not sure if this is still required but with a small modification to a few files, I have managed to display the stock quantity & stock message on the item-box (_ProductBox.cshtml) section. (as well as search results)
1. ProductOverviewModel.cs
Change;
public string Name { get; set; }
public string ShortDescription { get; set; }
public string FullDescription { get; set; }
public string SeName { get; set; }
public string Sku { get; set; }
public ProductType ProductType { get; set; }
public bool MarkAsNew { get; set; }
//price
public ProductPriceModel ProductPrice { get; set; }
TO:
public string Name { get; set; }
public string ShortDescription { get; set; }
public string FullDescription { get; set; }
public string SeName { get; set; }
public string Sku { get; set; }
public ProductType ProductType { get; set; }
public bool MarkAsNew { get; set; }
public string StockAvailability { get; set; } // add this line
//price
public ProductPriceModel ProductPrice { get; set; }
2. ProductModelFactory.cs
Change:
var model = new ProductOverviewModel
{
Id = product.Id,
Name = product.GetLocalized(x => x.Name),
ShortDescription = product.GetLocalized(x => x.ShortDescription),
FullDescription = product.GetLocalized(x => x.FullDescription),
SeName = product.GetSeName(),
Sku = product.Sku,
ProductType = product.ProductType,
MarkAsNew = product.MarkAsNew &&
(!product.MarkAsNewStartDateTimeUtc.HasValue || product.MarkAsNewStartDateTimeUtc.Value < DateTime.UtcNow) &&
(!product.MarkAsNewEndDateTimeUtc.HasValue || product.MarkAsNewEndDateTimeUtc.Value > DateTime.UtcNow)
};
//price
TO:
var model = new ProductOverviewModel
{
Id = product.Id,
Name = product.GetLocalized(x => x.Name),
ShortDescription = product.GetLocalized(x => x.ShortDescription),
FullDescription = product.GetLocalized(x => x.FullDescription),
SeName = product.GetSeName(),
Sku = product.Sku,
ProductType = product.ProductType,
StockAvailability = product.FormatStockMessage("", _localizationService, _productAttributeParser, _dateRangeService), // add this line
MarkAsNew = product.MarkAsNew &&
(!product.MarkAsNewStartDateTimeUtc.HasValue || product.MarkAsNewStartDateTimeUtc.Value < DateTime.UtcNow) &&
(!product.MarkAsNewEndDateTimeUtc.HasValue || product.MarkAsNewEndDateTimeUtc.Value > DateTime.UtcNow)
};
//price
3. _ProductBox.cshtml
Change;
@if (EngineContext.Current.Resolve<CatalogSettings>().ShowSkuOnCatalogPages && !string.IsNullOrEmpty(Model.Sku))
{
<div class="sku">
@Model.Sku
</div>
}
TO:
@if (EngineContext.Current.Resolve<CatalogSettings>().ShowSkuOnCatalogPages && !string.IsNullOrEmpty(Model.Sku))
{
<div class="sku">
@Model.Sku - @Model.StockAvailability
</div>
}
Or you can simply add @Model.StockAvailability to anywhere you want the stock message to display.
This could be;
xx amount in stock like "22 in stock" or "Out of stock"
You can also style the message like below;
@if (!String.IsNullOrWhiteSpace(Model.StockAvailability) || Model.DisplayBackInStockSubscription)
{
@*Stock availability*@
var MyStockValue = Model.StockAvailability;
var StockStyle = "";
if (MyStockValue == "Out of stock")
{
StockStyle = "color:red !important;";
}
else
{
StockStyle = "color:green !important;";
}
<div class="availability">
@if (!String.IsNullOrWhiteSpace(Model.StockAvailability))
{
<div class="stock">
<span class="label">@T("Products.Availability"):</span>
<span class="value" id="stock-availability-value[email protected]" style="@Html.Raw(StockStyle)">@Model.StockAvailability</span>
</div>
}
@Html.Partial("_BackInStockSubscription", Model)
</div>
}
Hope this helps someone else.
Cheers.
V.