Page 1 of 1

Category Grid Page - In Stock

Posted: Wed Apr 08, 2009 7:38 am
by niall08
I'm trying to add an "in stock / out of stock" element to the category grid display - the "product.instock" property is used (and works!) when the product is tracked by the product - but when tracked by the variants, it always displays an "out of stock" warning.. any ideas how I can test for whether the variants are in stock or not, if the Inventory Mode is 2??

Re: Category Grid Page - In Stock

Posted: Wed Apr 08, 2009 7:54 am
by niall08
Right..

The product has to be saved with an instock amount.. once saved, the tracking can be set to the variants for inventory management - after this, the product will show as being "in stock"..

SO -
The product has to be entered with it's own stock amount first??
Then the variants created with their stock levels - and then it will appear as being in stock..

Is that right?? And if it is, can the product stock level (not the variants) be controlled from the Inventory page??

Re: Category Grid Page - In Stock

Posted: Thu Apr 09, 2009 2:26 am
by niall08
Has anyone attempted to show "In Stock" and "Out of Stock" messages on the category display pages?

I can't get it to work when the products have variants attached, so I've just limited it to products that are tracked by the product (rather than the variant) - but handling the tracking by variants would be ideal.. Any ideas?

Here's what I have so far..

Code: Select all

if (product.InventoryModeId == 1)
 {
if (product.InStock > 0)
{
string inStockformat = Token.Instance.Store.Settings.InventoryInStockMessage;
string inStockMessage = string.Format(inStockformat, product.InStock);
inStockMessage = "IN STOCK";
if (product.InStock > 10)
{
inStockMessage += " [More than 10]";
}
itemTemplate2.Controls.Add(new LiteralControl("<p>" + catalogNode.Summary + "</p>"));
itemTemplate2.Controls.Add(new LiteralControl("<p>" + inStockMessage + "</p>"));
}
else
{
string outOfStockformat = Token.Instance.Store.Settings.InventoryOutOfStockMessage;
string outOfStockMessage = string.Format(outOfStockformat, product.InStock);
itemTemplate2.Controls.Add(new LiteralControl("<p>" + catalogNode.Summary + "</p>"));
itemTemplate2.Controls.Add(new LiteralControl("<p>" + outOfStockMessage + "</p>"));
}
}
else
{
itemTemplate2.Controls.Add(new LiteralControl("<p>" + catalogNode.Summary + "</p>"));
}

Re: Category Grid Page - In Stock

Posted: Thu Apr 09, 2009 5:31 am
by niall08
I got there in the end!

Created my own class with a function that queries the DB based on Product ID, summing the variant instock amounts for that product, and returning it to the category grid page:

Code: Select all

if (AlwaysConvert.ToInt(product.InventoryModeId) == 1)
                    {
                        if (product.InStock > 0)
                        {
                            string inStockformat = Token.Instance.Store.Settings.InventoryInStockMessage;
                            string inStockMessage = string.Format(inStockformat, product.InStock);
                            inStockMessage = "IN STOCK";
                            if (product.InStock > 10)
                            {
                                inStockMessage += " [More than 10]";
                            }
                            itemTemplate1.Controls.Add(new LiteralControl("<p>" + inStockMessage + "</p>"));
                        }
                        else
                        {
                            string outOfStockformat = Token.Instance.Store.Settings.InventoryOutOfStockMessage;
                            string outOfStockMessage = string.Format(outOfStockformat, product.InStock);
                            itemTemplate1.Controls.Add(new LiteralControl("<p>" + outOfStockMessage + "</p>"));
                        }
                    }
                    else if (AlwaysConvert.ToInt(product.InventoryModeId) == 2)
                    {
                        Int32 variantStockLevel = RFC_ProductHelper.IsProductVariantsInStock(product.ProductId);
                        if (variantStockLevel > 0)
                        {
                            string inStockformat = Token.Instance.Store.Settings.InventoryInStockMessage;
                            string inStockMessage = string.Format(inStockformat, product.InStock);
                            inStockMessage = "IN STOCK";
                            if (variantStockLevel > 10)
                            {
                                inStockMessage += " [More than 10]";
                            }
                            itemTemplate1.Controls.Add(new LiteralControl("<p>" + inStockMessage + "</p>"));
                        }
                        else
                        {
                            string outOfStockformat = Token.Instance.Store.Settings.InventoryOutOfStockMessage;
                            string outOfStockMessage = string.Format(outOfStockformat, product.InStock);
                            itemTemplate1.Controls.Add(new LiteralControl("<p>" + outOfStockMessage + "</p>"));
                        }
                    }

Re: Category Grid Page - In Stock

Posted: Thu Feb 18, 2010 2:58 pm
by mfreeze
Which category page are you using? I need to do the same thing for categorygridpage4. I have the original code in the page now but my customer just started using variants and those products are showing as out of stock.

Where did you place the code in the categorygridpagex.aspx.cs? The code I am using now is right after the //output retail price

Code: Select all

                //OUTPUT RETAIL PRICE IF AVAILABLE
                if (catalogNode.CatalogNodeType == CatalogNodeType.Product)
                {
                    Product product = (Product)catalogNode.ChildObject;
// Mary added the following to show out of stock on category page 					
					int _ProductId = 0;
					_ProductId = catalogNode.CatalogNodeId;
					 InventoryManagerData inv = InventoryManager.CheckStock(_ProductId);
        if (inv.InStock <= 0)
        
        {
            string outOfStockformat = Token.Instance.Store.Settings.InventoryOutOfStockMessage;
            string outOfStockMessage = string.Format(outOfStockformat, inv.InStock);
		
            itemTemplate1.Controls.Add(new LiteralControl("<br>" + outOfStockMessage + "<br>"));
        }
// end out of stock modifications