Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 2 of 2

Thread: get category name & id from orderconfirmation.aspx.cs

  1. #1
    coroin is offline Junior Member
    Join Date
    Aug 2012
    Posts
    2

    Default get category name & id from orderconfirmation.aspx.cs

    greetings,

    can someone point me to the documentation or a code sample demonstrating how to retrieve the CategoryName and CategoryID from a particular ProductID?

    the following code is close, but GetCategoryName() doesn't work:

    Code:
            protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
            {
    		int CustomerID = ThisCustomer.CustomerID;
    		int OrderNumber = CommonLogic.QueryStringUSInt("OrderNumber");
    		Order ord = new Order(OrderNumber, ThisCustomer.LocaleSetting);
    		...
    		foreach (CartItem ci in ord.CartItems)
                    {
    			...
    			string catName = GetCategoryName(ci.m_ProductID);
    			//long catId = GetCategoryId(ci.m_ProductID);
    			...
                    }
                    ...
            }
    thanks in advance.
    cheers,
    -e

  2. #2
    coroin is offline Junior Member
    Join Date
    Aug 2012
    Posts
    2

    Default [solved]

    solved ... just in case anyone else has need, here is my code
    Code:
    	foreach (CartItem ci in ord.CartItems)
    	{
    		// local variables
    		int categoryId = AppLogic.GetFirstProductEntityID(AppLogic.LookupHelper("Category"), ci.m_ProductID, false);
    		string categoryName = AppLogic.LookupHelper(base.EntityHelpers, "Category").GetEntityName(categoryId, ThisCustomer.LocaleSetting);
    		categoryName = categoryName.Replace("'", "");
    		string productName = ci.m_ProductName.Replace("'", "");
    		// build strings
    		categoryIds = categoryIds == string.Empty ? categoryId.ToString() : string.Concat(categoryIds, ", ", categoryId.ToString());
    		categoryNames = categoryNames == string.Empty ? categoryName : string.Concat(categoryNames, ", ", categoryName);
    		productIds = productIds == string.Empty ? ci.m_ProductID.ToString() : string.Concat(productIds, ", ", ci.m_ProductID.ToString());
    		productNames = productNames == string.Empty ? productName : string.Concat(productNames, ", ", productName);
    	}
    this is used in the ordercheckout.aspx.cs to generate comma-separated list of categories and products (eg. to implement order tracking via third party)

    this code needs to be optimized so it strips out illegal characters that could throw javascript errors, etc., but hopefully this will be of use to someone.

    cheers,
    -e
    Last edited by coroin; 08-28-2012 at 09:17 AM. Reason: revised code