Copied to clipboard

Flag this post as spam?

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


  • Asbjørn 82 posts 195 karma points c-trib
    Jul 26, 2017 @ 06:19
    Asbjørn
    0

    Events happening before an action should be cancelable

    As a convention in .NET, events whose names end with -ing (ie. Deleting vs. Deleted) occur before an action and are cancelable whereever possible. This allows you to prevent the actions from happening for whatever reason.

    TeaCommerce does not follow this convention. It does have both types of events, occuring before and after an action, but the one occuring before is not cancelable - which means it is pretty much useless.

    We had a case where we only want to allow certain users to delete orders. We thought this would be simple - just hook into the Order.Deleting event and cancel the action when required. Instead it proved impossible, since there is no way in the Deleting event to prevent deletion from occuring.

  • Anders Burla 2560 posts 8256 karma points
    Sep 07, 2017 @ 08:23
    Anders Burla
    0

    Hi Asbjørn

    You are right about the convention and normally you can cancel an event. But the problem here being is that you could add order properties, add order lines, change payment country, change currency and the call order.Save(). Then if you rollback the country, then the currency change might also need to rollback because of business logic in Tea Commerce. So its pretty hard to have cancel mechanics when you only have one save method. Would be way easier if we changed the currency right away and also persisted it. But we don't :) Not something that we can easily rewrite as its a pretty huge change :)

    Kind regards

    Anders

  • Asbjørn 82 posts 195 karma points c-trib
    Sep 07, 2017 @ 09:44
    Asbjørn
    0

    Thanks for the reply.

    I can totally understand what you say about the interaction with Order.Save(). That makes sense, given the architecture of TeaCommerce.

    But what about the example I mentioned above? Deleting an order is a single action, and I see little reason that it should not be possible to cancel deletion from the Deleting event. And I'm sure there are other events where the same logic applies.

  • Anders Burla 2560 posts 8256 karma points
    Sep 19, 2017 @ 12:02
    Anders Burla
    0

    In the delete event it makes sense - you are right. Could you make an issue on GitHub describing what your would like. Then we have that for reference when we add it to the source.

    https://github.com/TeaCommerce/Tea-Commerce-for-Umbraco

    Kind regards

    Anders

Please Sign in or register to post replies

Write your reply to:

Draft