Copied to clipboard

Flag this post as spam?

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


  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 03, 2013 @ 16:28
    Rasmus Fjord
    0

    Teacommerce events and order save not playing nicely

    Hey there 

    Again its a TC 1 case, sorry :)

    In this shop im hooking in to a few events :

        WebshopEvents.OrderLineChanged += WebshopEvents_OrderLineChanged;
    WebshopEvents.OrderLineRemoved += WebshopEvents_OrderLineChanged;
    WebshopEvents.OrderLineAdded += WebshopEvents_OrderLineAdded;

     

    So when im adding a new orderline im updating the unit price if the product is part of a campaign, its quite simple and looks like this :

      private void WebshopEvents_OrderLineAdded(Order order, OrderLine Orderline)
            {
                var campaignItem = new CampaignHandler().hasCampaign(Orderline.NodeId);
    
                if (campaignItem.HasCampaign)
                {  
                    var calcedPrice = Convert.ToInt32(Orderline.UnitPrice);
                    calcedPrice =   calcedPrice = Convert.ToInt32(calcedPrice - Convert.ToDouble((campaignItem.Percentage / 100.0) * calcedPrice));
    
                    order.OrderLines.First(x => x.Id == Orderline.Id).UnitPrice = calcedPrice;
                    order.Save();  //<---- After Save it runs Here it runs the OrderLineChanged event and the price of the order is correct.
    } } //<---- when the current event ends here it runs the OrderLineChanged again but this time the price of the order is back to square one.

    The problem is in the 2 comments.

    The OrderLineChanged event is not doing anything to the price.

  • Anders Burla 2560 posts 8256 karma points
    Dec 04, 2013 @ 17:06
    Anders Burla
    0

    So is it saved correctly do the DB right after the first order.Save()?

    Kind regards
    Anders

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 05, 2013 @ 14:08
    Rasmus Fjord
    0

    Actually i cannot answer you that because i cannot find anything in the database besides the orderline price and that dosnt change.

    So this is what happens : 

    Right after i hit .Save() it goes into "OrderLineChanged"(Recalculateprice) and the total orderprice is 869 like it should be.

    So so far all looks good. Nothing actually happens in the recalculate method since it only does recalculation of the price when a giftcard is added.

    Next it returns to the "orderlineadded", and finishes it off still everything is good.

    Apperently when it finished the "orderlineadded" event it then goes back down into the "OrderLineChanged" event, and here the total order price changes :

    In the database the orderline unit price keeps on 999 and does not change to 809 as expected.

  • Anders Burla 2560 posts 8256 karma points
    Dec 05, 2013 @ 16:08
    Anders Burla
    0

    When you check the database you should look for the column - ManipulatedUnitPriceWithoutVAT which is the one that is being saved - the unit price will always be the one from Umbraco when the order line was added.

    The reason why the order line updated event is triggered is because you save the order in the order line added event. It is correct to call order.Save() but it was just to let you know that this behavier is expected. Ofcourse the pricing stuff isnt expected :)

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 05, 2013 @ 16:46
    Rasmus Fjord
    0

    Will have a look at the ManipulatedUnitPriceWithoutVAT then :)

    Yea i was expecting the OrderLineChanged event to be fired aswell. 

    So ive checked the manipulated and it does actually change, but as soon as the event is finished it changes again. But its not something i can step into.

    the price is changed :

    and when the event ends and it continues to "OrderLineChanged" once more it changes back :


     

     

     

  • Anders Burla 2560 posts 8256 karma points
    Dec 06, 2013 @ 08:44
    Anders Burla
    0

    Could you try and simplify your events so you only have one event and that is the order line added event. Then just change it and save the order - no other code. Then see if that works. If it does you have to look somewhere else of how this price can be changed.

    Kind regards
    Anders

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 09, 2013 @ 14:41
    Rasmus Fjord
    0

    Hey Anders

    http://www.screenr.com/d2wH

    Ive made a quick screener where you can see that all other events are disabled, and that the event runs fine through.

    but still when i look up the order right after it still looks like this : 

     

     

  • Anders Burla 2560 posts 8256 karma points
    Dec 10, 2013 @ 13:08
    Anders Burla
    0

    So RIGHT after the order.Save method has run - before your code quits the event. Try and check the database and see what the ManipulatedUnitPriceWithoutVAT is. Is that the value that you had set?

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Dec 11, 2013 @ 09:43
    Rasmus Fjord
    0

    The field is null when im entering the method.

    Right after .save (the method is not finished) the value is set to 647,20 (correct).

    The method ends and its set to 799.20 again.

    Im not doing anything in either on the page your landing on or through JS just double checked.

    If you have 5 could you skype me ? you have me added :)

Please Sign in or register to post replies

Write your reply to:

Draft