Developer forum

Forum » Development » Show quantity of units

Show quantity of units

Caro De Weze
Reply

Hi,

I want to show the unit of measure with its quantity for each product. So far I have managed to show whether a product is in stock or not, but when I use @unitOption.StockLevel to show the quantity, it returns 0. Here is my piece of code:

<div class="button-container">
@foreach (var unitOption in product.UnitOptions)
{
var selectedUnit = unitOption.Id == unitId ? "selected" : "";
 
<p data-value="@unitOption.Id" onclick="document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId.Replace(".", "_"))_@Model.ID').querySelector('.js-unit-id').value = this.getAttribute('data-value');
document.querySelector('#Unit_@(product.Id)_@product.VariantId.Replace(".", "_")').value = this.getAttribute('data-value');
swift.PageUpdater.Update(document.querySelector('#UnitSelectorForm_@(product.Id)_@(product.VariantId.Replace(".", "_"))_@Model.ID'))">
<span>@unitOption.Name</span>
<span>
@if (unitOption.StockLevel > 0 || unitOption.NeverOutOfStock)
{
<span class="small text-success">@unitOption.StockLevel @Translate("In stock")</span>
}
else
{
<span class="small text-danger">@Translate("Out of Stock")</span>
}
</span>
</p>
 
}
</div>

I use Swift and based it on the item type Swift_ProductAddToCart.cshtml. Can anyone help me further?

Caro


Replies

 

You must be logged in to post in the forum