0
votes

I have a sitecore item, "category", which has a drop link which populate "product type" template list.

Each category can have a "product type".

(Products being created under a category node will be using the template selected in the drop down. e.g. Shoes category will have a Shoes template, Slippers category will also have a shoes template, Bags category will have a bags template).

Problem:

  1. These categories should be able to mark related categories. Therefore I need to show a treelist kind of a control which only allows options to select categories with same "product type". Under "Shoes" category, I need to have "Slippers". How can I do this?

  2. After selecting "Slippers" as the related item to "Shoes", if the user tries to change the "product type" drop link value in "slippers", how can I warn the user that this product type has already linked to another category? (Validation on saving the category item.)

Hope this is a common issue with Related items in Sitecore, yet I could not find a solution for this.

1

1 Answers

1
votes

Your first problem, "marking related categories" is not clear to me what you want to achieve with it. But if I understand you correctly, you want to select a product-type-template in the Category-item to let the editor create products of the chosen producttype below the Category-item.

You can resolve this by using the item:saved event on the Category-item: - first check if you are saving an item of type Category but checking the template. - If it is a Category-Item, read the value of the product-type droplink and on the fly add this template to the insert-option of the Category item.

Your second problem with the check on related items can merely handled the same way by using the item:saving event. Not the item:saved event because you want to do the check before the item is saved so you can cancel the saving and display a messagebox through the Sitecore.Web.UI.Sheer.SheerResponse.Alert() method. In the item:saving event you need to check if the current item has 1 or more referrers (items that link to this item) through the LinkDatabase method Globals.LinkDatabase.GetReferrers().

Using validation on this instead of the item:saving event is not usefull because the validation event only throws a warning and saves the item anyway.

Another good link with example code is this blog of John West.