Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Jan 15, 2014 @ 18:41
    John C Scott
    0

    stopping order line being added

    My customer's requirement is that certain products should not be allowed to be added to the basket/cart according to some complex criteria.

    I wanted to use the .net API  and the code I've pasted below - works in the sense that if I put a breakpoint in I can see all the details of the order and the order line in the debugger. What I am not clear about is how I would return a fail / false to say that the item cannot be added to the order. 

    Is this possible?

    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Mail;
    using TeaCommerce.Api.Models;
    using TeaCommerce.Api.Notifications;
    using Umbraco.Core;
    
    namespace Extensions.TCx
    {
        public class CheckProducts
        {
            public class ApplicationStartup : ApplicationEventHandler
            {
                public ApplicationStartup()
                {
                    NotificationCenter.Order.OrderLinesAdding += CheckProduct_OrderLinesAdding;
                }
    
                void CheckProduct_OrderLinesAdding(Order order, IEnumerable<OrderLine> orderLines)
                {
                    var z = order;
                    var y = orderLines;
                }
            }
        }
    }
  • Anders Burla 2560 posts 8256 karma points
    Jan 20, 2014 @ 17:46
    Anders Burla
    0

    Hi John

    This is the .NET API so no notification to the UI of the web client. What you can do is that you use the JavaScript API to add the order line and check if there was an order line added. If not - then write some UI to show that it was not added.

    Kind regards
    Anders

  • John C Scott 473 posts 1183 karma points
    Jan 20, 2014 @ 19:01
    John C Scott
    0

    Thanks - if that's the way it is then that's the way it is.

    I was imagining something like returning false that you may do to stop an umbraco document being published if you add a custom event

    I have done this all now in Javascript (and must say thoroughly enjoying with tea commerce it's a real pleasure) but I am aware that someone maybe could manipulate the javascript on the client side.

    It's an unusual project in that sales are strictly limited to people who have earned the correct certifications, and there is a maximum limit of how many each person can buy, sometimes an item can't be added if it is already in the shopping cart, and these certified people are "experts" in a well known globalised web software technology business, so there is every chance that they could hack with the javascript. It would have been nice to just have a kind of server side validation rules as well as the javascript UI stuff. But it's OK as it is. I can't frankly imagine anyone would, but it is surprising the distances people may go to for a free t-shirt! It's what gets me to codegarden :)

     

  • Anders Burla 2560 posts 8256 karma points
    Jan 20, 2014 @ 19:33
    Anders Burla
    0

    You should do the validation on the server side so all business rules are done right and secure. Then your javascript should just have like this.

    var numberOfOrderLines = TC.getCurrentOrder(storeId).totalQuantity;
    TC.addOrUpdateOrderLine() and then fetch how many order lines it now has. If the number is still the same you can show an error message. Then all important stuff is done on the server.

    And thanks for the nice words about Tea Commerce!

  • John C Scott 473 posts 1183 karma points
    Jan 23, 2014 @ 15:38
    John C Scott
    0

    I'd assumed that you'd write a .net extension for OrderLinesAddingthat checked if it was OK to add the orderline and said no if you can't.

    Is there a better way? 

     

  • Anders Burla 2560 posts 8256 karma points
    Jan 24, 2014 @ 14:58
    Anders Burla
    100

    Yeah you should write the extension and not return if it will be added. But rather - it will be added and you can then remove it if you dont want it to be added using the notification center. I know its a bit of the other way around - but if we should have implemented the other way it would be quite crazy programming :)

  • John C Scott 473 posts 1183 karma points
    Jan 24, 2014 @ 15:03
    John C Scott
    0

    that makes perfect sense :)

Please Sign in or register to post replies

Write your reply to:

Draft