Page 1 of 1

Code changed in 7.03

Posted: Fri Feb 19, 2010 5:25 pm
by mfreeze
I am trying to implement the following code obtained from another forum post in CategoryGridPage4 but the line Int32 variantStockLevel = RFC_ProductHelper.IsProductVariantsInStock(product.ProductId);
no longer works.

I see that the inventory count for variants is no longer in producthelper. Looking at the class files, I believe it moved to commercebuilder.products.productvariant but I have not yet been successful at setting it correctly. Does anybody know what I should use to replace the producthelper reference in order to retrieve the variant stock level for the product?

The sole purpose of this code is to check the stock level of the product variants to determine whether to show the 'out of stock message'. If anybody knows a better way I would appreciate any help you could give.

Code: Select all

					int _ProductId = 0;
					_ProductId = catalogNode.CatalogNodeId;
                    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";
                            
                            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";
                            
                            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: Code changed in 7.03

Posted: Mon Feb 22, 2010 12:18 pm
by mazhar
Mary have a look at this thread.
viewtopic.php?f=42&t=10310

Re: Code changed in 7.03

Posted: Mon Feb 22, 2010 3:12 pm
by mfreeze
I got it to work using the following code. This was in categorygridpage4.ascx.cs. the code I added is after the comment.

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;
                    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";
                            
                            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)
                    {
                        int variantStockLevel = 0;
                        foreach (ProductVariant oVariant in product.Variants)
                        {
                            if (oVariant.InStock > variantStockLevel)
                            {
                                variantStockLevel = oVariant.InStock;
                                break;
                            }
                        }
                        if (variantStockLevel > 0)
                        {
                            string inStockformat = Token.Instance.Store.Settings.InventoryInStockMessage;
                            string inStockMessage = string.Format(inStockformat, product.InStock);
                            inStockMessage = "IN STOCK";
                            
                            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>"));
                        }
                    }
// end out of stock modifications