Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1459 posts 1880 karma points
    Apr 16, 2012 @ 15:43
    Gordon Saxby
    0

    Customer comments on order item

    Very generalised - I want to be able to add user comments to an order line when adding it to the basket.

    I haven't really got started on the basket code yet, but I understand that Tea Commerce uses an Umbraco node as a product (or properties from it). I can see how to get / add the Product ID, but how do I add the free text comments, entered by the customer, onto the order line as well?

    In fact I have to do this with a large number of customer chosen options, but once I can do one item I should be able to do them all!?

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 16, 2012 @ 15:49
    Gordon Saxby
    0

    Umm - I can't edit my original post, so I shall post a follow-up:

    I should add that I have a C# / .Net UserControl which deals with presenting the user options. I believe there is a .Net API? (I am investigating at the moment...)

  • Rune Grønkjær 1372 posts 3103 karma points
    Apr 16, 2012 @ 15:55
    Rune Grønkjær
    0

    Hi Gordon,

    Are you using the .NET API to add/edit the orderlines or do you use the javascript API?

    /Rune

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 16, 2012 @ 16:02
    Gordon Saxby
    0

    Sorry - I probably haven't explained my situation very well!!

    I have a .Net UserControl which is where a customer will "prepare" what they want to order (enter text, choose font, colour and other stuff). The UserControl has a "Buy" button which needs to add the product to the basket ... but I also need to save the customer entered information.

    There is not "need" to do it via JavaScript as the UserControl does a "call back" anyway - so, I guess I could use either the JavaScript or .Net API ... preference would probably be the .Net API.

    The key question is how do I save the customer entered info to the order line?

  • Rune Grønkjær 1372 posts 3103 karma points
    Apr 16, 2012 @ 16:10
    Rune Grønkjær
    0

    Hi Gordon,

    The .NET API will be quite enough to do what you are aiming for.

    You will be posting your information to the server with standard ASP.NET. When on the server you will then get the order (Cart/basket) using the Tea Commerce Razor API like this TeaCommerce.Razor.TeaCommerce.GetOrder()

    Now you have the order and you will have to either create a new orderline, or update an existing one:

    orderLineId = orderLineId < 0 ? null : (long?)orderLineId;
    
          OrderLine orderLine = GetOrderLine( order, nodeId, orderLineId, isUnique );
          if ( orderLine == null ) {
            if ( !isUnique )
              orderLine = order.CreateOrderLine( nodeId, quantity );
            else
              orderLine = order.CreateUniqueOrderLine( nodeId, quantity );
          } else {
            if ( !overwriteQuantity )
              orderLine.Quantity += quantity;
            else
              orderLine.Quantity = quantity;
          }

    That's the basic stuff. Now you will add the userspecific information/properties to the orderline. you can add as many as you want like this:

    orderLine.AddProperty( new OrderLineProperty( yourKey, yourValue, null ) );
    

    That should do the trick.

    To update an existing property, just get it from the orderLine object and then update it.

    NOTE: Always remember to save the order after changing the order, orderlines or anything else on the order. Otherwise your data will not be persisted to the database.

    /Rune

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 16, 2012 @ 16:20
    Gordon Saxby
    0

    Thanks Rune ... that seems easy enough (adding extra properties anyway).

    I assume I still need to enter some property names in the "Order line property aliases" box in "General Settings"?

    Does "TeaCommerce.Razor.TeaCommerce.GetOrder()" create an order if one does not yet exist?

  • Rune Grønkjær 1372 posts 3103 karma points
    Apr 16, 2012 @ 16:41
    Rune Grønkjær
    0

    Yes, you should still enter the  "Order line property aliases" that you wish Tea Commerce to automatically add to the order line. Product name, number and so on.

    Yes, TeaCommerce.Razor.TeaCommerce.GetOrder() will create an order if none exists. It will be placed in the users session and from then on the same order will be returned.

    /Rune

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 17, 2012 @ 00:02
    Gordon Saxby
    0

    I was rather hoping to find documentation for the .Net API ... but I can't? How do I know what is available?

    I don't fully understand the code you have given above - where does orderLineId come from? Where does GetOrderLine come from?

    Maybe it's now a bit too late to be working on this!!?

  • Rune Grønkjær 1372 posts 3103 karma points
    Apr 17, 2012 @ 09:02
    Rune Grønkjær
    0

    Hi Gordon,

    All documentation can be found here: http://www.teacommerce.dk/en/documentation.aspx

    Sorry about the almost pseudo code above. I'll try and expand.

    Get orderline can be made lige this:

    private static OrderLine GetOrderLine( Order order, int? nodeId, long? orderLineId, bool isUnique ) {
          if ( !isUnique )
            return order.OrderLines.SingleOrDefault( o => o.NodeId == nodeId && !o.IsUnique );
          else
            return order.OrderLines.SingleOrDefault( o => o.Id == orderLineId && o.IsUnique );
        }

    The order line id will have to come from your own code. If you want to create a NEW orderline, orderLineId will be null. If you want to update an existing order line you can either find it by the products "nodeId" or the "orderLineId". The last one is mostly needed if you are creating unique orderlines. Unique orderlines are explained in this javascript documentation, but is escentially the same in .NET.

    Feel free to ask if you need any more info.

    /Rune

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 17, 2012 @ 20:06
    Gordon Saxby
    0

    Phew, getting somewhere now! I now have items (order lines) adding to the order and I am displaying the total (items & cost).

    Next job ... full details basket page :-)

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Apr 18, 2012 @ 08:00
    Rune Grønkjær
    0

    That's fantastic. Could you mark the correct answer, so others can easily find it later on.

    I hope your basket will come along nicely. You might want to use the razor API for that part. It should have all the functionality you need.

    You could also take a look at our starter kit for Tea Commerce and steal the html and css from that. Might save you some time.

    /Rune

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 20, 2012 @ 17:09
    Gordon Saxby
    0

    I am looking for the answer as well ... but could you tell me how I access properties on an order line that I have added using:

    orderLine.AddProperty

    The is a fixed set of properties being added, I need to read / use them on the order summary in Umbraco and probably during the checkout process.

     

     

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 20, 2012 @ 18:02
    Gordon Saxby
    0

    Doh - got it!!

    ./properties/custom_property_name

     

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 24, 2012 @ 13:32
    Gordon Saxby
    0

    Getting the property value in XSLT is easy (as above) ... but how do I do the same in C# ?

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Apr 24, 2012 @ 13:42
    Rune Grønkjær
    0

    Something like: orderLine.Properties.Select(p => p.Alias == "propAlias")

    /Rune

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 24, 2012 @ 14:57
    Gordon Saxby
    0

    I tried this:

            private string GetOrderLineProperty(string propertyId)
            {
                return this.orderLine.Properties.Select(p => p.Alias == propertyId);
            }

    but it is trying to return a Boolean value rather than a string (the value of the property) ... I've tried a few things but can't get it to work :-(

    This is return a value added with "orderLine.AddProperty"

  • Gordon Saxby 1459 posts 1880 karma points
    Apr 24, 2012 @ 15:30
    Gordon Saxby
    0

    Aha! This works:

            private string GetOrderLineProperty(string propertyId)
            {
                return this.orderLine.Properties.Single(p => p.Alias.Equals(propertyId)).Value;
            }
  • Rune Grønkjær 1372 posts 3103 karma points
    Apr 25, 2012 @ 08:41
    Rune Grønkjær
    0

    That is great, and that will ofcause work on the orders own properties as well.

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft