Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marthijn 6 posts 26 karma points
    May 20, 2010 @ 00:53
    Marthijn
    0

    Create a content tree like the members section

    I'm pretty new to umbraco and i'm developing a little webshop in it. I store my products under folder node like this. 

    Products
    a
    AProduct1
    Aroduct2
    b
    BProduct1

    But now my question is how can i create a product on the main node(Products) so it is automatically stored under the correct node letter. So a Bicycle goes under the letter B and car under C. I assume you can use a sort of documenttype event (prepost)? Can i just create a class library? How can i reference to that type of document?

  • Chris Dunn 210 posts 401 karma points
    May 20, 2010 @ 01:27
    Chris Dunn
    1

    Tim wrote a package awhile back to do what your looking for, if I understand your post right.  Haven't tried it yet but give it a look.

    Download here : http://our.umbraco.org/projects/alphabetfolder

    Some more info here: http://www.nibble.be/?p=30

    -Chris

  • Marthijn 6 posts 26 karma points
    May 20, 2010 @ 02:27
    Marthijn
    0

    Thanks Chris!

    I just found a solution on the forums. This is what i have so far:

        public class ProductActionHandler : IActionHandler

        {

            #region IActionHandler Members

     

            public bool Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)

            {

                if (documentObject.ContentType.Alias == "Product")

                {

                    try

                    {

                        Node currentNode = new Node(documentObject.Parent.Id);

     

                        foreach (Node node in currentNode.Children)

                        {

                            if (node.Name == "b")

                            {

                                documentObject.Move(node.Id);

                            }

     

                        }

     

                    }

                    catch (Exception)

                    {

                        return false;

                    }

                    return true;

                }

                else

                {

                    return false;

                }

            }

            public umbraco.interfaces.IAction[] ReturnActions()

            {

                return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew() };

                //http://our.umbraco.org/forum/developers/api-questions/4680-Implementing-an-action-handler-in-Umbraco-4---ActionNew()-is-obsolete

            }

     

    But i just found out that the code is for V3 and not for v4

    http://our.umbraco.org/forum/developers/api-questions/4680-Implementing-an-action-handler-in-Umbraco-4---ActionNew()-is-obsolete

    I post my final solution here.

  • Marthijn 6 posts 26 karma points
    May 20, 2010 @ 14:59
    Marthijn
    0

    Here my solution:

        public class ProductActionHandler : ApplicationBase
        {
            public ProductActionHandler()
            {
                Document.BeforeAddToIndex += new Document.IndexEventHandler(Document_BeforeAddToIndex);
            }

            void Document_BeforeAddToIndex(Document doc, AddToIndexEventArgs e)
            {
                if (doc.ContentType.Alias == "Product")
                {
                    try
                    {
                        Node currentNode = new Node(doc.Parent.Id);

                        foreach (Node node in currentNode.Children)
                        {
                            if (node.Name == "b")
                            {
                                doc.Move(node.Id);
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        Log.Add(LogTypes.Error, doc.Id, "document: " + doc.Text + " Error: " + ex.Message );
                    }
                }
            }
        }

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies