|
Home > Archive > Commerce Server Catalog > July 2006 > Sequencing Products/Categories
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Sequencing Products/Categories
|
|
| Dave Marini 2006-07-18, 7:22 am |
| I read in the documentation that ranking of products/categories can be done
through the CatalogItemsDataTable collection. The example shows a firehose
method of ranking products/categories. In our use case, I have the
CatalogItemsDataTable collection of categories bound to a grid. When the
user clicks the "reorder" button, I need to loop through the grid and
individually order the rows as the user has specified. The problem is that
to get the preceise category I want, I have to use the Select() method, which
is giving me back a datarow[]. I cast that to a
CatalogItemsDataTable.CatalogItem and set the rank, save, and nothing sticks.
How can one modify the rank of a particular category in a collection?
Thanks,
Dave
| |
| Reshmi Mangalore 2006-07-18, 7:22 am |
| Hi Dave,
Is this what you were looking for?
// Get the catalog
BaseCatalog bssc =
(BaseCatalog)catalogContext.GetCatalog("Adventure Works Catalog");
// Use Category Config if required. Here I am using for sorting by Rank
property.
CategoryConfiguration catConfig = new
CategoryConfiguration();
catConfig.ChildCategories.SearchOptions.SortDescending = true;
catConfig.ChildCategories.SearchOptions.SortProperty
= "Rank";
// This should fetch the results in descending order of Rank
Category rootCategory =
bssc.GetRootCategory(catConfig);
CatalogItemsDataSet dataset =
rootCategory.ChildCategories.DataSet;
DataTable table = dataset.CatalogItems;
// Set the rank of required row in teh dataset.
table.Rows[5][CatalogItemsDataSetSchema.Rank] = 80;
rootCategory.Save();
// Fetch the data set and look for the updated rank
rootCategory = bssc.GetRootCategory(catConfig);
Hope this helps.
Thanks!
Reshmi
---------------------------
This posting is provided "AS IS" with no warranties, and confers no
rights. You assume all risk for your use. © 2002 Microsoft Corporation.
All
rights reserved.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Get Secure! For more info visit http://www.microsoft.com/security.
Please reply to the newsgroups only
| |
| Dave Marini 2006-07-19, 7:47 am |
| Reshmi,
What you have provided is close, but what I need is to Get a particular
category, by name, and modify it's rank. The only problem with the code
snippet below is that it references an index of the CatalogItemsDataTable. I
will not know the index, only the CategoryName. I have tried the following
code and it didn't work:
public static void UpdateCategorySetRank(string catalogName, string
categoryName, int rank)
{
Category category = CatalogContext.GetCategory(catalogName,
categoryName);
if(category.ParentCategories.Count > 0)
{
StaticCategory parentCategory = (StaticCategory)
category.ParentCategories[0];
//doing it this way complains that "Rank" is get only, not set
parentCategory.ChildCategories[categoryName]["Rank"] = rank;
parentCategory.Save();
}
else
{
StaticCategory root =
(StaticCategory)Catalog.GetRootCategory(catalogName);
CatalogItemsDataSet categories = root.ChildCategories.DataSet;
//this works but when the root.save() is called, it doesn't
actually save!?!?
DataRow[] mycategory =
categories.CatalogItems.Select("CategoryName = '" + categoryName + "'");
((CatalogItemsDataSet.CatalogItem)mycategory[0]).Rank = 5;
root.Save();
}
}
I call this function for each row in my gridview, where I pass the catalog
name, the category name, and the rank that the user wants to set the category
to.
Thanks for your reply,
Dave
"Reshmi Mangalore" wrote:
> Hi Dave,
>
> Is this what you were looking for?
>
> // Get the catalog
> BaseCatalog bssc =
> (BaseCatalog)catalogContext.GetCatalog("Adventure Works Catalog");
>
> // Use Category Config if required. Here I am using for sorting by Rank
> property.
> CategoryConfiguration catConfig = new
> CategoryConfiguration();
>
> catConfig.ChildCategories.SearchOptions.SortDescending = true;
> catConfig.ChildCategories.SearchOptions.SortProperty
> = "Rank";
>
> // This should fetch the results in descending order of Rank
> Category rootCategory =
> bssc.GetRootCategory(catConfig);
> CatalogItemsDataSet dataset =
> rootCategory.ChildCategories.DataSet;
> DataTable table = dataset.CatalogItems;
>
> // Set the rank of required row in teh dataset.
> table.Rows[5][CatalogItemsDataSetSchema.Rank] = 80;
> rootCategory.Save();
>
> // Fetch the data set and look for the updated rank
> rootCategory = bssc.GetRootCategory(catConfig);
>
> Hope this helps.
>
> Thanks!
> Reshmi
> ---------------------------
> This posting is provided "AS IS" with no warranties, and confers no
> rights. You assume all risk for your use. © 2002 Microsoft Corporation.
> All
> rights reserved.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> Get Secure! For more info visit http://www.microsoft.com/security.
> Please reply to the newsgroups only
>
| |
| Reshmi Mangalore 2006-07-19, 7:47 am |
| Hi Dave,
You can put a Select (Filter) to get the exact CategoryName
For Example: If you want to get CategoryName = "Boots" in "Adventure Works
Catalog"
CatalogItemsDataSet dataset =
rootCategory.ChildCategories.DataSet;
DataTable table = dataset.CatalogItems;
// Set the filter to get the exact CategoryName
DataRow []dr= table.Select("CategoryName = 'Boots'");
dr[0][CatalogItemsDataSetSchema.Rank] = 55;
rootCategory.Save();
Thanks,
Reshmi
------------
This posting is provided "AS IS" with no warranties, and confers no
rights. You assume all risk for your use. © 2002 Microsoft Corporation.
All
rights reserved.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
| |
| Dave Marini 2006-07-21, 1:20 am |
| Reshmi,
This code doesn't throw exceptions and everything appears to work, but I
don't think the new rank is saving, because when the grid gets rebound to the
CatalogItemsDataTable for the categories again after the update, ALL
categories still have a rank of 0. Do I have to enable category sequencing?
it should be mentioned that I'm using CS2007 RC1, not sure if maybe there is
a known problem with this functionality in that build.
Thanks,
Dave
"Reshmi Mangalore" wrote:
> Hi Dave,
>
> You can put a Select (Filter) to get the exact CategoryName
>
> For Example: If you want to get CategoryName = "Boots" in "Adventure Works
> Catalog"
>
> CatalogItemsDataSet dataset =
> rootCategory.ChildCategories.DataSet;
> DataTable table = dataset.CatalogItems;
> // Set the filter to get the exact CategoryName
> DataRow []dr= table.Select("CategoryName = 'Boots'");
> dr[0][CatalogItemsDataSetSchema.Rank] = 55;
> rootCategory.Save();
>
> Thanks,
> Reshmi
>
> ------------
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights. You assume all risk for your use. © 2002 Microsoft Corporation.
> All
> rights reserved.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright
| |
| Dave Marini 2006-07-21, 1:20 am |
| As an update to this, I am finding that the Category Search I'm doing always
brings back Rank column with value of 0. However, in the table
<CATALOGNAME>_CatalogHierarchy the Rank column is ordered as I made it. Any
idea why the Rank property always returns 0 in my Category Search?? I have
Rank as the SortProperty, so I'm kind of out of ideas at this point. Here's
the query that gets my categories that I want to see rank for:
Category rootCategory = null;
CategoryCollection allCategories = null;
//Get the Catalog
ProductCatalog pc = Catalog.GetCatalog(catalogName);
//Create a new CategoryConfiguration object
CategoryConfiguration categoryConfig = new
CategoryConfiguration();
//Enable loading ChildCategories
categoryConfig.LoadChildCategories = true;
//Don't Recurse on each child category to get the list of
categories in the catalog
categoryConfig.RecursiveChildCategories = false;
//Provide a SQLWhereClause to only return cateogries that aren't
deleted
categoryConfig.ChildCategories.SqlWhereClause = "IsDeleted = 0";
categoryConfig.ChildCategories.SearchOptions.SortProperty =
"Rank";
//Get the RootCategory using the CategoryConfiguration object
rootCategory = pc.GetRootCategory(categoryConfig);
//Get all the cateogories in the catalog.
allCategories = rootCategory.ChildCategories;
Thanks,
Dave
"Dave Marini" wrote:
[vbcol=seagreen]
> Reshmi,
>
> This code doesn't throw exceptions and everything appears to work, but I
> don't think the new rank is saving, because when the grid gets rebound to the
> CatalogItemsDataTable for the categories again after the update, ALL
> categories still have a rank of 0. Do I have to enable category sequencing?
> it should be mentioned that I'm using CS2007 RC1, not sure if maybe there is
> a known problem with this functionality in that build.
>
> Thanks,
>
> Dave
>
> "Reshmi Mangalore" wrote:
>
|
|
|
|
|