Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Software > Commerce Server Catalog > Retrieve Compet...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 718 of 763
Post > Topic >>

Retrieve Competitor parts and related parts using one API call

by =?Utf-8?B?TWFuaXNo?= <Manish@[EMAIL PROTECTED] > Nov 17, 2006 at 07:57 AM

Is there a way using API call, I can retrieve Competitor parts and related 
parts using one API call? Currently we retrieve the Competitor parts and
then 
loop through and make a seperate call per part to retrieve the related 
products. This means if we have 1000 competitor parts, we will be making
1000 
calls to retrieve the related parts.

Here is the code:
/// <summary>
/// To retrieve the result for Competitor Part Number Search.
/// </summary>
/// <param name="Region">Region</param>
/// <param name="SearchPhrase">Search Phrase</param>        
/// <returns></returns>
public DataTable GetCompetitorPartsSearchResult(string Region, string 
SearchPhrase)
{
    DataView dv = null;
    DataTable dtTemp = null;
    DataTable dtParts = null;
    DataTable dtCompetitorParts = new DataTable();
    dtCompetitorParts.Columns.Add("ProductID");
    dtCompetitorParts.Columns.Add("Part Number");
    dtCompetitorParts.Columns.Add("Description");
    dtCompetitorParts.Columns.Add("Brand");
    Product competitorPart = null;
    CatalogItemsDataSet csPart = null;
    try
    {
        string searchValue = SearchPhrase.Trim();
        //To remove special characters before searching competitor parts.
        searchValue = searchValue.Replace("~", "").Replace("`", 
"").Replace("!", "").Replace("@[EMAIL PROTECTED]
", "").Replace("#", "").Replace("$", 
"").Replace("%", "").Replace("^", "").Replace("&", "").Replace("*", 
"").Replace(" (", "").Replace(")", "").Replace("_", "").Replace("-", 
"").Replace("+", "").Replace("=", "").Replace("{", "").Replace(" [", 
"").Replace("}", "").Replace("]", "").Replace("|", "").Replace(":", 
"").Replace(";", "").Replace("'", "").Replace("<", "").Replace(">", 
"").Replace(",", "").Replace(".", "").Replace("?", "").Replace("/", 
"").Replace(@[EMAIL PROTECTED]
"\", "");
        if (catalogType[0] == 0) throw new CommerceException(Division + 
"_CompetitorParts is not added in CatalgoSet.");
        if (catalogType[3] == 0) throw new CommerceException(Division + 
"_ProductFamily is not added in CatalgoSet.");
        //To retrieve competitor parts based on the given search criteria 
and region.
        if(catalogType[0]==1)
            dtTemp = ExecuteSearch(vcCompetitorParts.Name, 
"BaseCatalogName='" + CompetitorPartBaseCatalog + "' and Region='" +
Region + 
"' and [Part Number] like '%" + searchValue + "%'", "ProductID,Part 
Number,Description,Competitor,DisplayName", 
CatalogClassTypes.ProductVariantClass);
        else if (catalogType[0] == 2)
            dtTemp = ExecuteSearch(bcCompetitorParts.Name, 
"BaseCatalogName='" + CompetitorPartBaseCatalog + "' and Region='" +
Region + 
"' and [Part Number] like '%" + searchValue + "%'", "ProductID,Part 
Number,Description,Competitor,DisplayName", 
CatalogClassTypes.ProductVariantClass);
        if (dtTemp != null)
        {
            dv = new DataView(dtTemp);
            dtTemp = dv.ToTable(true, new string[] { "ProductID", "Part 
Number", "Description", "Competitor", "DisplayName" });
            //To check whether each competitor part from the resultset is 
having any product relation****p with Delphi Parts, i.e direct replcaement
or 
indirect replacement for Delphi Parts.
            foreach (DataRow drTemp in dtTemp.Rows)
            {
                StringBuilder partsList = new StringBuilder(string.Empty);
                if (catalogType[0] == 1)
                    competitorPart = 
catalogContext.CatalogContext.GetProduct(vcCompetitorParts.Name, 
drTemp["ProductID"].ToString(), ActiveLanguage);
                else if (catalogType[0] == 2)
                    competitorPart = 
catalogContext.CatalogContext.GetProduct(bcCompetitorParts.Name, 
drTemp["ProductID"].ToString(), ActiveLanguage);
                csPart = competitorPart.Information;
                DataRow drPart = csPart.Tables[0].Rows[0];
                //Checking the Product Relation****p of a competitor part.
                foreach (CatalogRelation****psDataSet.CatalogRelation****p 
crPart in competitorPart.RelatedProducts.CatalogRelation****ps)
                {
                    if ((crPart.Relation****pName.ToUpper() == 
DirectRelation) || (crPart.Relation****pName.ToUpper() ==
IndirectRelation))
                    {
                        partsList.Append("'" + crPart.TargetProductId +
"',");
                    }
                }
                //To retrieve all the Delphi Parts having product 
relation****p with Competitor Parts retrived based on the search criteria. 
   
                                           
                if (partsList.ToString().Length > 0)
                {
                    StringBuilder partsDesc = new
StringBuilder(string.Empty);
                    string parts = partsList.ToString();
                    parts = parts.Substring(0, parts.Length - 1);
                    if (catalogType[3] == 1)
                        dtParts = ExecuteSearch(vcDelphiParts.Name, 
"[BaseCatalogName]='" + PartBaseCatalog + "' and Region='" + Region + "'
and 
[Active Status]='True' and Upper([Part Status]) in ('" + 
ActivePartStatus.Replace(",", "','") + "') and [ProductId] in (" + parts +

")", "ProductId,Description", CatalogClassTypes.ProductVariantClass);
                    else if (catalogType[3] == 2)
                        dtParts = ExecuteSearch(bcDelphiParts.Name, 
"[BaseCatalogName]='" + PartBaseCatalog + "' and Region='" + Region + "'
and 
[Active Status]='True' and Upper([Part Status]) in ('" + 
ActivePartStatus.Replace(",", "','") + "') and [ProductId] in (" + parts +

")", "ProductId,Description", CatalogClassTypes.ProductVariantClass);
                    if (dtParts != null)
                    {
                        DataView dvParts = dtParts.DefaultView;
                        dtParts = dvParts.ToTable(true, new string[] { 
"ProductId", "Description" });
                        //Description will be concatenated with comma if 
more competitor partn is having Product relation****p with more than one 
Delphi Part.
                        foreach (DataRow drParts in dtParts.Rows)
                            
partsDesc.Append(drParts["Description"].ToString() + ", ");
                    }
                    //Final ouptut will be a datatable containing
ProductID, 
Part Number, Brand of Competitor Parts and Description of Delphi Parts.
                    DataRow dr = dtCompetitorParts.NewRow();
                    dr["ProductID"] = drTemp["ProductID"];
                    dr["Part Number"] = drTemp["DisplayName"];
                    string desc = partsDesc.ToString().Trim();
                    if (desc.Trim().Length > 0) desc = desc.Substring(0, 
desc.Length - 1);
                    dr["Description"] = desc;
                    dr["Brand"] = drTemp["Competitor"];
                    dtCompetitorParts.Rows.Add(dr);
                }
            }
        }
        //To display the records in descending order.
        if (dtCompetitorParts != null)
        {
            DataView dvParts = dtCompetitorParts.DefaultView;
            dvParts.Sort = "Part Number DESC";
            return dvParts.ToTable(true, new string[] { "ProductID", "Part

Number", "Description", "Brand" });                    
        }
        return dtCompetitorParts;
    }
    catch (EntityDoesNotExistException ce)
    {
        throw new 
Delphi.ApplicationBlocks.Exceptions.DatabaseException(ce.Message, ce);
    }
    catch (CatalogException ce)
    {
        throw new 
Delphi.ApplicationBlocks.Exceptions.DatabaseException(ce.Message, ce);
    }
    catch (CommerceException ce)
    {
        throw new 
Delphi.ApplicationBlocks.Exceptions.DatabaseException(ce.Message, ce);
    }
    finally
    {
        if(dv!=null) dv.Dispose();
        if(dtTemp!=null) dtTemp.Dispose();
        if(dtCompetitorParts!=null) dtCompetitorParts.Dispose();
        if (csPart != null) csPart.Dispose();
    }
}
 




 1 Posts in Topic:
Retrieve Competitor parts and related parts using one API call
=?Utf-8?B?TWFuaXNo?= <  2006-11-17 07:57:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Nov 23 6:37:20 CST 2008.