Show in stock/out of stock at category level

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Show in stock/out of stock at category level

Post by compunerdy » Mon Jan 11, 2016 9:31 am

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.

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

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

Post by nadeem » Tue Feb 02, 2016 1:32 am

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.

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

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

Post by compunerdy » Wed Feb 10, 2016 1:44 pm

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
}

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

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

Post by nadeem » Thu Feb 11, 2016 5:33 am

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.

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

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

Post by compunerdy » Thu Feb 11, 2016 8:29 am

THANK YOU!!! Works great

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

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

Post by compunerdy » Thu Feb 11, 2016 11:08 am

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.

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

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

Post by nadeem » Fri Feb 12, 2016 5:24 am

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?

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

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

Post by compunerdy » Fri Feb 12, 2016 6:33 am

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.

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

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

Post by compunerdy » Mon Feb 15, 2016 7:33 am

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

    }
}

nadeem
Captain (CAPT)
Captain (CAPT)
Posts: 258
Joined: Tue Jul 31, 2012 7:23 pm

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

Post by nadeem » Tue Feb 16, 2016 12:53 am

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)

Post Reply