Copied to clipboard

Flag this post as spam?

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


  • Bex 444 posts 555 karma points
    Nov 25, 2011 @ 15:11
    Bex
    0

    Custom Orderline Properties for Vouchers

    Hi

    One of my webshops needs to sell vouchers.

    Each voucher will have 3 custom properties - to, from and message. (a pdf will be generated and emailed when the order is complete)

    Theoretically an order can contain multiple vouchers of the same type but with different details!

    So far this is my jquery:

    jQuery('.voucherAddToCart').live('click', function () {
      var jQEle = jQuery(this);
    
      //Get the various elements and variables
      var voucher = jQEle.closest('.voucher'),
          quantityInput = product.find('.quantity input'),
          toInput = product.find('.voucherTo input'),
          fromInput = product.find('.voucherFrom input'),
          messageInput = product.find('.voucherMessage input'),
          quantityInput = product.find('.quantity input'),
          quantity = quantityInput[0] ? quantityInput.val() : 1,
          to = toInput[0] ? toInput.val() : '',
          from = fromInput[0] ? fromInput.val() : '',
          message = messageInput[0] ? messageInput.val() : '',
          variant = voucher.find('.voucherVariants select'),
          nodeId = variant[0] ? variant.val() : product.attr('productid');
    
      TeaCommerce.addUniqueOrderLine(nodeId , quantity, false);
    
    });

     

    I have two questions:

    1: Will "addUniqueOrderline" allow multiple products of the same type to be added to the basket?

    It is unclear from the documentation as it says:

    "A unique order line means that you can add the same product to the cart several times", but then it also says "It also takes a Quantity. If you add one product to the cart that is allready in the cart, the quantity of that orderline will now be two"

    Question 2:

    How do I add my to, from and message to the order?

    I am looking at "updateOrderLineProperty". Is this the correct function as I am adding rather than updating.
    And looking at my function above what do I need to put to get the orderlineId and add my properties?

    Thanks

    Bex

     

  • Anders Burla 2560 posts 8256 karma points
    Nov 25, 2011 @ 18:11
    Anders Burla
    0

    Hi Bex

    I will get Rune to answer this as quick as possible

    Kind regards
    Anders

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 27, 2011 @ 10:39
    Rune Grønkjær
    0

    Hi Bex,

    Yes addUniqueOrderline will enable you to add the same product to multiple order lines. It will be perfect for you voucher system, as you can use the .NET API to add the important details to each order line. You will only need one product node.

    If you are using unique order lines you can use TeaCommerce.updateUniqueOrderLineProperty to both add and update order line properties. If the to, from and message are general for the complete order, you just use TeaCommerce.updateOrderProperty and set the properties directly on the order, instead of the individual order lines.

    Remember that any information you add via the client API can be tampered with. Business critical information, should allways be added via the .NET API and use the ServerSideOnly bool. This way they are safely guarded against evil hackers.

    /Rune

  • Bex 444 posts 555 karma points
    Nov 28, 2011 @ 10:50
    Bex
    0

    Hi Rune

    If I use the addUniqueOrderLine, it says I can add the following values:

    TeaCommerce.addUniqueOrderLine(nodeId, orderLineId, quantity, async, successfn, errorfn, properties);

    If I use this to add the properties in what format do they need to be in?
    Also can I set the orderlineId, successfn and errofn to null if I don't need these?

    Should this be correct as I can't get it to work (as in it doesn't appear in the database)?

    var properties = {"voucherto": to,
    "voucherfrom":from,
    "voucherMessage":message};

    TeaCommerce.addUniqueOrderLine(nodeId , null, quantity, false,null,null,properties);

    Bex

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 28, 2011 @ 10:58
    Rune Grønkjær
    0

    Hi Bex,

    Your code looks right. You're just not using addUniqueOrderLine. Maybe that's it?

    The orderline id should be set to null if your'e not updating the order line. When updating a unique order line you need to provide the specific order line id.

    The success and error functions can be set to null if not needed.

    /Rune

  • Bex 444 posts 555 karma points
    Nov 28, 2011 @ 11:00
    Bex
    0

    :) sorry that was a typo.. just noticed as you posted.

    Should I see the properties appear in the database immediately?

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 28, 2011 @ 11:12
    Rune Grønkjær
    0

    I found the problem, which lies in the resent update we made to the javascript API. You're probably using the new one in which your properties should be added a little different. I can see that I haven't updated the documentation in english. DOH.

    The method now looks like this:

    TeaCommerce.addUniqueOrderLine = function (nodeId, orderLineId, quantity, settings)
    

    The settings object holds all the variable information like successfn, errorfn and properties. Your settings object should look like this:

    var settings {
      properties: {'key1': 'value1', 'key2': 'value2'}
    }

    Sorry about that. I will update the documentation right away.

    /Rune

  • Bex 444 posts 555 karma points
    Nov 28, 2011 @ 11:26
    Bex
    0

    Thanks Rune!

    That works perfectly!

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 28, 2011 @ 11:31
    Rune Grønkjær
    0

    Cool. I have updated the documentation. Only half of it was updated correctly. Wonder how I did that.

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft