I've looked all over for a thread that covers this, but haven't found one.
Basically, I've got 1 database that covers 2 sites. The first one is the primary site, and it has a number of cobrand sites.
The second site is has a specialized product list that includes everything from the first site, but adds a number of items only available on the second site. I inherited maintenance of this site, so I'm not the one who made these choices.
In order to accommodate this, they used hidden items for all of the 2nd site specific items. I'm not sure why, but it's what I'm stuck with.
The problem I have is that on an admin screen orders set for review are displayed, and a dropdown list is used to show products of the same category and their variants so that an admin can correct an erroneous order. (The site has all in-house customers, not public facing). The problem is that when one of the hidden items is the one that's ordered, the LINQ query that gets the category siblings and variants to populate the list is not returning the hidden item. Thus, when the control databinds and tries to select the item that was actually ordered, it's not on the list. I trap the error, but then it appears to the customer that the order is changing.
Is there a way to force hidden items to be returned, or will I have to write a custom search?
Here's the LINQ statement:
protected IEnumerable<ProductOptionContainer> GetSiblings(OrderItem orderItem)
{
return orderItem.Product.Categories
.Select(catId => CategoryDataSource.Load(catId))
.SelectMany(cat => cat.CatalogNodes.Cast<CatalogNode>())
.Where(node => node.CatalogNodeType == CatalogNodeType.Product)
.Select(node => node.ChildObject as Product)
.Distinct()
.SelectMany(product => product.ProductOptions.Cast<ProductOption>())
.Select(po => po.Option)
.SelectMany(option => option.Choices.Cast<OptionChoice>())
.Select(choice => new ProductOptionContainer(choice));
}
Is there a better way I can do this to get the hidden items? (SQL Query, or an API method?)
Thanks,
Jon Upchurch
LyntonWeb
Including ghosted (hidden) items in API calls
Re: Including ghosted (hidden) items in API calls
Use CatalogNodeDataSource.LoadForCategory method and pass false as its second parameter. This will load all items with any type of visibility. Then iterate over items and filter out the ones either public or hidden. It could be something like below
Code: Select all
CatalogNodeCollection catalogNodes = CatalogDataSource.LoadForCategory(categoryid, false);
ProductCollection products = new ProductCollection();
foreach (CatalogNode catalogNode in catalogNodes)
if (catalogNode.CatalogNodeType == CatalogNodeType.Product && (catalogNode.ChildObject.Visibility == CatalogVisibility.Public || catalogNode.ChildObject.Visibility == CatalogVisibility.Hidden))
products.Add((Product)catalogNode.ChildObject);
Re: Including ghosted (hidden) items in API calls
Perfect, that's exactly what I needed!
Thanks!
Thanks!