Copied to clipboard

Flag this post as spam?

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


  • Matt Taylor 873 posts 2086 karma points
    Jul 06, 2011 @ 14:56
    Matt Taylor
    0

    Creating an order and adding product lines .Net API - Getting started

    I'm just a little confused as to the correct process and method calls for creating a new order with the .Net API.
    In my .Net user control I have the product node that I wish to add to the order.

    I'm guessing I need to create a new order first.

    Add the product to it with the appropriate quantity.

    Could someone get me started with some sample code?

    Thanks,

    Matt

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 06, 2011 @ 15:02
  • Matt Taylor 873 posts 2086 karma points
    Jul 06, 2011 @ 15:09
    Matt Taylor
    0

    Hi Rune,

    I did see that post when I checked to see if my question had already been asked.

    Order order =TeaCommerce.Razor.TeaCommerce.GetOrder();

    The above code will return null if no order is present so I need to find out how to create a new order to begin with.

    Cheers, Matt

  • Matt Taylor 873 posts 2086 karma points
    Jul 06, 2011 @ 15:16
    Matt Taylor
    0

    Ah OK, I figured out that calling

    TeaCommerce.Base.AddOrderLine

    will create a new order if one does not exist. :)

  • Anders Burla 2560 posts 8256 karma points
    Jul 06, 2011 @ 15:20
    Anders Burla
    0

    Indeed it will - if you try to do anything with the order it will be auto created. We will look into to create new good stuff to help you in the .NET API

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 06, 2011 @ 15:24
    Rune Grønkjær
    0

    Yes, I was just about to write that. BUT it will return you a useless jSon string, and not a working order. I will create a new Razor method called

    GetOrCreateOrder()
    

    With that you will get the current order or generate a new one.

    /Rune

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 06, 2011 @ 15:32
    Rune Grønkjær
    0

    Yes, I was just about to write that. BUT it will return you a useless jSon string, and not a working order. I will create a new Razor method called

    GetOrCreateOrder()
    

    With that you will get the current order or generate a new one, and have that returned. It will never return null.

    /Rune

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 06, 2011 @ 15:49
    Rune Grønkjær
    0

    Oups, double post.

    Anyways. I have uploaded a new Tea Commerce 1.4.1.0 BETA and changed the GetOrder() method instead of creating the GetOrCreateOrder() method

    The razor version of GetOrder was buggy as it actually where supposed to return a new order if none was present. Otherwise the HasOrder method would also be useless :)

    You can just install the new package on top of the old.

    /Rune

  • Matt Taylor 873 posts 2086 karma points
    Jul 06, 2011 @ 17:18
    Matt Taylor
    0

    Cool,

    And getting the orderlines is simple enough.

    TeaCommerce.Data.Order order = TeaCommerce.Razor.TeaCommerce.GetOrder();
    foreach (TeaCommerce.Data.OrderLine orderLine in order.OrderLines)
    ...

    Cheers, Matt

  • Anders Burla 2560 posts 8256 karma points
    Jul 06, 2011 @ 17:26
    Anders Burla
    0

    Great to hear! Please mark the correct post as a solution :)

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 07, 2011 @ 10:52
    Rune Grønkjær
    0

    Hi guys,

    I have uploaded a new beta fixing a few bugs with the above mentioned stuff.

    /Rune

  • Matt Taylor 873 posts 2086 karma points
    Jul 07, 2011 @ 11:37
    Matt Taylor
    0

    Seems I was adding product lines incorrectly and this is how it should be done.

    TeaCommerce.Data.Order order = TeaCommerce.Razor.TeaCommerce.GetOrder();
    OrderLine orderLine = order.GetOrCreateOrderLine(Node.GetCurrent().Id, null, false);
    orderLine.Quantity += 1;
    order.Save();

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 07, 2011 @ 11:40
    Rune Grønkjær
    0

    Yes, that is the correct way, after we have updated the API!

    /Rune

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 07, 2011 @ 14:59
    Rune Grønkjær
    0

    Hi Matt,

    After Kenn and Dan from the other post came back with one more bug we have refactored the bit of the API you all are using. I have uploaded a new BETA package. We refactored the whole create orderline part and there's now two new, and much more simple methods called "CreateOrderLine" and "CreateUniqueOrderLine". You will then have to check for the existense of the order line yourselves.

    Here an example for you:

    OrderLine newOrderLine = order.OrderLines.FirstOrDefault( ol => ol.NodeId == 1106 );
    
    if ( newOrderLine == null ) {
      newOrderLine = order.CreateOrderLine( 1106, 1 );
    } else {
      newOrderLine.Quantity++;
    }
    
    order.Save();

    Hope it helps. And sorry for the break.

    Thanks for the great feedback. It's really valuable for us.

    /Rune

  • Matt Taylor 873 posts 2086 karma points
    Jul 07, 2011 @ 15:52
    Matt Taylor
    0

    Thanks for letting me know Rune.

Please Sign in or register to post replies

Write your reply to:

Draft