Try our conversational search powered by Generative AI!

Validation on a node

Vote:
 

Hey, we have a requirement where we can have a selection of nodes, foir a rough example say we call them:

10% Discount
20% Discount

Content editors can drag varients under the node they want the discount to be applied and associate them.  they will not live directly under these nodes.

What is the best way to prevent content editors from being able to drag a varient under more than one of these node?  E.g. if variant one, has had an association added to it under the 10% discount node, if a content editor tries to additionally create a second association under 20% discount they should get some form of warning.

Thanks!

Jon

#133360
Sep 02, 2015 16:59
Vote:
 

One way could be, hook On Saving Events and Cancel Saving on validation
http://world.episerver.com/blogs/K-Khan-/Dates/2015/5/hook-into-catalog-events/
Regards
/K

#133362
Sep 02, 2015 17:09
Vote:
 

Thanks for the reply :)  That was one of my first ideas and in theory it would work.  One question though is that to add a varient to a node, I'm physiucally dragging varients over and using the link option when prompted, this updates and moves it automatically (reference here http://prntscr.com/8bt8go).

Does linking still call the published event even though I don't need to actually hit the publish button?

#133364
Edited, Sep 02, 2015 18:39
Vote:
 

Hi,

With this approach, you will add handler for SavingContent (Not publishing events)

http://world.episerver.com/documentation/class-library/?documentId=cms/7/bcf6284c-22d0-5375-5b15-142b35138eb0

Regards
/K

#133374
Sep 03, 2015 9:11
Vote:
 

Changes to Relations/Associations between nodes and entries can be listened via CatalogEventListenerBase http://world.episerver.com/documentation/Class-library/?documentId=commerce/8/1E7D1BBB . What I think that might work for you is:

- Implement an implemenation of CatalogEventListenerBase

- Override AssociationUpdating and RelationUpdating methods

- In these method, check if the changes satisfy your conditions or not.

Those events are ecf events, they work with DTO (CatalogRelationDto and CatalogAssociationDto).

Regards.

/Q

#133390
Sep 03, 2015 11:42
Vote:
 

+1 for Quan's Solution.
/K

#133391
Sep 03, 2015 12:01
Vote:
 

That looks promsiing, lathoguth my codes not getting hit.  How do i register it?  

I've got this

    public class MyCatalogEventListenerBase : CatalogEventListenerBase
    {
        public new void AssociationUpdating(object source, AssociationEventArgs args)
        {
            var variant = source as GameVariation;

            var boo = variant != null;
        }

        public new void RelationUpdating(object source, RelationEventArgs args)
        {
            var variant = source as GameVariation;


            var boo = variant != null;
        }
    }

and I also added in a structure map config but still nothign, is there somethign i'm missing?

            container.For<CatalogEventListenerBase>()
                .Use(ctx => new MyCatalogEventListenerBase());
#133401
Sep 03, 2015 13:53
Vote:
 

Hi,

You are using "new". You should use "override" instead.

P/s: And you can use the attribute registration: [ServiceConfiguration(typeof(CatalogEventListenerBase)]

/Q

#133402
Sep 03, 2015 13:56
Vote:
 

Perfect, thanks for your help.  That's got it working.  Last question though.. I can now do look-ups and prevent extra nodes, is there a recommened way that I can feed this back to the user?  I assume I'd write somethign like this :

        public override void RelationUpdating(object source, RelationEventArgs args)
        {
            var variant = source as GameVariation;


            var boo = variant != null;

            if (beep == NotUnderAnotherNode())
                base.RelationUpdating(source, args);

            else
                // Display Error Somehow
        }

In the CMS I'd use soemthig like IValidate to return a ValidationError, any suggestions?

#133413
Sep 03, 2015 15:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.