We had the need to hide the "Buy" button when the stock ran to zero. I didn't see anywhere to easily implement this so, so we coded it in ourselves.
It took a good amount of coding to get this working. More than I anticipated so I figured I'd share it here.
1) Modify the ZNODE_GetCategoryByID_XML
In the select statement after ",ZNodeProduct.CallForPricing" add:
,ZNodeProduct.QuantityOnHand
2) (Themes/.../ProductList.ascx.cs) Open ProductList.ascx.cs
In the respective places, Add the following to the Function: BindProductList
DataColumn col9 = new DataColumn("QuantityOnHand", System.Type.GetType("System.Int32"));
dt.Columns.Add(col9);
dr[8] = ((ZNodeProduct)(enumerator.Current)).QuantityOnHand;
3) (Themes/.../ProductList.ascx.cs) Create a new function:
//Added to disable buttons from showing when out of stock
public bool IsAvailable(object callForPricing, object invStock)
{
if (invStock == null) { return true; }
bool boolCallForPricing = bool.Parse(callForPricing.ToString());
int intInvStock = int.Parse(invStock.ToString());
if (intInvStock <= 0 || boolCallForPricing == true)
{
return false;
}
else
{
return true;
}
}
4) (Themes/.../ProductList.ascx) Edit the HTML to implement the new function
Change
<div><asp:ImageButton CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ProductID")%>'
ID="btnbuy" runat="server" ImageUrl='<%# BuyImage %>' OnClick="buy_Click"
Visible='<%# Check(Eval("CallForPricing")) %>'/></div>
To
<div><asp:ImageButton CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ProductID")%>'
ID="btnbuy" runat="server" ImageUrl='<%# BuyImage %>' OnClick="buy_Click"
Visible='<%# IsAvailable(Eval("CallForPricing"),Eval("QuantityOnHand"))
%>'/></div>