Show in stock/out of stock at category level
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Show in stock/out of stock at category level
I found quite a few posts about this for AC7 but none for Gold yet. Does anyone have some code to show this on the category grid page? Having the option in the drop down to only show in stock would be a bonus.
Re: Show in stock/out of stock at category level
Let me give you some direction to achieve your desired goal:
- Open Website/ConLib/Utility/ProductItemDisplay.ascx and add a label to display inventory something like
- Now open Website/ConLib/Utility/ProductItemDisplay.ascx.cs and add a boolean property with default value 'false' in ProductItemDisplay constructor
- Now add the inventory status checking logic inside Page_PreRender method just below the following line of code
Something like
- Finally, open your desired category display page and set the ProductItemDisplay control parameter 'ShowInventoryStatus' to true
For example, update the ProductItemDisplay inside 'Website/ConLib/CategoryGridPage.ascx' like this:
Hope this will helps.
- Open Website/ConLib/Utility/ProductItemDisplay.ascx and add a label to display inventory something like
Code: Select all
<asp:Panel ID="InventoryStatusPanel" runat="server" CssClass="inventoryStatus">
<asp:Label ID="productInventoryStatus" runat="server"></asp:Label>
</asp:Panel>
Code: Select all
public bool ShowInventoryStatus { get; set; }
Code: Select all
// SHOW ADD TO CART
ActionsPanel.Visible = ShowAddToCart;
Code: Select all
InventoryStatusPanel.Visible = ShowInventoryStatus;
if (ShowInventoryStatus)
{
// YOUR INVENTORY CHECKING LOGIC FOR EACH ITEM GOES HERE
// e.g. Check stock status using inventory manager CheckStock method
// and set the in stock/out of stock values to productInventoryStatus label for display
}
For example, update the ProductItemDisplay inside 'Website/ConLib/CategoryGridPage.ascx' like this:
Code: Select all
<uc1:ProductItemDisplay ID="ProductItemDisplay1" runat="server" Item='<%# Container.DataItem %>' ShowManufacturer="true" ShowRating="true" ShowAddToCart="true" ShowInventoryStatus="true" />
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Show in stock/out of stock at category level
Thanks.. can you provide some sample code for this part?
Code: Select all
InventoryStatusPanel.Visible = ShowInventoryStatus;
if (ShowInventoryStatus)
{
// YOUR INVENTORY CHECKING LOGIC FOR EACH ITEM GOES HERE
// e.g. Check stock status using inventory manager CheckStock method
// and set the in stock/out of stock values to productInventoryStatus label for display
}
Re: Show in stock/out of stock at category level
Here is the code to show instock/outofstock messages.
Please note that I have not considered variants. If you want to display stock level message for variants, you have to update above code for variants as well.
Code: Select all
if (ShowInventoryStatus)
{
CommerceBuilder.Services.IInventoryManager inventoryManager = AbleContext.Resolve<CommerceBuilder.Services.IInventoryManager>();
InventoryManagerData inv = inventoryManager.CheckStock(Item.Id);
CommerceBuilder.Stores.Store store = AbleContext.Current.Store;
if (store.Settings.EnableInventory && store.Settings.InventoryDisplayDetails && (Item.InventoryMode != InventoryMode.None) && (!Item.AllowBackorder))
{
if (Item.InventoryMode == InventoryMode.Product)
{
if (inv.InStock > 0)
{
string inStockformat = store.Settings.InventoryInStockMessage;
productInventoryStatus.Text = string.Format(inStockformat, inv.InStock);
}
else
{
string outOfStockformat = store.Settings.InventoryOutOfStockMessage;
productInventoryStatus.Text = string.Format(outOfStockformat, inv.InStock);
}
}
}
}
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Show in stock/out of stock at category level
THANK YOU!!! Works great
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Show in stock/out of stock at category level
Did notice a problem. Variants do not show in stock or out of stock as you had mentioned which is fine but kit parent items are showing in stock when they are out of stock on the product page.
Re: Show in stock/out of stock at category level
Can you confirm if 'Allow Backorders' option isn't enabled for kit products at edit product page?Did notice a problem. Variants do not show in stock or out of stock as you had mentioned which is fine but kit parent items are showing in stock when they are out of stock on the product page.
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Show in stock/out of stock at category level
It is not enabled. It shows in stock at the category level but out of stock at the product level. You can see this behavior here.. http://www.thecustomsabershop.com/Sound-C51.aspx
Another thing to add would be to say stock available on items that do not have inventory turned on.
Another thing to add would be to say stock available on items that do not have inventory turned on.
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Show in stock/out of stock at category level
Using this I got it to show none inventory items as in stock. I am still having the issue with kit items. They show up as InventoryMode.Product as they have a inventory value set to a number like 9999999 so the kit inventory works correctly based off the sub items. How would I change the code to check and see if the product is a kit parent item and if so do not display a stock message or better yet properly check to see if the kit is in stock?
Code: Select all
if (ShowInventoryStatus)
{
CommerceBuilder.Services.IInventoryManager inventoryManager = AbleContext.Resolve<CommerceBuilder.Services.IInventoryManager>();
InventoryManagerData inv = inventoryManager.CheckStock(Item.Id);
CommerceBuilder.Stores.Store store = AbleContext.Current.Store;
if (store.Settings.EnableInventory && store.Settings.InventoryDisplayDetails && (!Item.AllowBackorder))
{
if (Item.InventoryMode == InventoryMode.Product)
{
if (inv.InStock > 0)
{
string inStockformat = store.Settings.InventoryInStockMessage;
productInventoryStatus.Text = string.Format(inStockformat, inv.InStock);
}
else
{
string outOfStockformat = store.Settings.InventoryOutOfStockMessage;
productInventoryStatus.Text = string.Format(outOfStockformat, inv.InStock);
}
}
else if (Item.InventoryMode == InventoryMode.None)
{
string inStockformat = store.Settings.InventoryInStockMessage;
productInventoryStatus.Text = string.Format(inStockformat, inv.InStock);
}
}
}
Re: Show in stock/out of stock at category level
You can simply update the following check to not show the stock messages for kit items:
To
Code: Select all
if (Item.InventoryMode == InventoryMode.Product)
Code: Select all
if (Item.InventoryMode == InventoryMode.Product && !Item.IsKit && Item.KitStatus != KitStatus.Master)