Page 1 of 1

Show in stock/out of stock at category level

Posted: Mon Jan 11, 2016 9:31 am
by compunerdy
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

Posted: Tue Feb 02, 2016 1:32 am
by nadeem
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

Code: Select all

<asp:Panel ID="InventoryStatusPanel" runat="server" CssClass="inventoryStatus">
     <asp:Label ID="productInventoryStatus" runat="server"></asp:Label>
</asp:Panel>
- Now open Website/ConLib/Utility/ProductItemDisplay.ascx.cs and add a boolean property with default value 'false' in ProductItemDisplay constructor

Code: Select all

public bool ShowInventoryStatus { get; set; }
- Now add the inventory status checking logic inside Page_PreRender method just below the following line of code

Code: Select all

// SHOW ADD TO CART
ActionsPanel.Visible = ShowAddToCart;
Something like

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
}
- 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:

Code: Select all

<uc1:ProductItemDisplay ID="ProductItemDisplay1" runat="server" Item='<%# Container.DataItem %>' ShowManufacturer="true" ShowRating="true" ShowAddToCart="true" ShowInventoryStatus="true" />
Hope this will helps.

Re: Show in stock/out of stock at category level

Posted: Wed Feb 10, 2016 1:44 pm
by compunerdy
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

Posted: Thu Feb 11, 2016 5:33 am
by nadeem
Here is the code to show instock/outofstock messages.

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);
            }
        }
    }
}
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.

Re: Show in stock/out of stock at category level

Posted: Thu Feb 11, 2016 8:29 am
by compunerdy
THANK YOU!!! Works great

Re: Show in stock/out of stock at category level

Posted: Thu Feb 11, 2016 11:08 am
by compunerdy
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

Posted: Fri Feb 12, 2016 5:24 am
by nadeem
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.
Can you confirm if 'Allow Backorders' option isn't enabled for kit products at edit product page?

Re: Show in stock/out of stock at category level

Posted: Fri Feb 12, 2016 6:33 am
by compunerdy
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.

Re: Show in stock/out of stock at category level

Posted: Mon Feb 15, 2016 7:33 am
by compunerdy
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

Posted: Tue Feb 16, 2016 12:53 am
by nadeem
You can simply update the following check to not show the stock messages for kit items:

Code: Select all

if (Item.InventoryMode == InventoryMode.Product)
To

Code: Select all

if (Item.InventoryMode == InventoryMode.Product && !Item.IsKit && Item.KitStatus != KitStatus.Master)